marko-js-archive / marko-widgets

[LEGACY] Module to support binding of behavior to rendered UI components rendered on the server or client
http://v3.markojs.com/docs/marko-widgets/
MIT License
141 stars 40 forks source link

init is run each time setState is invoked [v4.3.3] #89

Closed merwan7 closed 9 years ago

merwan7 commented 9 years ago

Please checkout this fork of the sample project where I have made a few modifications:

As you can see, each time you change the state of the widget, init runs. This is a problem only in 4.x as it seems to be fixed in 5.0.0-beta of marko-widgets; however, given that it's still a beta and v4 is what is living in NPM I think it's worth taking a look.

According to the docs, init should run only once. Unless I'm totally misunderstanding this, which is definitely a possibility :sleepy:

yomed commented 9 years ago

This should be expected behavior in 4.x (the docs were updated for 5.x). init gets called whenever the widget is rendered (including client rerenderings via setState). More discussion on this here: https://github.com/marko-js/marko-widgets/issues/60

philidem commented 9 years ago

@yomed is exactly right. I just wanted to add that I found the behavior of init being called more than once confusing as well but @patrick-steele-idem was worried about changing this behavior and breaking apps. For that reason, the change to call init only once is coming in marko-widgets v5 (currently in beta now but should be published next week).

merwan7 commented 9 years ago

Ok this is great info, thank you both. I apologize for the noise, but I was confused by the updated docs vs latest release on NPM.

Happy to hear that v5 is just around the corner!