New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching `rv-if` causes binder to set up multiple times #678

Namek opened this Issue Sep 5, 2016 · 3 comments


None yet
3 participants
Copy link

Namek commented Sep 5, 2016

rv-if going to falsy doesn't destroy elements, it seems to just remove them from DOM and keep in memory.


  1. set rv-if to truthy, binder's function should be called
  2. set rv-if to falsy, nested elements should be removed from DOM
  3. set rv-if to truthy again, binder function is called on same element as previously

When rv-if turns to truthy then it readds nested elements. However, binder (checked only one-way binders) setup function is being called as many times as rv-if is switched to truthy state.


Here's the fiddle presenting the problem:

Spam "toggle state" button and observe new elements appearing which is inappropriate.

It does not matter if rv-if was truthy or falsy from the beginning which can be seen here:

My commentary on this:

in AngularJS there's ng-show (hiding elements using CSS) and ng-if (removing elements). Here rv-if seems to be something inbetween, because it removes elements but readds them instead of recreating.

Although it's pretty interesting solution it seems to be inconsistent with binders, am I wrong?


This comment has been minimized.

Copy link

jccazeaux commented Sep 19, 2016

That's an interesting case. I do not have a direct answer, but as I see it you should implement unbind function on your binder to correctly handle the unbinding.


This comment has been minimized.

Copy link

blikblum commented Oct 22, 2016

I did a test and removed nested.bind / unbind calls inside if.routine except the bind after nested is created.
The tests passes and the behavior of this issue is not seem.

I think the reason to unbind / bind inside if routine is an optimization to avoid the nested view to be updated when its model data changes. Although is questionable since the cost to unbind/rebind may be bigger than the eventual observers calls in the nested view while it is hidden


This comment has been minimized.

Copy link

jccazeaux commented Jun 28, 2017

After some time i think the optimization causes some problems. If a binder is unbound it should be totally removed and not "cached" for further use. The problem can be seen in components too. See this fiddle

We see that a unbound component keeps a state. It's not logic. The initialize function should be called any time the component is bound. If we want to keep a state we don't use rv-if

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment