prepareInstanceModel not being called when I expect it to

19 views
Skip to first unread message

Justin Fagnani

unread,
Jan 31, 2014, 4:07:39 PM1/31/14
to polymer-dev, John Messerly, Rafael Weinstein
I'm working on some changes to the Dart version of PolymerExpressions and I'm trying to better use prepareInstanceModel to build up scope objects. I'm finding that prepareInstanceModel isn't being called before the binding closure (returned from prepareBinding) in some cases, causing me to have to check the type of the incoming model and conditionally wrap it in a Scope.

I was hoping that by using prepareInstanceModel to always return a Scope, I could be assured that I always received a Scope in a binding closure. The two cases, so far, that I'm seeing the raw model passed to the binding closure are a binding on template, like <template bind="a as b"> and with custom elements the model is always the element and never a scope.

So is my understanding or prepareInstanceModel incorrect? When is it guaranteed to be called?

Thanks,
  Justin

Rafael Weinstein

unread,
Jan 31, 2014, 5:26:04 PM1/31/14
to Justin Fagnani, polymer-dev, John Messerly
The prepareInstanceModel closure will be called exactly once for each instance that a template needs to produce. The return value will be used as the model parameter to createInstance().

It is also the case that the root model of an element is the element itself, not a closure. I'm not sure I understand the <template bind="a as b"> case you describe.
Reply all
Reply to author
Forward
0 new messages