Skip to content

Commit

Permalink
Add templatizer tests. Fix issues from tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Oct 8, 2015
1 parent 2e086fe commit 2d97cd7
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@
// archetypes do special caching
this._customPrepAnnotations(archetype, template);

// forward parent properties to archetype
this._prepParentProperties(archetype, template);

// setup accessors
archetype._prepEffects();
this._customPrepEffects(archetype);
archetype._prepBehaviors();
archetype._prepBindings();

// forward parent properties to archetype
this._prepParentProperties(archetype, template);

// boilerplate code
archetype._notifyPath = this._notifyPathImpl;
archetype._scopeElementClass = this._scopeElementClassImpl;
Expand Down Expand Up @@ -241,10 +241,12 @@
}
}
// Instance setup
this._extendTemplate(template, proto);
if (template != this) {
Polymer.Bind.prepareInstance(template);
template._forwardParentProp = this._forwardParentProp.bind(this);
}
this._extendTemplate(template, proto);
if (template != this) {
template._pathEffector = this._pathEffectorTemplate.bind(this);
}
}
Expand All @@ -259,7 +261,7 @@
_createHostPropEffector: function(prop) {
var prefix = this._parentPropPrefix;
return function(source, value) {
this.dataHost[prefix + prop] = value;
this.dataHost._templatized[prefix + prop] = value;
};
},

Expand Down Expand Up @@ -299,7 +301,7 @@
// Call extension point for Templatizer sub-classes
dataHost._forwardInstancePath.call(dataHost, this, path, value);
if (root in dataHost._parentProps) {
dataHost.notifyPath(dataHost._parentPropPrefix + path, value);
dataHost._templatized.notifyPath(dataHost._parentPropPrefix + path, value);
}
},

Expand Down
2 changes: 2 additions & 0 deletions src/standard/notify-path.html
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,9 @@
// Base or all in Bind.
prepareModelNotifyPath: function(model) {
this.mixin(model, {
fire: Polymer.Base.fire,
notifyPath: Polymer.Base.notifyPath,
_EVENT_CHANGED: Polymer.Base._EVENT_CHANGED,
_notifyPath: Polymer.Base._notifyPath,
_pathEffector: Polymer.Base._pathEffector,
_annotationPathEffect: Polymer.Base._annotationPathEffect,
Expand Down
1 change: 1 addition & 0 deletions test/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
'unit/styling-cross-scope-unknown-host.html',
'unit/custom-style.html',
'unit/dynamic-import.html',
'unit/templatizer.html',
'unit/dom-repeat.html',
'unit/dom-if.html',
'unit/dom-bind.html',
Expand Down
221 changes: 221 additions & 0 deletions test/unit/templatizer-elements.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
<dom-module id="x-host">
<template>

<x-templatizer obj="{{objA}}" prop="{{propA}}" id="templatizer">
<template>
<x-child id="childA"
outer-prop="{{outerProp}}"
outer-obj="{{outerObj}}"
outer-obj-prop="{{outerObj.prop}}"
prop="{{prop}}"
obj="{{obj}}"
obj-prop="{{obj.prop}}"
></x-child>
</template>
</x-templatizer>

<template is="x-templatizee" obj="{{objB}}" prop="{{propB}}" id="templatizee">
<x-child id="childB"
outer-prop="{{outerProp}}"
outer-obj="{{outerObj}}"
outer-obj-prop="{{outerObj.prop}}"
prop="{{prop}}"
obj="{{obj}}"
obj-prop="{{obj.prop}}"
></x-child>
</template>

</template>
</dom-module>

<script>
Polymer({
is: 'x-child',
properties: {
outerProp: {
notify: true
},
outerObj: {
notify: true
},
outerObjProp: {
notify: true
},
prop: {
notify: true
},
obj: {
notify: true
},
objProp: {
notify: true
}
},
observers: [
'objChanged(obj.*)',
'outerObjChanged(outerObj.*)'
],
objChanged: function() {},
outerObjChanged: function() {}
});

Polymer({
is: 'x-templatizer',
behaviors: [Polymer.Templatizer],
properties: {
obj: {
notify: true
},
prop: {
notify: true,
observer: 'propChanged'
}
},
observers: [
'objChanged(obj.*)'
],
_instanceProps: {
obj: true,
prop: true
},
propChanged: function(value) {
this._forwardParentProp('prop', value);
},
objChanged: function(info) {
if (info.path == 'obj') {
this._forwardParentProp('obj', info.value);
} else {
this._forwardParentPath(info.path, info.value);
}
},
_forwardParentProp: function(prop, value) {
if (this.instance) {
this.instance[prop] = value;
}
},
_forwardParentPath: function(path, value) {
if (this.instance) {
this.instance.notifyPath(path, value, true);
}
},
_forwardInstanceProp: function(inst, prop, value) {
if (prop == 'obj') {
this.obj = value;
} else if (prop == 'prop') {
this.prop = value;
}
},
_forwardInstancePath: function(inst, path, value) {
if ((path.indexOf('obj.') === 0) || (path.indexOf('prop.') === 0)) {
this.notifyPath(path, value);
}
},
go: function() {
var template = Polymer.dom(this).querySelector('template');
this.templatize(template);
this.instance = this.stamp({obj: this.obj, prop: this.prop});
var parent = Polymer.dom(this).parentNode;
Polymer.dom(parent).appendChild(this.instance.root);
}
});

Polymer({
is: 'x-templatizee',
extends: 'template',
behaviors: [Polymer.Templatizer],
properties: {
obj: {
notify: true
},
prop: {
notify: true,
observer: 'propChanged'
}
},
observers: [
'objChanged(obj.*)'
],
_instanceProps: {
obj: true,
prop: true
},
propChanged: function(value) {
this._forwardParentProp('prop', value);
},
objChanged: function(info) {
if (info.path == 'obj') {
this._forwardParentProp('obj', info.value);
} else {
this._forwardParentPath(info.path, info.value);
}
},
_forwardParentProp: function(prop, value) {
if (this.instance) {
this.instance[prop] = value;
}
},
_forwardParentPath: function(path, value) {
if (this.instance) {
this.instance.notifyPath(path, value, true);
}
},
_forwardInstanceProp: function(inst, prop, value) {
if (prop == 'obj') {
this.obj = value;
} else if (prop == 'prop') {
this.prop = value;
}
},
_forwardInstancePath: function(inst, path, value) {
if ((path.indexOf('obj.') === 0) || (path.indexOf('prop.') === 0)) {
this.notifyPath(path, value);
}
},
go: function() {
this.templatize(this);
this.instance = this.stamp({obj: this.obj, prop: this.prop});
var parent = Polymer.dom(this).parentNode;
Polymer.dom(parent).appendChild(this.instance.root);
}
});

Polymer({
is: 'x-host',
properties: {
outerProp: {
value: 'outerProp'
},
outerObj: {
value: function() {
return { prop: 'outerObj.prop' };
}
},
propA: {
value: 'prop-a'
},
objA: {
value: function() {
return { prop: 'objA.prop' };
}
},
propB: {
value: 'prop-b'
},
objB: {
value: function() {
return { prop: 'objB.prop' };
}
}
},
observers: [
'outerObjChanged(outerObj.*)',
'objAChanged(objA.*)',
'objBChanged(objB.*)'
],
outerObjChanged: function() {},
objAChanged: function() {},
objBChanged: function() {}
});

</script>

Loading

0 comments on commit 2d97cd7

Please sign in to comment.