antonmedv / monkberry

Monkberry is a JavaScript library for building web user interfaces
https://monkberry.js.org
MIT License
1.49k stars 78 forks source link

Lifecycle methods are overridden #27

Open Madumo opened 7 years ago

Madumo commented 7 years ago

There is three methods that seem to act as lifecycle methods on the components: onRender, onUpdate and onRemove.

But the Monkberry constructor is setting them to null, and then the component constructor may set them to a function, like when you use a directive.

Because of that, you can't just declare an onRender method that call super.onRender() in your component class. It will get overridden. Right now if you want to do something on onRender or onRemove, you have to keep the ref of the current method within the constructor, assign a new method that do your stuff and also call the previous method.

It would be great if we could just create the lifecycle methods within our class and just call the super one if needed.

antonmedv commented 7 years ago

Yes, it's true, this methods using for internal purposes in monkberry. It's not like lifecycle methods. But i think we can add lifecycle events with more native naming and rename onRender to something like __onRender__.

wellcaffeinated commented 6 years ago

Looks like there was a PR #31 for this but it was never merged. I'm trying to use monkberry for a project (and love it) but i really need lifecycle methods. Any chance you could bump the version and add this feature?

antonmedv commented 6 years ago

Sorry, no, now main main goal is to finish next version.

wellcaffeinated commented 6 years ago

Fair enough, is there any way I can help? If I push this feature to the next branch can you instruct me on how to use the new branch in my project :) ?

antonmedv commented 6 years ago

It’s still in early age. It’s difficult to explain what’s going on there, sorry.