Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support property observers which are direct function references #4574

Merged
merged 1 commit into from
Dec 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lib/mixins/property-effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,12 @@
* @private
*/
function runObserverEffect(inst, property, props, oldProps, info) {
let fn = inst[info.methodName];
let fn = typeof info.method === "string" ? inst[info.method] : info.method;
let changedProp = info.property;
if (fn) {
fn.call(inst, inst.__data[changedProp], oldProps[changedProp]);
} else if (!info.dynamicFn) {
console.warn('observer method `' + info.methodName + '` not defined');
console.warn('observer method `' + info.method + '` not defined');
}
}

Expand Down Expand Up @@ -1989,19 +1989,19 @@
* full API docs.
*
* @param {string} property Property name
* @param {string} methodName Name of observer method to call
* @param {string|function(*,*)} method Function or name of observer method to call
* @param {boolean=} dynamicFn Whether the method name should be included as
* a dependency to the effect.
* @protected
*/
_createPropertyObserver(property, methodName, dynamicFn) {
let info = { property, methodName, dynamicFn: Boolean(dynamicFn) };
_createPropertyObserver(property, method, dynamicFn) {
let info = { property, method, dynamicFn: Boolean(dynamicFn) };
this._addPropertyEffect(property, TYPES.OBSERVE, {
fn: runObserverEffect, info, trigger: {name: property}
});
if (dynamicFn) {
this._addPropertyEffect(methodName, TYPES.OBSERVE, {
fn: runObserverEffect, info, trigger: {name: methodName}
this._addPropertyEffect(method, TYPES.OBSERVE, {
fn: runObserverEffect, info, trigger: {name: method}
});
}
}
Expand Down Expand Up @@ -2129,13 +2129,13 @@
* Creates a single-property observer for the given property.
*
* @param {string} property Property name
* @param {string} methodName Name of observer method to call
* @param {string|function(*,*)} method Function or name of observer method to call
* @param {boolean=} dynamicFn Whether the method name should be included as
* a dependency to the effect.
* @protected
*/
static createPropertyObserver(property, methodName, dynamicFn) {
this.prototype._createPropertyObserver(property, methodName, dynamicFn);
static createPropertyObserver(property, method, dynamicFn) {
this.prototype._createPropertyObserver(property, method, dynamicFn);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/unit/property-effects-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@
},
prop2: {
value: 'default',
observer: 'prop2Changed'
observer: function(newProp, oldProp) { return this.prop2Changed(newProp, oldProp); }
}
},
created: function() {
Expand Down