diff --git a/README.md b/README.md index de20c8b..9fad7d0 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Revisiting the previous example, you can solve this problem quite easily with a In `triggerflow`, base conditions are when a `boolean` is `true` and when a `number` is `0`. -Example: +**Example:** ```javascript var trigger = require('triggerflow'); @@ -50,7 +50,7 @@ walk('~/data') .on('file', function(file) { processing += 1; tf.update({processing: processing}); - processFile(function() { //hypothetical async file process function + processFile(file, function() { //hypothetical async file process function processing -= 1; tf.update({processing: processing}); }) diff --git a/src/triggerflow.coffee b/src/triggerflow.coffee deleted file mode 100644 index cd5f9e0..0000000 --- a/src/triggerflow.coffee +++ /dev/null @@ -1,43 +0,0 @@ -class TriggerFlow - constructor: -> - @callback = -> - @object = {} - @hasTriggered = false - - update: (partialObject) => - for key,val of partialObject - #console.log "pobj: #{key},#{val}" - if partialObject.hasOwnProperty(key) - if typeof val is 'number' - if val < 0 #should just decrement - @object[key] = @object[key] + val - else - @object[key] = val - else - @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 - @hasTriggered = true - 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 \ No newline at end of file