3 ms·
I'm glad to see more people writing about functional programming for JavaScript web applications. I liked a lot of the ideas here, but I don't really see the n
by davexunit 11y ago
I'm glad to see more people writing about functional programming for JavaScript web applications. I liked a lot of the ideas here, but I don't really see the need for the "component" data type. Why not just regular functions? Also, I don't think that letting each component determine whether or not it needs to redraw is a good idea. I'd rather just let the rendering system handle it by diffing the tree. With immutable data, it's trivial to see if a node has changed and redraw the subtree.
I've been doing experiments with Mithril (provides virtual DOM) and various functional reactive programming libraries (such as Kefir), and I think something like that is the right way to go.
- UberMouse 11y agoI'm not quite understanding how the component determines whether it should redraw itself in this example. The component gets redrawn when the render function is called (if the data it's passed is different and if the output of the render changes) and the render function gets called when a "swap" event is raised, which is raised when a component updates the app state, but it's not saying "please redraw me now". It's not aware it's getting redrawn, it just happens. Unless I've mis defined what "letting the component determine it needs to redraw" means in this context.
- mikaelbr 11y agoComponent here is just to illustrate that the type is of a view component, and due to it being implemented on top of React. `component()` is a factory/syntactic sugar on top of React allowing you to have referentially transparent components (as you get arguments passed to the render function). In time, React hopefully (and probably) gets support for stateless functions without the syntactic sugar (https://github.com/reactjs/react-future/blob/master/01%20-%20Core/03%20-%20Stateless%20Functions.js https://github.com/reactjs/react-future/blob/master/01%20-%2...). This will be supported when React adds support for functions returning VDOM elements.