Closed merwan7 closed 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
@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).
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!
Please checkout this fork of the sample project where I have made a few modifications:
4.3.3
(latest release on npm)init
function that simply writes to the browser console each time it's run.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 in5.0.0-beta
of marko-widgets; however, given that it's still a beta andv4
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: