Hacker News new | ask | show | jobs
by vinceguidry 4441 days ago
How does one share server HTTP-serving code and client DOM-manipulating code?
4 comments

Facebook's React lets you write DOM rendering code that can easily run on both client and server. The framework discourages DOM manipulation, instead promoting a near-declarative style of stateless rendering. Updates to the client DOM are then done by efficient tree diffing. It's very nice.
Most likely by abstracting both into business concerns which appear in the client (manipulation for implementing a UI) and the server (manipulation for persistence and client-to-client communication).
There's a library called browserify that does it. It's not useful for direct DOM manipulation, but there are other libraries for which it is nice.
You only share the data model between the server and the client.