wavesoft / dot-dom

.dom is a tiny (512 byte) template engine that uses virtual DOM and some of react principles
Apache License 2.0
806 stars 53 forks source link

Feature: Lifecycle Methods #8

Closed wavesoft closed 7 years ago

wavesoft commented 7 years ago

This PR is a work in progress towards implementing two lifecycle methods that can be used to accessing the DOM and binding event handlers:

NOTE: This is WIP because I want the result to be at most 512 bytes ๐Ÿ˜„

SilentCicero commented 7 years ago

Would this be used in props?

wavesoft commented 7 years ago

Currently the planning is to use this as a fourth callback function on the functional component. For example:

function Component(props, state, setState, setLifecycleCallback) {
  setLifecycleCallback((prevDOM, nextDOM) => {
    if (!prevDOM && nextDOM) {
      // mounted
    } else if (prevDOM & !nextDOM) {
      // unmounted
    } else {
      // changed
    }
  });

  return div( ... )
}
wavesoft commented 7 years ago

Ok, so managed to bring it down to 512 bytes by doing something that I am not 100% OK with:

I am going to continue working on this, but I am open on ideas/suggestions ๐Ÿ˜„

wavesoft commented 7 years ago

And to comment on my thoughts: