From e2312d954de44714e2a9bfb0f3b92c2d58d825d2 Mon Sep 17 00:00:00 2001 From: dherrero Date: Thu, 5 Oct 2017 09:31:28 +0200 Subject: [PATCH] watcher renamed properties --- client/core/src/watcher/watcher.js | 35 ++++++++++++------------------ 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/client/core/src/watcher/watcher.js b/client/core/src/watcher/watcher.js index 87b3d552c1..ec541f21da 100644 --- a/client/core/src/watcher/watcher.js +++ b/client/core/src/watcher/watcher.js @@ -23,7 +23,7 @@ export default class Watcher extends Component { this.state = null; this.deregisterCallback = $transitions.onStart({}, transition => this.callback(transition)); - this.copyData(); + this.updateOriginalData(); } $onInit() { @@ -36,7 +36,7 @@ export default class Watcher extends Component { $onChanges(changes) { if (this.data) { - this.copyData(); + this.updateOriginalData(); } } @@ -50,7 +50,7 @@ export default class Watcher extends Component { this.$http.get(`${this.url}/${id}`).then( json => { this.data = copyObject(json.data); - this.copyData(); + this.updateOriginalData(); } // json => reject(json) ); @@ -127,15 +127,8 @@ export default class Watcher extends Component { } writeData(json, resolve) { - /* Object.keys(this.data).forEach( - key => { - this.data[key] = json.data[key]; - } - );*/ - - this.data = Object.assign(this.data, json.data); - - this.copyData(); + Object.assign(this.data, json.data); + this.updateOriginalData(); resolve(json); } @@ -153,26 +146,26 @@ export default class Watcher extends Component { resolve(); } - copyData() { - this.orgData = this.copyObject(this.data); + updateOriginalData() { + this.orgData = this.copyInNewObject(this.data); } - copyObject(data) { - let copy = {}; - if (data) { + copyInNewObject(data) { + let newCopy = {}; + if (data && typeof data === 'object') { Object.keys(data).forEach( val => { if (data[val] !== "" && data[val] !== undefined && data[val] !== null) { if (typeof data[val] === 'object') { - copy[val] = this.copyObject(data[val]); + newCopy[val] = this.copyInNewObject(data[val]); } else { - copy[val] = data[val]; + newCopy[val] = data[val]; } } } ); } - return copy; + return newCopy; } callback(transition) { @@ -187,7 +180,7 @@ export default class Watcher extends Component { } dataChanged() { - let newData = this.copyObject(this.data); + let newData = this.copyInNewObject(this.data); return !myEqual(newData, this.orgData); }