do not mutate function args

This commit is contained in:
David Tsay 2020-04-06 18:53:48 -07:00
parent e0c5bca47d
commit 17bca04560

View File

@ -201,7 +201,7 @@ export default class ConditionManager extends EventEmitter {
return currentCondition; return currentCondition;
} }
updateConditionResults(conditionResults, resultObj) { updateConditionResults(resultObj) {
if (!resultObj) { if (!resultObj) {
return; return;
} }
@ -209,13 +209,12 @@ export default class ConditionManager extends EventEmitter {
const id = resultObj.id; const id = resultObj.id;
if (this.findConditionById(id)) { if (this.findConditionById(id)) {
conditionResults[id] = resultObj.data.result; this.conditionResults[id] = resultObj.data.result;
} }
} }
handleConditionResult(resultObj) { handleConditionResult(resultObj) {
this.updateConditionResults(this.conditionResults, resultObj); this.updateConditionResults(resultObj);
const currentCondition = this.getCurrentCondition(this.conditionResults); const currentCondition = this.getCurrentCondition(this.conditionResults);
const timestamp = JSON.parse(JSON.stringify(resultObj.data)) const timestamp = JSON.parse(JSON.stringify(resultObj.data))
delete timestamp.result delete timestamp.result
@ -246,10 +245,13 @@ export default class ConditionManager extends EventEmitter {
return Promise.all(conditionRequests) return Promise.all(conditionRequests)
.then((results) => { .then((results) => {
results.forEach(resultObj => { results.forEach(resultObj => {
this.updateConditionResults(conditionResults, resultObj); const { id, data, data: { result } } = resultObj;
if (this.findConditionById(id)) {
conditionResults[id] = result;
}
latestTimestamp = getLatestTimestamp( latestTimestamp = getLatestTimestamp(
latestTimestamp, latestTimestamp,
resultObj.data, data,
this.timeSystems this.timeSystems
); );
}); });