Closed mgschoen closed 5 years ago
Some prototype mutator methods of the Array prototype perform more than one operation on the Array, making all watchers fire several times for a single operation. In order to prevent that, the respective methods (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype) need to be overwritten and use something like this:
this._executeAsAtomicOperation = function (operation, args) { var target = _this.proxyObject var oldObject = Array.isArray(target) ? [] : {} Object.assign(oldObject, target) _this.atomicOperationOngoing = true operation.apply(target, args) _this.atomicOperationOngoing = false for (var j = 0; j < _this.watchers.length; j++) { _this.watchers[j](oldObject, target) } }
☝️doesn't work because prototype functions are passed by-reference. Next try: https://stackoverflow.com/questions/1833588/javascript-clone-a-function
Some prototype mutator methods of the Array prototype perform more than one operation on the Array, making all watchers fire several times for a single operation. In order to prevent that, the respective methods (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype) need to be overwritten and use something like this: