Skip to content

Commit

Permalink
example for callback usage and some fixes for unnamed callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
andykent committed Sep 28, 2011
1 parent 8aeb8bf commit 4032f5a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
12 changes: 12 additions & 0 deletions 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)

4 changes: 2 additions & 2 deletions examples/twitter.creek
Expand Up @@ -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
Expand All @@ -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
5 changes: 3 additions & 2 deletions lib/compound-aggregator.coffee
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 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"
Expand Down

0 comments on commit 4032f5a

Please sign in to comment.