Skip to content

Commit

Permalink
Support property observers which are direct function references in ad…
Browse files Browse the repository at this point in the history
…dition to strings.

Provides better static analysis and refactoring support in multiple tools. Alleviates the need for property reflection with Closure-compiler renaming.
  • Loading branch information
ChadKillingsworth committed Aug 8, 2017
1 parent 9b00efa commit 4bae2b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
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

0 comments on commit 4bae2b6

Please sign in to comment.