-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composition api #1923
Composition api #1923
Conversation
unwrap reactive and ref more effeciently unwrap createRef
…is is a combination between hydration and replacing a node we have a combination of excessDomChildren and dom which did not get cleared for the case of textNodes
* (tests) - add test for the replaceNode render case seemingly since this is a combination between hydration and replacing a node we have a combination of excessDomChildren and dom which did not get cleared for the case of textNodes * (fix) - clear excessDomChildren for the textNode case * (refactor) - save some bytes by inlining check and allocation
unwrap reactive and ref more effeciently unwrap createRef
Wow, that's really cool! It's good to know that the Preact code base remains approachable even with the new addon structure :) This is an area where I've done a lot of prototypes and experiments myself. Back when the react team announced hooks (and even earlier) we've been toying with a similar idea in spirit like the one vue is pursuing. The gist of it was to have constructor functions for components, like you have in this PR, and to follow a more observable like approach. I'd love for this to become a solid alternative to hooks. I wouldn't focus too much on remaining 1:1 API compatible with vue and would rather tackle it from the perspective of what's best for Preact 👍 Regarding Anyhow, gotta run. I really love where this is going and I'm very interested in this. Feel free to hit me up on slack. |
Thanks @marvinhagemeister Would be nice to collaborate in the API design and add the missing pieces to make the API production ready. |
This is ridiculously cool and I'm still digesting the syntax. It looks like observables! |
Wow, thanks for your feedback. I guess better docs and samples would help... 5 minutes demo https://codesandbox.io/s/preact-composition-github-demo-hfdsq |
Thanks @JoviDeCroock, i answered or solved your questions 👍 |
That simplifies code, allows for direct access to c.props
random idea:
I'm sure you were already thinking about that and maybe you have even better name :-) BTW: I should probably calm down a bit but, this is EXACTLY what I was waiting for:
What I mean by the last point is that your hooks can now be nontrivial, you can do things like:
and it can do some introspection, etc. or whatever what would be normally a problem because of performance (with hooks you'd need to couple it with memos & dependencies everywhere which quickly gets nasty) I can imagine using styles this way too, again, some nontrivial style generation, observe+watch to update and the current value is simply forwarded to the view. |
Thanks for the excitement @cztomsik ❗ |
I've implement one for react already in Concent, see this demo: here is a article about setup feature: the most interesting thing about Concent's setup is that it can be reused in function component and class component both. Welcome to understand and give me feedback |
This was a great experiment! Allowed me to understand much about how Preact works internally. It was too ambitious for me 😄 but I hope at least some ideas here were good. And I'm really happy to see reactivity coming in the form of preact/signals Closed in favor of https://github.com/preactjs/signals |
This pull request is a implementation of the Vue Composition API in Preact.
This started as a proof of concept of implementing the API in Preact, but ended up being a full implementation. It adds bytes to Preact itself and can be used standalone just like hooks, so both Composition and Hooks can be used also together.
There are some differences from the Vue Api as Preact works differently internally.
I wriote a blog post to show the differences between Vue composition Api and React Hooks
There are still missing tests, docs, better typings, more examples and probably benchmark it to see the differences between this, hooks and classes.
If someone else find this concept interesting, i can work more on it and bring those missing parts.
Examples: