Permalink
Browse files

add a name to each tadaa.start to allow multiple at once

  • Loading branch information...
1 parent 038475b commit 41dd738d3a4741a7d94a97f37e2725835c277d89 @jamesbloomer committed Oct 9, 2013
Showing with 29 additions and 11 deletions.
  1. +1 −0 README.md
  2. +2 −1 example/random_number.js
  3. +8 −7 lib/tadaa.js
  4. +1 −1 package.json
  5. +17 −2 test/tadaa_test.js
View
1 README.md
@@ -48,6 +48,7 @@ Use as a module like this:
var getValueOptions = { a : 1, b : 2 };
tadaa.start(
+ 'a_name_for_this_monitor',
interval,
[{fn: fnup, sound:up}, {fn: fndown, sound:down}],
getValue,
View
3 example/random_number.js
@@ -25,8 +25,9 @@ var getValue = function(options, callback){
var getValueOptions = { a : 1, b : 2 };
tadaa.start(
+ 'random',
interval,
[{fn: fnup, sound:up}, {fn: fndown, sound:down}],
getValue,
getValueOptions,
- audioPlayer);
+ audioPlayer);
View
15 lib/tadaa.js
@@ -3,7 +3,7 @@ var child = require('child_process'),
var tadaa = {};
-tadaa.current = 0;
+tadaa.current = [];
tadaa.playCorrectSound = function(incurrent, result, logic, audioPlayer, callback) {
@@ -40,20 +40,21 @@ tadaa.dropToZero = function(currentValue, newValue) {
return currentValue > 0 && newValue === 0;
};
-tadaa.getValueAndPlaySound = function(logicArray, getValue, getValueOptions, audioPlayer) {
+tadaa.getValueAndPlaySound = function(name, logicArray, getValue, getValueOptions, audioPlayer) {
var logic = logicArray;
var player = audioPlayer;
getValue(getValueOptions, function(error, result) {
- tadaa.playCorrectSound(tadaa.current, result, logic, player, function(error) {
- tadaa.current = result;
+ tadaa.playCorrectSound(tadaa.current[name], result, logic, player, function(error) {
+ tadaa.current[name] = result;
return;
});
});
};
-tadaa.start = function(interval, logic, getValue, getValueOptions, audioPlayer) {
- setInterval(this.getValueAndPlaySound, interval, logic, getValue, getValueOptions, audioPlayer);
+tadaa.start = function(name, interval, logic, getValue, getValueOptions, audioPlayer) {
+ tadaa.current[name] = 0;
+ setInterval(tadaa.getValueAndPlaySound, interval, name, logic, getValue, getValueOptions, audioPlayer);
};
-module.exports = tadaa;
+module.exports = tadaa;
View
2 package.json
@@ -1,7 +1,7 @@
{
"name": "tadaa",
"description": "Monitor stuff via the medium of sound.",
- "version": "0.2.2",
+ "version": "0.2.3",
"licenses": [{
"type": "MIT",
"url": "https://github.com/jamesbloomer/tadaa/raw/master/LICENSE"
View
19 test/tadaa_test.js
@@ -141,7 +141,7 @@ describe('Tadaa', function() {
beforeEach(function() {
sinon.stub(tadaa, 'getValueAndPlaySound');
clock = sinon.useFakeTimers();
- tadaa.start(10, [{fn: tadaa.up, sound:'upsound'}, {fn: tadaa.down, sound:'downsound'}], 'getValue', 'getValueOptions', 'audioPlayer');
+ tadaa.start('NAME', 10, [{fn: tadaa.up, sound:'upsound'}, {fn: tadaa.down, sound:'downsound'}], 'getValue', 'getValueOptions', 'audioPlayer');
clock.tick(15);
});
@@ -152,6 +152,21 @@ describe('Tadaa', function() {
it('should call getValueAndPlaySound', function() {
assert(tadaa.getValueAndPlaySound.calledOnce);
+ // TODO args coming back undefined in test
+ // assert.deepEqual(tadaa.getValueAndPlaySound.args[0][0], 'NAME');
+ // assert.deepEqual(tadaa.getValueAndPlaySound.args[0][1], [{fn: tadaa.up, sound:'upsound'}, {fn: tadaa.down, sound:'downsound'}]);
+ // assert.deepEqual(tadaa.getValueAndPlaySound.args[0][2], 'getValue');
+ // assert.deepEqual(tadaa.getValueAndPlaySound.args[0][3], 'getValueOptions');
+ // assert.deepEqual(tadaa.getValueAndPlaySound.args[0][4], 'audioPlayer');
});
});
-});
+
+ describe('with two different tags', function() {
+ // TODO
+ // first : 10 -> 20 -> 30 === up played twice
+ // second : 5 -> 15 -> 25 === up played twice
+
+ // -> 20, 15, 30, 25
+
+ });
+});

0 comments on commit 41dd738

Please sign in to comment.