use mergeWith in requestAddMonitor, requestUpdateMonitor

So undefined values don't overwrite defined ones
This commit is contained in:
Connor Hudson 2018-06-06 15:54:12 -04:00
parent c2645f3da5
commit 18640d7ddc

View file

@ -1522,7 +1522,17 @@ class Runtime extends EventEmitter {
* @param {!MonitorRecord} monitor Monitor to add. * @param {!MonitorRecord} monitor Monitor to add.
*/ */
requestAddMonitor (monitor) { requestAddMonitor (monitor) {
this._monitorState = this._monitorState.set(monitor.get('id'), monitor); const id = monitor.get('id');
if (this._monitorState.has(id)) {
this._monitorState = this._monitorState.set(id, this._monitorState.get(id).mergeWith((prev, next) => {
if (!next) {
return prev;
}
return next;
}, monitor));
} else {
this._monitorState = this._monitorState.set(id, monitor);
}
} }
/** /**
@ -1536,7 +1546,12 @@ class Runtime extends EventEmitter {
const id = monitor.get('id'); const id = monitor.get('id');
if (this._monitorState.has(id)) { if (this._monitorState.has(id)) {
this._monitorState = this._monitorState =
this._monitorState.set(id, this._monitorState.get(id).merge(monitor)); this._monitorState.set(id, this._monitorState.get(id).mergeWith((prev, next) => {
if (!next) {
return prev;
}
return next;
}, monitor));
} }
} }