Comparing version 2.0.0 to 2.1.0
@@ -10,3 +10,3 @@ var eventuate = require('..'), | ||
function onRequest (req) { | ||
// do something | ||
console.log(req) | ||
} | ||
@@ -17,3 +17,3 @@ request(onRequest) | ||
request().then(function nextRequest (req) { | ||
// do something | ||
console.log(req) | ||
}) | ||
@@ -28,2 +28,2 @@ | ||
// remove our consumer | ||
request.remove(onRequest) | ||
request.removeConsumer(onRequest) |
@@ -18,4 +18,4 @@ var Promise = require('promise-polyfill') | ||
else | ||
nextEvent = nextEvent || (nextEvent = new Promise(function (resolve,reject) { | ||
_nextEvent = {resolve:resolve, reject:reject} | ||
nextEvent = nextEvent || (nextEvent = new Promise(function (resolve, reject) { | ||
_nextEvent = {resolve: resolve, reject: reject} | ||
})) | ||
@@ -34,2 +34,4 @@ | ||
eventuate.produce = function (data) { | ||
if (options.requireConsumption && !eventuate.hasConsumer) | ||
throw ((data instanceof Error) ? data : new Error(data)) | ||
consumers.forEach(function eventuateConsume(consume) { | ||
@@ -50,3 +52,3 @@ consume(data) | ||
Object.defineProperty(eventuate, "hasConsumer", { | ||
Object.defineProperty(eventuate, 'hasConsumer', { | ||
get: function eventuateHasConsumer () { | ||
@@ -53,0 +55,0 @@ return !!(nextEvent || consumers.length) |
{ | ||
"name": "eventuate", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"description": "Handle events without emitters", | ||
@@ -34,12 +34,12 @@ "main": "index.js", | ||
"devDependencies": { | ||
"istanbul": "~0.2.8", | ||
"jshint": "^2.5.6", | ||
"opn": "^1.0.1", | ||
"tap-dot": "^0.2.2", | ||
"tap-spec": "~0.1.9", | ||
"tape": "~3.4.0" | ||
"eslint": "~0.24.1", | ||
"istanbul": "~0.3.17", | ||
"opn": "~3.0.2", | ||
"tap-dot": "~1.0.0", | ||
"tap-spec": "~4.0.2", | ||
"tape": "~4.0.0" | ||
}, | ||
"dependencies": { | ||
"promise-polyfill": "^2.0.0" | ||
"promise-polyfill": "~2.1.0" | ||
} | ||
} |
@@ -55,2 +55,3 @@ # eventuate | ||
* requireConsumption - throw an error if a produced event is not consumed, useful for error producers | ||
* monitorConsumers - [default: `true`] `true` or `false`, see "unmonitored eventuate" below | ||
@@ -60,5 +61,3 @@ | ||
Consume events with the `consumer` function, which should have the signature | ||
`function (data) {}`. When an event is produced, it will be passed to the consumer | ||
function as the first and only argument. | ||
Consume events with the `consumer` function, which should have the signature `function (data) {}`. When an event is produced, it will be passed to the consumer function as the first and only argument. | ||
@@ -69,28 +68,21 @@ When invoked this way, the return value of `event()` is undefined. | ||
When `event()` is invoked without a consumer, it returns a `Promise` object | ||
representing the next produced event. | ||
When `event()` is invoked without a consumer, it returns a `Promise` object representing the next produced event. | ||
### event.produce(data) | ||
Produce an event. All `event` consumer functions will be called with `data`, and | ||
the `Promise` representing the next event will be resolved with `data`. | ||
Produce an event. All `event` consumer functions will be called with `data`, and the `Promise` representing the next event will be resolved with `data`. If the `requireConsumption` option was provided, and nothing consumes the data, an error will be thrown. | ||
### event.removeConsumer(consumer) | ||
Remove the formerly added `consumer`, so that it will not be called with future produced | ||
events. | ||
Remove the formerly added `consumer`, so that it will not be called with future produced events. | ||
### event.hasConsumer | ||
Property containing value `true` or `false`, indicating whether or not the event has a | ||
consumer. This will also return true if there is an outstanding promise. | ||
Property containing value `true` or `false`, indicating whether or not the event has a consumer. This will also return true if there is an outstanding promise. | ||
### event.consumerAdded([consumer]) | ||
Unmonitored eventuate representing additions of consumers. Any consumers of `consumerAdded` will be | ||
invoked with the consumer added to the `eventuate`. As this is an eventuate itself, it will return a | ||
promise that will resolve to the next consumer added if no `consumerAdded` consumer is provided. | ||
Unmonitored eventuate representing additions of consumers. Any consumers of `consumerAdded` will be invoked with the consumer added to the `eventuate`. As this is an eventuate itself, it will return a promise that will resolve to the next consumer added if no `consumerAdded` consumer is provided. | ||
If the consumer added to the `eventuate` was a promise, the consumer passed to the `consumerAdded` | ||
consumer will be undefined. | ||
If the consumer added to the `eventuate` was a promise, the consumer passed to the `consumerAdded` consumer will be undefined. | ||
@@ -113,8 +105,5 @@ Example: | ||
Unmonitored eventuate representing removal of consumers. Any consumers of `consumerRemoved` will be | ||
invoked with the consumer removed from the `eventuate`. As this is an eventuate itself, it will return a | ||
promise that will resolve to the next consumer removed if no `consumerRemoved` consumer is provided. | ||
Unmonitored eventuate representing removal of consumers. Any consumers of `consumerRemoved` will be invoked with the consumer removed from the `eventuate`. As this is an eventuate itself, it will return a promise that will resolve to the next consumer removed if no `consumerRemoved` consumer is provided. | ||
If the consumer removed from the `eventuate` was a promise, the consumer passed to the `consumerRemoved` | ||
consumer will be undefined. | ||
If the consumer removed from the `eventuate` was a promise, the consumer passed to the `consumerRemoved` consumer will be undefined. | ||
@@ -138,6 +127,3 @@ Example: | ||
If the eventuate is created with the option `monitorConsumers` set to false, the eventuate | ||
will not have the following properties: `hasConsumer`, `consumerRemoved`, `consumerAdded`. | ||
No events will be triggered when consumers are manipulated. This is used internally within | ||
eventuate for sub-events such as `consumerRemoved` and `consumerAdded`. | ||
If the eventuate is created with the option `monitorConsumers` set to false, the eventuate will not have the following properties: `hasConsumer`, `consumerRemoved`, `consumerAdded`. No events will be triggered when consumers are manipulated. This is used internally within eventuate for sub-events such as `consumerRemoved` and `consumerAdded`. | ||
@@ -144,0 +130,0 @@ |
@@ -17,6 +17,2 @@ var test = require('tape'), | ||
} | ||
function consumer2 (value) { | ||
t.equal(value, 'test1', 'consumer2 should be passed value') | ||
event.removeConsumer(consumer2) | ||
} | ||
@@ -23,0 +19,0 @@ t.equal(typeof event(consumer1), 'undefined', '(consumer) should return undefined') |
@@ -17,6 +17,2 @@ var test = require('tape'), | ||
} | ||
function consumer2 (value) { | ||
t.equal(value, 'test1', 'consumer2 should be passed value') | ||
event.removeConsumer(consumer2) | ||
} | ||
@@ -23,0 +19,0 @@ t.equal(typeof event(consumer1), 'undefined', '(consumer) should return undefined') |
Sorry, the diff of this file is not supported yet
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
200
16420
13
147
Updatedpromise-polyfill@~2.1.0