From 2e086fec0d5ebacccd54772ca5df74b48abba160 Mon Sep 17 00:00:00 2001 From: Kevin Schaaf Date: Tue, 6 Oct 2015 09:50:58 -0700 Subject: [PATCH] Add notify-path API to templatized template. Fixes #2505. --- src/lib/template/templatizer.html | 16 +++++++++++++--- src/standard/notify-path.html | 19 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/lib/template/templatizer.html b/src/lib/template/templatizer.html index 95dbf34eb0..6d209c60de 100644 --- a/src/lib/template/templatizer.html +++ b/src/lib/template/templatizer.html @@ -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 @@ -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); } }, @@ -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); diff --git a/src/standard/notify-path.html b/src/standard/notify-path.html index 8875cf5df5..0ec156a890 100644 --- a/src/standard/notify-path.html +++ b/src/standard/notify-path.html @@ -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 + }); } });