Closed SilentCicero closed 7 years ago
Got it done, 510 bytes with safe scoping @kumavis @wavesoft =D
Are you gonna add examples to the README how to use this?
@styfle Yes, we will need to change the ReadMe.
Mainly..
function MyComponent(props, state, setState, hooks){
hooks.m.push(() => console.log('component did mount life cycle hook'));
hooks.d.push(() => console.log('did update life cycle hook'));
hooks.u.push(() => console.log('did unload life cycle hook'));
return H('div', 'My component body');
}
R(H(MyComponent), document.body);
So the life cycle hooks are added by pushing a method to the hook arrays. This allows for both, multiple hooks to be added, and for things like higher-order components to be created.
Right now we are dealing with a scope/state sharing component design problem (it can be avoided however, if every component returns at least a single element as their child's first node (that isn't another component). We are figuring out a way to collapse this now. Gonna be hard though, we only have a few bytes left ;)
Ow yeah ✨ Awesome work @SilentCicero :1st_place_medal: I am going to give it a spin and merge 👍
Hmm @SilentCicero what's your "build" command? Because when I try to minify this it gets down to 520 bytes :thinking:
@wavesoft just using npm run build:uglify
, 508 bytes by the latest count.
@wavesoft I really want to solve that higher component problem. See gitter.
👷 LET'S MERGE THIS ! 👷
You can now add multiple lifecycle hooks per component. The life cycle variables are arrays, which functions can be pushed too.