[Timers] Simplify mutation calls

This commit is contained in:
Victor Woeltjen
2017-05-03 16:15:17 -07:00
parent 906646704e
commit 6e1a43130d
4 changed files with 8 additions and 36 deletions

View File

@@ -58,16 +58,12 @@ define(
var domainObject = this.domainObject, var domainObject = this.domainObject,
now = this.now; now = this.now;
function setTimerState(model) { function updateModel(model) {
model.timerState = 'paused'; model.timerState = 'paused';
}
function setPausedTime(model) {
model.pausedTime = now(); model.pausedTime = now();
} }
return domainObject.useCapability('mutation', setTimerState) && return domainObject.useCapability('mutation', updateModel);
domainObject.useCapability('mutation', setPausedTime);
}; };
return PauseTimerAction; return PauseTimerAction;

View File

@@ -56,21 +56,13 @@ define(
var domainObject = this.domainObject, var domainObject = this.domainObject,
now = this.now; now = this.now;
function setTimestamp(model) { function updateModel(model) {
model.timestamp = now(); model.timestamp = now();
}
function setTimerState(model) {
model.timerState = 'started'; model.timerState = 'started';
}
function setPausedTime(model) {
model.pausedTime = undefined; model.pausedTime = undefined;
} }
return domainObject.useCapability('mutation', setTimestamp) && return domainObject.useCapability('mutation', updateModel);
domainObject.useCapability('mutation', setTimerState) &&
domainObject.useCapability('mutation', setPausedTime);
}; };
return RestartTimerAction; return RestartTimerAction;

View File

@@ -57,7 +57,7 @@ define(
var domainObject = this.domainObject, var domainObject = this.domainObject,
now = this.now; now = this.now;
function setTimestamp(model) { function updateModel(model) {
//if we are resuming //if we are resuming
if (model.pausedTime) { if (model.pausedTime) {
var timeShift = now() - model.pausedTime; var timeShift = now() - model.pausedTime;
@@ -65,19 +65,11 @@ define(
} else { } else {
model.timestamp = now(); model.timestamp = now();
} }
}
function setTimerState(model) {
model.timerState = 'started'; model.timerState = 'started';
}
function setPausedTime(model) {
model.pausedTime = undefined; model.pausedTime = undefined;
} }
return domainObject.useCapability('mutation', setTimestamp) && return domainObject.useCapability('mutation', updateModel);
domainObject.useCapability('mutation', setTimerState) &&
domainObject.useCapability('mutation', setPausedTime);
}; };
return StartTimerAction; return StartTimerAction;

View File

@@ -57,21 +57,13 @@ define(
StopTimerAction.prototype.perform = function () { StopTimerAction.prototype.perform = function () {
var domainObject = this.domainObject; var domainObject = this.domainObject;
function setTimestamp(model) { function updateModel(model) {
model.timestamp = undefined; model.timestamp = undefined;
}
function setTimerState(model) {
model.timerState = 'stopped'; model.timerState = 'stopped';
}
function setPausedTime(model) {
model.pausedTime = undefined; model.pausedTime = undefined;
} }
return domainObject.useCapability('mutation', setTimestamp) && return domainObject.useCapability('mutation', updateModel);
domainObject.useCapability('mutation', setTimerState) &&
domainObject.useCapability('mutation', setPausedTime);
}; };
return StopTimerAction; return StopTimerAction;