Skip to content

Commit

Permalink
Add test suite for effects order
Browse files Browse the repository at this point in the history
  • Loading branch information
TimvdLippe committed Feb 5, 2016
1 parent 06cd560 commit 56df8f7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib/bind/accessors.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
_notifyChange: function(source, event, value) {
value = value === undefined ? this[source] : value;
event = event || Polymer.CaseMap.camelToDashCase(source) + '-changed';
this.fire(event, {value: value},
this.fire(event, {value: value},
{bubbles: false, cancelable: false, _useCache: true});
},

Expand Down Expand Up @@ -221,8 +221,8 @@
} else {
// TODO(sorvell): even though we have a `value` argument, we *must*
// lookup the current value of the property. Multiple listeners and
// queued events during configuration can theoretically lead to
// divergence of the passed value from the current value, but we
// queued events during configuration can theoretically lead to
// divergence of the passed value from the current value, but we
// really need to track down a specific case where this happens.
value = target[property];
if (!isStructured) {
Expand Down
83 changes: 83 additions & 0 deletions test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,86 @@
});
</script>
</dom-module>

<dom-module id="x-order-of-effects-parent">
<template>
<x-order-of-effects id="child" base="{{base}}"></x-order-of-effects>
</template>
</dom-module>

<dom-module id="x-order-of-effects">
<template>
<x-order-of-effects-child prop="{{base}}"></x-order-of-effects-child>
<div id="child">{{_computedAnnotation(base)}}</div>
</template>
<script>
(function() {
var invocations = 0;
Polymer({
is: 'x-order-of-effects-child',
properties: {
prop: {
type: String,
observer: '_childProp'
}
},
_childProp: function(prop) {
assert.equal(invocations++, 1);
}
});
Polymer({
is: 'x-order-of-effects',
properties: {
base: {
type: String,
observer: '_observer',
notify: true,
reflectToAttribute: true
},
computed: {
type: String,
computed: '_computed(base)'
},
complex: {
type: String,
value: 'complex'
}
},
observers: ['_complexObserver(complex, base)'],
ready: function() {
var old = this.reflectPropertyToAttribute.bind(this);
this.reflectPropertyToAttribute = function(property, attribute, value) {
assert.equal(invocations++, 3);
old(property, attribute, value);
};
},
_computed: function(base) {
assert.equal(invocations++, 0);
return base;
},
_computedAnnotation: function(base) {
assert.equal(invocations++, 2);
return base;
},
_observer: function() {
assert.equal(invocations++, 5);
},
_complexObserver: function() {
assert.equal(invocations++, 6);
}
});
Polymer({
is: 'x-order-of-effects-parent',
properties: {
base: {
type: String,
observer: '_childPropertyChanged'
}
},
_childPropertyChanged: function() {
assert.equal(invocations++, 4);
}
});
})();
</script>
</dom-module>
13 changes: 13 additions & 0 deletions test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,19 @@

});

suite('order of effects', function() {

var el;

setup(function() {
el = document.createElement('x-order-of-effects-parent').$.child;
});

test('effects are sorted', function() {
el.base = 'changed';
});
});

</script>

</body>
Expand Down

0 comments on commit 56df8f7

Please sign in to comment.