-
Notifications
You must be signed in to change notification settings - Fork 54
Unbinding a model does not completely make the template's contents disappear #128
Comments
btw, this has the same results with either |
Thanks for filing. |
hmm, thinking about this some more, I think you need to add an I did get it to work by adding Here is the working version:
|
Thanks for researching this, John. I asked more about what bind means, and if this is really a bug, on this thread: https://groups.google.com/forum/?fromgroups=#!topic/polymer-dev/nBdPaVMtcys
|
That's just the thing, there isn't an implicit "if". "If" implies "bind", not the other way around. "bind" just means "make this template active using the provided model". You can also use it to get at a field, e.g. |
You can think of bind as a 1-element repeat. (Which is exactly how it's implemented) |
Thanks John. This is clear to me: "make this template active using the provided model". However, shouldn't the opposite be true? ""make this template inactive if there is no model" That is how it works when the page initially starts up, before I ever bind to that template. Maybe.... I'm "unbinding" by setting model to null (in my Dart version). Perhaps null isn't enough to fully and truly unbind? |
right, I don't think there is a way to "unbind" a template, unless it has the "if" attribute. It is rather strange that this has a side effect which cannot be reversed: var node = querySelector('template'); // note: template has "bind" attribute
node.model = node.model; // set property to itself--harmless right? you can reverse it in a few different ways: node.unbindAll(); // option 1
node.unbind('bind'); // option 2
node.bind('if', false, ''); // option 3 None of those are very satisfying. Also I think MDV will leak a little bit of memory even with unbindAll (IIRC, the TemplateIterator internal object isn't freed when all of the TemplateBinding objects are unregistered). |
So that begs the question, how can you ask if a template has something that is bound? I was doing |
Hmm, it should be possible to do via In JavaScript it's probably safer to do |
So, I agree with you guys that the current semantics are a bit weird. I'm at a loss as to what the "right" behavior is. One option is that template instances will never be created if the model is undefined. That would have the effect that However, to be consistent with that, I think the needs to apply to repeat, so
would also produce zero instances (which pretty much everyone agrees is wrong). This brings me to the fact that template instances must tolerate any model value. FWIW, the real way to remove a "bound" instance is to unbind it, e.g. template.unbind('bind'). That will remove the instance regardless (always). template.model = is really just a short hand for
If you guys can think of a better way to express this API, I'm all ears. |
Thanks for the comments. I'm not sold that template instances must tolerate undefined or null as acceptable model values. If It's weird to let me call |
Raf, can you confirm that "FWIW, the real way to remove a "bound" instance is to unbind it, e.g." also implies that the template is removed from the DOM? |
Seth: Yes. |
Ok. So here's my proposal: add a |
Sounds reasonable to me. |
|
(original bug https://code.google.com/p/dart/issues/detail?id=11983)
I took @sethladd 's example and integrated it into MDV's sample.html:
The text was updated successfully, but these errors were encountered: