diff --git a/platform/features/clock/src/actions/AbstractStartTimerAction.js b/platform/features/clock/src/actions/AbstractStartTimerAction.js index 8c1554965c..116a5e51f4 100644 --- a/platform/features/clock/src/actions/AbstractStartTimerAction.js +++ b/platform/features/clock/src/actions/AbstractStartTimerAction.js @@ -35,10 +35,21 @@ define( * Both "Start" and "Restart" share this implementation, but * 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) { - var domainObject = context.domainObject; + this.domainObject = context.domainObject; + this.now = now; + } + + AbstractStartTimerAction.prototype.perform = function () { + var domainObject = this.domainObject, + now = this.now; function doPersist() { var persistence = domainObject.getCapability('persistence'); @@ -49,13 +60,9 @@ define( model.timestamp = now(); } - return { - perform: function () { - return domainObject.useCapability('mutation', setTimestamp) - .then(doPersist); - } - }; - } + return domainObject.useCapability('mutation', setTimestamp) + .then(doPersist); + }; return AbstractStartTimerAction; } diff --git a/platform/features/clock/src/actions/RestartTimerAction.js b/platform/features/clock/src/actions/RestartTimerAction.js index 8c8a942281..ae490df99d 100644 --- a/platform/features/clock/src/actions/RestartTimerAction.js +++ b/platform/features/clock/src/actions/RestartTimerAction.js @@ -31,12 +31,25 @@ define( * * Behaves the same as (and delegates functionality to) * 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) { - return new AbstractStartTimerAction(now, context); + AbstractStartTimerAction.prototype.apply( + this, + [ now, context ] + ); } + RestartTimerAction.prototype = + Object.create(AbstractStartTimerAction.prototype); + RestartTimerAction.appliesTo = function (context) { var model = (context.domainObject && context.domainObject.getModel()) diff --git a/platform/features/clock/src/actions/StartTimerAction.js b/platform/features/clock/src/actions/StartTimerAction.js index d7237c75e4..fb433608c3 100644 --- a/platform/features/clock/src/actions/StartTimerAction.js +++ b/platform/features/clock/src/actions/StartTimerAction.js @@ -32,12 +32,24 @@ define( * Sets the reference timestamp in a timer to the current * 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) { - return new AbstractStartTimerAction(now, context); + AbstractStartTimerAction.prototype.apply( + this, + [ now, context ] + ); } + StartTimerAction.prototype = + Object.create(AbstractStartTimerAction.prototype); + StartTimerAction.appliesTo = function (context) { var model = (context.domainObject && context.domainObject.getModel())