Skip to content

Commit

Permalink
Add notify-path API to templatized template. Fixes #2505.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Oct 6, 2015
1 parent 23c883b commit 2e086fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/lib/template/templatizer.html
Expand Up @@ -224,6 +224,7 @@
// assume that the template is not a Poylmer.Base, so prep it
// for binding
Polymer.Bind.prepareModel(proto);
Polymer.Base.prepareModelNotifyPath(proto);
}
// Create accessors for each parent prop that forward the property
// to template instances through abstract _forwardParentProp API
Expand All @@ -240,12 +241,12 @@
}
}
// Instance setup
this._extendTemplate(template, proto);
if (template != this) {
Polymer.Bind.prepareInstance(template);
template._forwardParentProp =
this._forwardParentProp.bind(this);
template._forwardParentProp = this._forwardParentProp.bind(this);
template._pathEffector = this._pathEffectorTemplate.bind(this);
}
this._extendTemplate(template, proto);
}
},

Expand Down Expand Up @@ -312,6 +313,15 @@
Polymer.Base._pathEffector.apply(this, arguments);
},

// Overrides Base notify-path module (for non-PE templates)
_pathEffectorTemplate: function(path, value, fromAbove) {
if (this._forwardParentPath) {
if (path.indexOf(this._parentPropPrefix) === 0) {
this._forwardParentPath(path.substring(8), value);
}
}
},

_constructorImpl: function(model, host) {
this._rootDataHost = host._getRootDataHost();
this._setupConfigure(model);
Expand Down
19 changes: 19 additions & 0 deletions src/standard/notify-path.html
Expand Up @@ -483,6 +483,25 @@
this._notifySplice(array, path, 0, args.length, []);
}
return ret;
},

// TODO(kschaaf): This is the path analogue to Polymer.Bind.prepareModel,
// which provides API for path-based notification on elements with property
// effects; this should be re-factored along with the Bind lib, either all on
// Base or all in Bind.
prepareModelNotifyPath: function(model) {
this.mixin(model, {
notifyPath: Polymer.Base.notifyPath,
_notifyPath: Polymer.Base._notifyPath,
_pathEffector: Polymer.Base._pathEffector,
_annotationPathEffect: Polymer.Base._annotationPathEffect,
_complexObserverPathEffect: Polymer.Base._complexObserverPathEffect,
_annotatedComputationPathEffect: Polymer.Base._annotatedComputationPathEffect,
_computePathEffect: Polymer.Base._computePathEffect,
_modelForPath: Polymer.Base._modelForPath,
_pathMatchesEffect: Polymer.Base._pathMatchesEffect,
_notifyBoundPaths: Polymer.Base._notifyBoundPaths
});
}

});
Expand Down

0 comments on commit 2e086fe

Please sign in to comment.