|
208 | 208 | * @private
|
209 | 209 | */
|
210 | 210 | function runObserverEffect(inst, property, props, oldProps, info) {
|
211 |
| - let fn = inst[info.methodName]; |
| 211 | + let fn = typeof info.method === "string" ? inst[info.method] : info.method; |
212 | 212 | let changedProp = info.property;
|
213 | 213 | if (fn) {
|
214 | 214 | fn.call(inst, inst.__data[changedProp], oldProps[changedProp]);
|
215 | 215 | } else if (!info.dynamicFn) {
|
216 |
| - console.warn('observer method `' + info.methodName + '` not defined'); |
| 216 | + console.warn('observer method `' + info.method + '` not defined'); |
217 | 217 | }
|
218 | 218 | }
|
219 | 219 |
|
|
1989 | 1989 | * full API docs.
|
1990 | 1990 | *
|
1991 | 1991 | * @param {string} property Property name
|
1992 |
| - * @param {string} methodName Name of observer method to call |
| 1992 | + * @param {string|function(*,*)} method Function or name of observer method to call |
1993 | 1993 | * @param {boolean=} dynamicFn Whether the method name should be included as
|
1994 | 1994 | * a dependency to the effect.
|
1995 | 1995 | * @protected
|
1996 | 1996 | */
|
1997 |
| - _createPropertyObserver(property, methodName, dynamicFn) { |
1998 |
| - let info = { property, methodName, dynamicFn: Boolean(dynamicFn) }; |
| 1997 | + _createPropertyObserver(property, method, dynamicFn) { |
| 1998 | + let info = { property, method, dynamicFn: Boolean(dynamicFn) }; |
1999 | 1999 | this._addPropertyEffect(property, TYPES.OBSERVE, {
|
2000 | 2000 | fn: runObserverEffect, info, trigger: {name: property}
|
2001 | 2001 | });
|
2002 | 2002 | if (dynamicFn) {
|
2003 |
| - this._addPropertyEffect(methodName, TYPES.OBSERVE, { |
2004 |
| - fn: runObserverEffect, info, trigger: {name: methodName} |
| 2003 | + this._addPropertyEffect(method, TYPES.OBSERVE, { |
| 2004 | + fn: runObserverEffect, info, trigger: {name: method} |
2005 | 2005 | });
|
2006 | 2006 | }
|
2007 | 2007 | }
|
|
2129 | 2129 | * Creates a single-property observer for the given property.
|
2130 | 2130 | *
|
2131 | 2131 | * @param {string} property Property name
|
2132 |
| - * @param {string} methodName Name of observer method to call |
| 2132 | + * @param {string|function(*,*)} method Function or name of observer method to call |
2133 | 2133 | * @param {boolean=} dynamicFn Whether the method name should be included as
|
2134 | 2134 | * a dependency to the effect.
|
2135 | 2135 | * @protected
|
2136 | 2136 | */
|
2137 |
| - static createPropertyObserver(property, methodName, dynamicFn) { |
2138 |
| - this.prototype._createPropertyObserver(property, methodName, dynamicFn); |
| 2137 | + static createPropertyObserver(property, method, dynamicFn) { |
| 2138 | + this.prototype._createPropertyObserver(property, method, dynamicFn); |
2139 | 2139 | }
|
2140 | 2140 |
|
2141 | 2141 | /**
|
|
0 commit comments