diff --git a/examples/callback-example.creek b/examples/callback-example.creek new file mode 100644 index 0000000..7438f80 --- /dev/null +++ b/examples/callback-example.creek @@ -0,0 +1,12 @@ +creek = require('../lib/creek') + +agg = creek.compoundAggregator.create() + +agg.track('sum', aggregator: creek.aggregators.sum.alltime, field: 'i') +agg.track('count', aggregator: creek.aggregators.count.alltime, field: 'i') + +agg.on 'change', (newValue, oldValue, name) -> console.log(name, newValue, oldValue) + +agg.push(new Date(), i:1) +agg.push(new Date(), i:3) + diff --git a/examples/twitter.creek b/examples/twitter.creek index bf2a853..252e757 100644 --- a/examples/twitter.creek +++ b/examples/twitter.creek @@ -9,7 +9,7 @@ track 'popular-words', aggregator: popular.timeboxed field: (o) -> if o.text then o.text.toLowerCase().split(' ') else undefined period: 60 - precision: 5 + precision: 1 top: 10 keep: 5 before: (v) -> if v and v.length > 4 then v else undefined @@ -18,6 +18,6 @@ track 'popular-urls', aggregator: popular.timeboxed field: (o) -> if o.text then o.text.split(' ') else undefined period: 60*30 - precision: 60 + precision: 10 top: 5 before: (v) -> if v and v.indexOf('http://') is 0 then v else undefined \ No newline at end of file diff --git a/lib/compound-aggregator.coffee b/lib/compound-aggregator.coffee index 3663810..ad95da7 100644 --- a/lib/compound-aggregator.coffee +++ b/lib/compound-aggregator.coffee @@ -13,9 +13,10 @@ class CompoundAggregator if arguments.length == 3 @aggregators[name].aggregator.on(event, callback) else - event = name callback = event - agg.aggregator.on(event, callback) for name, agg of @aggregators + event = name + for name, agg of @aggregators + ((name) -> agg.aggregator.on(event, (newValue, oldValue) -> callback(newValue, oldValue, name)))(name) push: (time, obj) -> for name, agg of @aggregators val = agg.getValue(obj) diff --git a/package.json b/package.json index 3a72aea..ffd5792 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "creek", "description": "Configurable stream aggregator", - "version": "0.2.2", + "version": "0.2.4", "author": { "name": "Andy Kent", "email": "andy@forward.co.uk"