snabbdom icon indicating copy to clipboard operation
snabbdom copied to clipboard

Hook signature of create

Open AlexGalays opened this issue 7 years ago • 2 comments

Would you be in favor of simplifying the hook signature of create ? It takes an arbitrary emptyVnode as a first argument.

The fact that the logic is reused in the core modules for the create and update phases should not bother users everytime they want to do something in a create hook. I use this hook a lot and it's so annoying.

It would just be a matter of creating a wrapping function in the modules.

If you all agree, I'm happy to create a PR when I have some time.

AlexGalays avatar Apr 18 '17 16:04 AlexGalays

Can you elaborate more? Creating an element while diffing two vnodes (the old one and the new one) is an important step in the process, and I don't think it has the same signature of update just to match the api. On top of that, this will be a non-BC change...

caridy avatar Apr 19 '17 19:04 caridy

I mean:

In the main module (snabbdom.js) the create hook is called with an empty VNode as its first argument

As far as I know, its only purpose is to make the create and update functions of modules able to reuse the same function

If create would only take the VNode with its newly created elm, then it would only be a tiny inconvenience when writing modules, something you certainly do not do everyday, and make for a better API when using the create hook in application code, something you do often (this is basically componentWillMount of react except you have access to the elm already).

It's a non backward compatible change, but an API simplification, easy to adjust without much thinking involved. Worth it for 0.7.0 imo.

AlexGalays avatar Apr 20 '17 09:04 AlexGalays