Permalink
Browse files

Initial release.

  • Loading branch information...
1 parent 200e75f commit 83371257b3f9ec42aef2c785f7c2ef7ae8c171e5 @jprichardson committed Jun 28, 2012
Showing with 134 additions and 1 deletion.
  1. +3 −0 CHANGELOG.md
  2. +54 −0 lib/triggerflow.js
  3. +35 −0 src/triggerflow.coffee
  4. +42 −1 test/triggerflow.test.coffee
View
@@ -0,0 +1,3 @@
+0.0.1 / 2012-06-28
+------------------
+* Initial release.
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -0,0 +1,35 @@
+class TriggerFlow
+ constructor: ->
+ @callback = ->
+ @object = {}
+
+ update: (partialObject) =>
+ for key,val of partialObject
+ #console.log "pobj: #{key},#{val}"
+ if partialObject.hasOwnProperty(key)
+ @object[key] = val
+
+ allTrue = true
+ for key,val of @object
+ #console.log "wobj: #{key},#{val}"
+ if @object.hasOwnProperty(key)
+ if typeof val is 'boolean'
+ allTrue &= val
+ if typeof val is 'number'
+ allTrue &= (val is 0)
+ if !allTrue
+ #console.log 'not all true'
+ return
+ #if we're here, they're allTrue
+ args = []
+ Array.prototype.push.apply(args, arguments)
+ args.shift() #cut partialObject out
+ if @callback? then @callback.apply(null, args)
+
+ @create: (object, callback) ->
+ tf = new TriggerFlow()
+ tf.callback = callback
+ tf.object = object
+ tf
+
+module.exports.TriggerFlow = TriggerFlow
@@ -1,6 +1,47 @@
tutil = require('testutil')
-next = require('../lib/nextflow')
+{TriggerFlow} = require('../lib/triggerflow')
util = require('util')
fs = require('fs-extra')
path = require('path-extra')
+describe 'TriggerFlow', ->
+ it 'should fire the event when the conditions are met', (done) ->
+ processing = 0
+ tf = TriggerFlow.create done: false, processing: processing, ->
+ done()
+
+ setTimeout(->
+ tf.update(done: true)
+ ,5)
+
+ again = ->
+ processing += 1
+ tf.update(processing: processing)
+ setTimeout(->
+ processing -= 1
+ tf.update(processing: processing)
+ ,10)
+ again()
+
+ it 'should fire the event when the conditions are met and retrieve the expected parameters', (done) ->
+ ARBITRARY_STRING = 'hello'
+ ARBITRATY_NUM = 29
+
+ processing = 0
+ tf = TriggerFlow.create done: false, processing: processing, (someNum, someString) ->
+ T someNum is ARBITRATY_NUM
+ T someString is ARBITRARY_STRING
+ done()
+
+ setTimeout(->
+ tf.update(done: true)
+ ,5)
+
+ again = ->
+ processing += 1
+ tf.update(processing: processing, ARBITRATY_NUM, ARBITRARY_STRING)
+ setTimeout(->
+ processing -= 1
+ tf.update(processing: processing, ARBITRATY_NUM, ARBITRARY_STRING)
+ ,10)
+ again()

0 comments on commit 8337125

Please sign in to comment.