Skip to content
This repository has been archived by the owner on Jul 25, 2018. It is now read-only.

Commit

Permalink
treat negative timeouts as infinite
Browse files Browse the repository at this point in the history
when a negative timeout is supplied, CT should not set a new timeout and instead keep the content up indefinitely. this commit also adds some utilities and documentation to improve local testrunning.
  • Loading branch information
lonnen committed May 24, 2013
1 parent 6073e0a commit 55863f2
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
test:
./node_modules/.bin/mocha


.PHONY: test
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ The main file is `crimsontwins.js`. Run that like
```

You should now have a running crimsontwins instance.


Development
===========

Make a feature branch and hack away. When you're ready, open a pull request. Use `make test` to run tests locally.
12 changes: 9 additions & 3 deletions app/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ ScreenManager.prototype.sendUrl = function(url, screenName) {
}
screen.content = content;
p.resolve(content);
self.makeTimeout(screen.name);
self.emit('screenChanged', screen);
},
function fail(error) {
Expand All @@ -108,6 +109,7 @@ ScreenManager.prototype.onContentLoad = function(first_argument) {
screen.content = self.contentManager.next();
self.emit('screenChanged', screen);

// ensure all screens don't change at once
self.makeTimeout(screen.name, skew);
skew += skewIncr;
}
Expand All @@ -123,13 +125,17 @@ ScreenManager.prototype.cycleScreen = function(name) {

ScreenManager.prototype.makeTimeout = function(name, time) {
var oldTimeout = this.timeouts[name];
if (arguments.length < 2) {
time = config.resetTime;
}

if (oldTimeout) {
clearTimeout(oldTimeout);
}
if (time === undefined) {
time = config.resetTime;

if (time > -1) {
this.timeouts[name] = setTimeout(this.cycleScreen.bind(this, name), time);
}
this.timeouts[name] = setTimeout(this.cycleScreen.bind(this, name), time);
};

ScreenManager.prototype.reset = function(screenName) {
Expand Down
12 changes: 11 additions & 1 deletion test/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,16 @@ describe('ScreenManager', function() {
clock.tick(60);
assert.notEqual(screen.content.url, before);
});

it('should not timeout when passed a negative time', function() {
var screen = screenMan.screens[0];
var before = screen.content.url;
screenMan.makeTimeout(screen.name, -1);
clock.tick(mockConfig.resetTime);
assert.equal(screen.content.url, before);
clock.tick(mockConfig.resetTime + 1); // induction step
assert.equal(screen.content.url, before);
})
});

describe('#reset', function() {
Expand Down Expand Up @@ -384,4 +394,4 @@ describe('ContentManager', function() {
cm.load();
});
});
});
});
File renamed without changes.

0 comments on commit 55863f2

Please sign in to comment.