From efcebac49ad67e8a6c6eae6344fb8f6efe228560 Mon Sep 17 00:00:00 2001 From: varsha Date: Tue, 14 Sep 2021 13:58:20 +0800 Subject: [PATCH] fix: watch oldValue update --- src/view/component.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/view/component.js b/src/view/component.js index 55db9afe..d662c5cd 100644 --- a/src/view/component.js +++ b/src/view/component.js @@ -789,7 +789,7 @@ Component.prototype._update = function (changes) { ); var htmlDirective = this.aNode.directives.html; - + if (this._rootNode) { this._rootNode._update(dataChanges); this._rootNode._getElAsRootNode && (this.el = this._rootNode._getElAsRootNode()); @@ -961,12 +961,15 @@ Component.prototype.watch = function (dataName, listener) { var newValue = evalExpr(dataExpr, me.data, me); if (newValue !== value) { + var oldValue = value; + value = newValue; + try { listener.call( - me, - newValue, + me, + newValue, { - oldValue: value, + oldValue: oldValue, newValue: newValue, change: change } @@ -975,7 +978,6 @@ Component.prototype.watch = function (dataName, listener) { catch (e) { handleError(e, me, 'watch:' + dataName); } - value = newValue; } } });