[Clocks/Timers] Update code style for actions

https://github.com/nasa/openmctweb/issues/209
This commit is contained in:
Victor Woeltjen 2015-12-09 12:17:32 -08:00
parent 89a93e2966
commit e30a82432d
3 changed files with 45 additions and 13 deletions

View File

@ -35,10 +35,21 @@ define(
* Both "Start" and "Restart" share this implementation, but * Both "Start" and "Restart" share this implementation, but
* control their visibility with different `appliesTo` behavior. * control their visibility with different `appliesTo` behavior.
* *
* @implements Action * @implements {Action}
* @memberof platform/features/clock
* @constructor
* @param {Function} now a function which returns the current
* time (typically wrapping `Date.now`)
* @param {ActionContext} context the context for this action
*/ */
function AbstractStartTimerAction(now, context) { function AbstractStartTimerAction(now, context) {
var domainObject = context.domainObject; this.domainObject = context.domainObject;
this.now = now;
}
AbstractStartTimerAction.prototype.perform = function () {
var domainObject = this.domainObject,
now = this.now;
function doPersist() { function doPersist() {
var persistence = domainObject.getCapability('persistence'); var persistence = domainObject.getCapability('persistence');
@ -49,13 +60,9 @@ define(
model.timestamp = now(); model.timestamp = now();
} }
return {
perform: function () {
return domainObject.useCapability('mutation', setTimestamp) return domainObject.useCapability('mutation', setTimestamp)
.then(doPersist); .then(doPersist);
}
}; };
}
return AbstractStartTimerAction; return AbstractStartTimerAction;
} }

View File

@ -31,12 +31,25 @@ define(
* *
* Behaves the same as (and delegates functionality to) * Behaves the same as (and delegates functionality to)
* the "Start" action. * the "Start" action.
* @implements Action *
* @extends {platform/features/clock.AbstractTimerAction}
* @implements {Action}
* @memberof platform/features/clock
* @constructor
* @param {Function} now a function which returns the current
* time (typically wrapping `Date.now`)
* @param {ActionContext} context the context for this action
*/ */
function RestartTimerAction(now, context) { function RestartTimerAction(now, context) {
return new AbstractStartTimerAction(now, context); AbstractStartTimerAction.prototype.apply(
this,
[ now, context ]
);
} }
RestartTimerAction.prototype =
Object.create(AbstractStartTimerAction.prototype);
RestartTimerAction.appliesTo = function (context) { RestartTimerAction.appliesTo = function (context) {
var model = var model =
(context.domainObject && context.domainObject.getModel()) (context.domainObject && context.domainObject.getModel())

View File

@ -32,12 +32,24 @@ define(
* Sets the reference timestamp in a timer to the current * Sets the reference timestamp in a timer to the current
* time, such that it begins counting up. * time, such that it begins counting up.
* *
* @implements Action * @extends {platform/features/clock.AbstractTimerAction}
* @implements {Action}
* @memberof platform/features/clock
* @constructor
* @param {Function} now a function which returns the current
* time (typically wrapping `Date.now`)
* @param {ActionContext} context the context for this action
*/ */
function StartTimerAction(now, context) { function StartTimerAction(now, context) {
return new AbstractStartTimerAction(now, context); AbstractStartTimerAction.prototype.apply(
this,
[ now, context ]
);
} }
StartTimerAction.prototype =
Object.create(AbstractStartTimerAction.prototype);
StartTimerAction.appliesTo = function (context) { StartTimerAction.appliesTo = function (context) {
var model = var model =
(context.domainObject && context.domainObject.getModel()) (context.domainObject && context.domainObject.getModel())