Skip to content

Commit

Permalink
Merged mode-specific defaults, with some refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Aug 4, 2016
2 parents f96f78f + 9a72c96 commit 6b482d4
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 17 deletions.
10 changes: 0 additions & 10 deletions example/localTimeSystem/src/LADTickSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,6 @@ define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/Local
}
LADTickSource.prototype = Object.create(LocalClock.prototype);

LADTickSource.prototype.tick = function () {
console.log('data tick');
var now = Date.now();
this.listeners.forEach(function (listener){
listener(now);
});
this.timeoutHandle = this.$timeout(this.tick.bind(this), this.period);
};


LADTickSource.prototype.type = function () {
return 'data';
};
Expand Down
9 changes: 9 additions & 0 deletions example/localTimeSystem/src/LocalTimeSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ define([
'./LADTickSource'
], function (TimeSystem, LocalClock, LADTickSource) {
var FIFTEEN_MINUTES = 15 * 60 * 1000,
THIRTY_MINUTES = 30 * 60 * 1000,
DEFAULT_PERIOD = 1000;

/**
Expand Down Expand Up @@ -71,8 +72,16 @@ define([
{
key: 'local-default',
name: 'Local 12 hour time system defaults',
mode: 'fixed',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
},
{
key: 'local-default',
name: 'Local 12 hour time system defaults',
mode: 'follow',
deltas: {start: THIRTY_MINUTES, end: 0},
bounds: {start: now - THIRTY_MINUTES, end: now}
}
];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ define(['./TickSource'], function (TickSource) {
};

LocalClock.prototype.tick = function () {
console.log('clock tick');
var now = Date.now();
this.listeners.forEach(function (listener){
listener(now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ define(
/**
* @private
*/
TimeConductorController.prototype.setDeltasFromTimeSystem = function (timeSystem) {
var defaults = timeSystem.defaults()[0];
TimeConductorController.prototype.setDeltasFromMode = function (mode) {
var defaults = mode.defaults();
var deltas = defaults.deltas;

/*
Expand Down Expand Up @@ -295,7 +295,7 @@ define(
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode();
mode.timeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
this.setDeltasFromMode(mode);

// If current mode supports ticking, set an appropriate tick
// source from the new time system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ define(
this.conductor.follow(false);
};

FixedMode.prototype.defaults = function () {
var timeSystem = this.timeSystem();

if (timeSystem){
return timeSystem.defaults().filter(function (d) {
return d.mode === 'fixed';
})[0];
}
};

/**
* Defines behavior to occur when selected time system changes. In
* this case, sets default bounds on the time conductor.
Expand All @@ -53,7 +63,7 @@ define(
TimeConductorMode.prototype.timeSystem.apply(this, arguments);

if (timeSystem) {
var defaults = timeSystem.defaults()[0];
var defaults = this.defaults();

var bounds = {
start: defaults.bounds.start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ define(
* Get or set tick source. Setting tick source will also start
* listening to it and unlisten from any existing tick source
* @param tickSource
* @returns {undefined|*}
* @returns {TickSource}
*/
FollowMode.prototype.tickSource = function (tickSource) {
if (tickSource) {
Expand All @@ -77,6 +77,16 @@ define(
return this._tickSource;
};

FollowMode.prototype.defaults = function () {
var timeSystem = this.timeSystem();

if (timeSystem){
return timeSystem.defaults().filter(function (d) {
return d.mode === 'follow';
})[0];
}
};

/**
* On time system change, default the bounds values in the time
* conductor, using the deltas associated with this mode.
Expand All @@ -87,7 +97,7 @@ define(
TimeConductorMode.prototype.timeSystem.apply(this, arguments);

if (timeSystem) {
var defaults = timeSystem.defaults()[0];
var defaults = this.defaults();

if (arguments.length > 0) {
var bounds = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ define(
return this._key;
};

TimeConductorMode.prototype.defaults = function () {
throw new Error("Not implemented");
};

TimeConductorMode.prototype.destroy = function () {
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ define([
{
key: 'utc-default',
name: 'UTC time system defaults',
mode: 'follow',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
},
{
key: 'utc-default',
name: 'UTC time system defaults',
mode: 'fixed',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
}
Expand Down

0 comments on commit 6b482d4

Please sign in to comment.