mikeric / rivets

Lightweight and powerful data binding.
http://rivetsjs.com
MIT License
3.23k stars 310 forks source link

Reset a binding before updating it? #727

Open rejhgadellaa opened 6 years ago

rejhgadellaa commented 6 years ago

Is there a way to 'reset' a binding before updating it?

For example, if I have this:

{data: { image: "someimage.jpg" }}
<img rv-src="data.image" />

it produces this after binding:

<img rv-src="data.image" src="someimage.jpg" />

But when I update the model with this:

{data: { image: "some-other-image.jpg" }}

the old image is still in place until the browser loaded the new image.

I'm also having an issue where attributes that I add don't get cleared out when updating:

<img rv-src="data.image" />

Becomes:

<img rv-src="data.image" src="someimage.jpg" />

Then, I add an attribute through javascript:

<img rv-src="data.image" src="someimage.jpg" data-custom-attr />

But when I update the model it still has the attribute (without me adding it):

<img rv-src="data.image" src="some-other-image.jpg" data-custom-attr />

What I want is rivets to use the template I initially used to bind the data, not what's currently in the DOM (because I may need to change that).

I hope the above is clear enough..?