Freak613 / stage0

Collection of low-level DOM tools for building high performant web interfaces
MIT License
262 stars 16 forks source link

What is the reason for node.collect(node) ? #17

Closed luwes closed 5 years ago

luwes commented 5 years ago

Thanks for this great lib!

I was wondering why the api for this call is node.collect(node)? Since it's called on the same object couldn't it be node.collect()?

Freak613 commented 5 years ago

The reason is that custom functions (like collect) are not copied on cloning. And you calling .collect(node) on template node returned from h function, not on the cloned one. For nodes, that are not cloned and used directly, it could be reasonable, but not consistent with API. I think clone-collect can be considered as default usage pattern, that's why API implemented in favor of this.

Freak613 commented 5 years ago

Here is one example: https://github.com/Freak613/stage0/blob/master/examples/sierpinski/app.js#L49 Check out examples folder, it demonstrates this pattern very well.