Skip to content

Commit

Permalink
Ensure no warnings for dynamic fns. Fixes #4575
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed May 4, 2017
1 parent a284d77 commit d72baf9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
let changedProp = info.property;
if (fn) {
fn.call(inst, inst.__data[changedProp], oldProps[changedProp]);
} else {
} else if (!info.dynamicFn) {
console.warn('observer method `' + info.methodName + '` not defined');
}
}
Expand Down Expand Up @@ -1905,7 +1905,7 @@
* @protected
*/
_createPropertyObserver(property, methodName, dynamicFn) {
let info = { property, methodName };
let info = { property, methodName, dynamicFn };
this._addPropertyEffect(property, TYPES.OBSERVE, {
fn: runObserverEffect, info, trigger: {name: property}
});
Expand Down Expand Up @@ -2317,6 +2317,7 @@
let dynamicFns = templateInfo.dynamicFns;
if (dynamicFns && dynamicFns[methodName] || signature.static) {
dependencies.push(methodName);
signature.dynamicFn = true;
}
} else {
// Property or path
Expand Down
14 changes: 11 additions & 3 deletions test/unit/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,13 @@

var el;

setup(function() {
sinon.spy(console, 'warn');
});

teardown(function() {
document.body.removeChild(el);
console.warn.restore();
});

test('annotated computation with dynamic function', function() {
Expand All @@ -407,6 +412,7 @@
};

assert.equal(el.$.check.textContent, 'changed: Hello World.');
assert.equal(console.warn.callCount, 0);
});

test('annotated computation / late resolved dynamic function', function() {
Expand All @@ -420,6 +426,7 @@
};

assert.equal(el.$.check.textContent, 'translated: Hello');
assert.equal(console.warn.callCount, 0);
});

test('method observer with dynamic function', function() {
Expand All @@ -444,7 +451,7 @@

el.translateMessage = sinon.spy();
assert.equal(el.translateMessage.callCount, 1);

assert.equal(console.warn.callCount, 0);
});

test('observer with dynamic function', function() {
Expand All @@ -468,7 +475,7 @@

el.messageChanged = sinon.spy();
assert.equal(el.messageChanged.callCount, 1);

assert.equal(console.warn.callCount, 0);
});

test('computed property with dynamic function', function() {
Expand Down Expand Up @@ -497,7 +504,7 @@

assert.equal(called, 1);
assert.equal(el.computedValue, 'translated: Hello');

assert.equal(console.warn.callCount, 0);
});

test('ensure annotator can pass dynamic fn to parent props', function(done) {
Expand All @@ -507,6 +514,7 @@
setTimeout(function() {
var check = el.root.querySelector('p');
assert.equal(check.textContent, 'text');
assert.equal(console.warn.callCount, 0);
done();
});

Expand Down

0 comments on commit d72baf9

Please sign in to comment.