jlongster / lively

Components & state
https://jlongster.github.io/lively/
145 stars 8 forks source link

Let's open a club #1

Open andywer opened 7 years ago

andywer commented 7 years ago

Hey @jlongster,

nice to see that other people feel similar about this. Just for reference: I came up with something very similar if not almost the same very recently: react-stateful-fn

You gave it the better name, though 😉

Cheers

jlongster commented 7 years ago

@andywer Hi! I think I saw that! First, note that I'm not taking this repo seriously (not going to market it or actually make it into anything right now). This is something I've been using on my own and I wanted to show it to a few people.

Your lib looks great, but there are a few differences which are purely for ergonomics. The updater pattern is a more elegant way, I think, of creating callbacks "bound" to the right instance. There is almost no ceremony (you never need to pass methods to lively). You can even add arguments at render time (see Form.js in examples). I don't implement it yet, but the updater function just needs to memoize values, and then it will always return exactly the same function instance which solves the pure equality issue.

I also don't see things like refs or instance variables addressed in your lib. Both are critical for complex apps, and doable with mine because I pass both inst and refs around. It's all in the component bag. Because there are many things to pass around, I think it's easiest to pass them around in an object instead of separate args.

Lastly, note that my API is basically taken from reason-react. I had landed on something close, so I took a few ideas from them. I say that because several core Facebook people are using that as an experiment for what the next API might look like.

Anyway, I'm not claiming one is necessarily better, but there are many small differences. And that's good for experimentation! Like I said, I'm not going to evolve this into a real project yet. Just showing what I've been using internally.

andywer commented 7 years ago

Of course, I get that. My approach was just writing down what was floating in my head as well :)

The reason-react origin is interesting. I totally agree with the updater & memoizing idea. Seems like a pretty elegant approach. Got to have another look at how you handle refs. As you pointed out there is in fact no way to handle refs in my thingy.

Always interesting to see alternative approaches. A few more iterations and it might make it into React 18 or so 🤓

PS: Nice job :)