Comparing version 4.0.0 to 5.0.0
@@ -59,5 +59,5 @@ var EventEmitter = require('events').EventEmitter, | ||
server = { | ||
ready: eventuate(), | ||
ready : eventuate(), | ||
connection: eventuate(), | ||
request: eventuate() | ||
request : eventuate() | ||
} |
@@ -15,5 +15,5 @@ var eventuate = require('..'), | ||
// handle next event with a promise (think .once) | ||
request().then(function nextRequest (req) { | ||
console.log(req) | ||
}) | ||
// request().then(function nextRequest (req) { | ||
// console.log(req) | ||
// }) | ||
@@ -28,1 +28,36 @@ // make sure someone is listening | ||
request.removeConsumer(onRequest) | ||
var pie = eventuate() | ||
pie(function (p) { | ||
console.log('%s served...', p.type) | ||
}) | ||
var everythingElse = pie.filter(function (pie) { | ||
return pie.type !== 'shoofly' | ||
}).map(function (pie) { | ||
switch (pie.type) { | ||
case 'shoofly': | ||
pie.topping = 'vanilla ice cream' | ||
break | ||
case 'pumpkin': | ||
pie.topping = 'whipped cream' | ||
break | ||
case 'apple': | ||
pie.topping = 'maple walnut syrup' | ||
break | ||
default: | ||
pie.topping = 'a cherry' | ||
} | ||
return pie | ||
}).reduce(function (lastValue, pie) { | ||
return lastValue + ' ' + pie.type + ' with ' + pie.topping | ||
}, 'Pies eaten so far in pie eating contest: ') | ||
everythingElse(function (p) { | ||
console.log(p) | ||
}) | ||
pie.produce({type: 'apple' }) | ||
pie.produce({type: 'cherry' }) | ||
pie.produce({type: 'shoofly' }) | ||
pie.produce({type: 'peach' }) |
42
index.js
@@ -1,8 +0,11 @@ | ||
var copy = require('shallow-copy'), | ||
assign = require('object-assign'), | ||
errors = require('./errors') | ||
var copy = require('shallow-copy'), | ||
assign = require('object-assign'), | ||
map = require('eventuate-map'), | ||
reduce = require('eventuate-reduce'), | ||
filter = require('eventuate-filter'), | ||
UnconsumedEventError = require('./errors').UnconsumedEventError | ||
module.exports = function mkEventuate (options) { | ||
module.exports = function createEventuate (options) { | ||
options = assign({ | ||
monitorConsumers: true, | ||
monitorConsumers : true, | ||
requireConsumption: false | ||
@@ -20,2 +23,3 @@ }, options) | ||
} | ||
eventuate.removeConsumer = function (consumer) { | ||
@@ -25,5 +29,7 @@ consumers.splice(consumers.indexOf(consumer), 1) | ||
} | ||
eventuate.removeAllConsumers = function () { | ||
for (var i = consumers.length - 1; i >= 0; i--) eventuate.removeConsumer(consumers[i]) | ||
} | ||
eventuate.produce = function (data) { | ||
@@ -36,7 +42,25 @@ if (options.requireConsumption && !eventuate.hasConsumer) | ||
} | ||
eventuate.factory = mkEventuate | ||
eventuate.map = function (cb) { | ||
return map(eventuate, cb) | ||
} | ||
eventuate.reduce = function (cb, initialValue) { | ||
return reduce(eventuate, cb, initialValue) | ||
} | ||
eventuate.filter = function (cb) { | ||
return filter(eventuate, cb) | ||
} | ||
eventuate.forEach = function (cb) { | ||
eventuate(cb) | ||
return eventuate | ||
} | ||
eventuate.factory = createEventuate | ||
if (monitored) { | ||
eventuate.consumerRemoved = mkEventuate({ monitorConsumers: false }) | ||
eventuate.consumerAdded = mkEventuate({ monitorConsumers: false }) | ||
eventuate.consumerRemoved = createEventuate({ monitorConsumers: false }) | ||
eventuate.consumerAdded = createEventuate({ monitorConsumers: false }) | ||
@@ -55,3 +79,1 @@ Object.defineProperties(eventuate, { | ||
} | ||
var UnconsumedEventError = errors.UnconsumedEventError |
{ | ||
"name": "eventuate", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Handle events without emitters", | ||
@@ -27,24 +27,38 @@ "main": "index.js", | ||
}, | ||
"contributors": [], | ||
"contributors": [ | ||
"Gege Pingin <gege@pincin.com> (https://github.com/Georgette)" | ||
], | ||
"devDependencies": { | ||
"@jasonpincin/standard": "~5.0.0-6", | ||
"eventuate-once": "~1.0.1", | ||
"istanbul": "~0.3.17", | ||
"@jasonpincin/standard": "~5.0.0-8", | ||
"faucet": "0.0.1", | ||
"istanbul": "~0.4.0", | ||
"opn": "~1.0.2", | ||
"tap-dot": "~1.0.0", | ||
"tap-spec": "~4.0.2", | ||
"tape": "~4.1.0", | ||
"snazzy": "~2.0.1", | ||
"tape": "~4.2.1", | ||
"phantomjs": "~1.9.18", | ||
"zuul": "~3.2.0" | ||
"zuul": "~3.7.2" | ||
}, | ||
"dependencies": { | ||
"define-error": "~1.0.0", | ||
"object-assign": "~3.0.0", | ||
"define-error": "~1.1.0", | ||
"eventuate-filter": "~3.0.0", | ||
"eventuate-map": "~1.0.1", | ||
"eventuate-reduce": "~1.0.0", | ||
"object-assign": "~4.1.0", | ||
"shallow-copy": "0.0.1" | ||
}, | ||
"scripts": { | ||
"test": "make npm-test", | ||
"coverage": "make npm-coverage", | ||
"browser-test": "make browser-test" | ||
"test": "npm run -s faucet && npm run -s lint && npm run -s check-cover", | ||
"test-nocover": "npm run -s faucet-nocover && npm run -s lint", | ||
"travis-test": "npm run -s tap && ((cat coverage/lcov.info | coveralls) || exit 0)", | ||
"travis-browser-test": "zuul -- test/*.js", | ||
"faucet": "istanbul cover --report lcov --print none -- tape test/*.js | faucet", | ||
"faucet-nocover": "tape test/**/*.js | faucet", | ||
"tap": "istanbul cover --report lcov --print none -- tape test/*.js", | ||
"tap-nocover": "tape test/**/*.js", | ||
"phantom": "zuul --phantom -- test/*.js | faucet", | ||
"lint": "standard | snazzy", | ||
"check-cover": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100 2>&1 | grep ERROR: ; (test ${PIPESTATUS[0]} -eq 0) || (istanbul report text; exit 1)", | ||
"view-cover": "istanbul report text", | ||
"open-cover": "open coverage/lcov-report/index.html" | ||
} | ||
} |
@@ -59,2 +59,6 @@ # eventuate | ||
### event.forEach(consumer) | ||
Alias for `event(consumer)` as described above. | ||
### event.produce(data) | ||
@@ -120,2 +124,17 @@ | ||
### newEventuate = event.filter(filterFunc) | ||
Return a new eventuate which is a filtered subset of `event`. See | ||
[eventuate-filter](https://github.com/jasonpincin/eventuate-filter). | ||
### newEventuate = event.map(mapFunc) | ||
Return a new eventuate which produces transformed data of `event`. See | ||
[eventuate-map](https://github.com/Georgette/eventuate-map). | ||
### newEventuate = event.reduce(reduceFunc) | ||
Return a new eventuate which produces on-goin reduced data of `event`. See | ||
[eventuate-reduce](https://github.com/Georgette/eventuate-reduce). | ||
### var UnconsumedEventError = require('eventuate/errors').UnconsumedEventError | ||
@@ -122,0 +141,0 @@ |
@@ -15,1 +15,13 @@ var test = require('tape'), | ||
}) | ||
test('consumer added (forEach)', function (t) { | ||
t.plan(1) | ||
function consumer1 () {} | ||
var event1 = eventuate() | ||
event1.consumerAdded(function (consumer) { | ||
t.equal(consumer, consumer1, 'should be called with consumer') | ||
}) | ||
event1.forEach(consumer1) | ||
}) |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21898
8
330
180
6
+ Addedeventuate-filter@~3.0.0
+ Addedeventuate-map@~1.0.1
+ Addedeventuate-reduce@~1.0.0
+ Addeddefine-error@1.1.0(transitive)
+ Addedeventuate-filter@3.0.0(transitive)
+ Addedeventuate-map@1.0.1(transitive)
+ Addedeventuate-reduce@1.0.0(transitive)
+ Addedobject-assign@4.1.1(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removeddefine-error@1.0.0(transitive)
- Removedobject-assign@3.0.0(transitive)
Updateddefine-error@~1.1.0
Updatedobject-assign@~4.1.0