Implementing React from Scratch
rob.directory
rob.directory
Abramov has a good and old but relevant video series on Redux from scratch too.
Sometimes it’s useful to know how something works and to be easily able to change every piece of the stack, other times it’s a massive waste of time and the end result is a worse documented and worse developed solution than what hundreds if not thousands of people have built and tested over the years.
Depends on what you’re working on, really, I’ve seen some really unfortunate stuff once people start rolling their own security stuff and it’s not like you can ask StackOverflow about why some random bespoke library or framework is full of weird behaviour.
But for personal learning projects? Go wild!
Sciter has Reactor - its own native and built-in implementation of React.
Main difference is that component is instanceof Element - components are DOM elements. This allows to unify React and WebComponent under the same umbrella/mechanism. Yet to extend standard DOM methods by use of JSX, so this
someDomElement.append(<div>Hello</div>)
works just fine - appends content from the vDOM.In fact Reactor is three entities implemented natively:
* JSX - embedded into JS compiler (830 LOC) - https://gitlab.com/c-smile/quickjspp/-/blob/master/quickjs-j... , produces vDOM literals
* Element.prototype.patch(JSX/vDOM) (420 LOC) - reconciliation / diff implementation
* Binding of lifecycle methods (200 LOC) - componentDidMount and Co.
There is also native implementation of Signal's (310 LOC) but they are optional for React'alike functionality.
It does support server-side-rendering, hydratation, and async events. It's a bit different in implementation in the OP's post, but I think the most important thing any reader should take away is that at the core, virtual-doms can be quite simple with plenty of room for further optimization.
For example, I use it in mockaton here:
https://github.com/ericfortis/mockaton/blob/7e6ad6226d7ed48e...
So if at some point I need React I can simply delete my version of createElement