73 points · by thenewestkid · 9y ago · 31 comments
The goal of this series is not to teach patterns but to promote a simple and flexible stack that you can use with the patterns that you like. (In your case you can move the view specific logic to the level of the components).
The library I made supports both of them, but I did not mention local state management for the sake of simplicity. You can find it here: https://github.com/solkimicreb/react-easy-state#easycomp (it will take 1 min to read).
Doesn't it get clumsy to pass state as props to deeply nested comps?
I enjoy the simplicity of it so much that I've now entirely adopted Elm -- type safety, super simple but powerful, and completely based on uni directional data flow with a compiler that is the most helpful I've ever used all wrapped up in the same State -> View function hierarchy that I adore in React.
It sounds like tracking this by hand ("what is needed where") could get messy, though I don't have experience with this approach.
Did you check out mobx?
My guess is that it would be almost as easy and a bit more mature.
MobX is also moving in the Proxy direction with v4, but I do not agree with some of their architectural decisions (mostly the synchronous execution), so I made a separate library. We can discuss these later if you are interested.
In a nutshell: it is used for computed properties, which compute their value on 'get' operations instead of storing them.
function Foo() {
var _bar = 42;
return {
get bar() {
return _bar;
}
}
}
var foo = Foo();
foo.bar
/*
42
*/
However the fact that you can transparently replace a simple property by a computed one (e.g. for backwards compatibility or to trigger side effects in observables) does make explicit, Java-style, getters and setters less useful.