Comparing version 3.2.0 to 4.0.0
var copy = require('shallow-copy'), | ||
assign = require('object-assign') | ||
assign = require('object-assign'), | ||
errors = require('./errors') | ||
@@ -28,3 +29,3 @@ module.exports = function mkEventuate (options) { | ||
if (options.requireConsumption && !eventuate.hasConsumer) | ||
throw ((data instanceof Error) ? data : assign(new Error('Unconsumed eventuate'), { data: data })) | ||
throw ((data instanceof Error) ? data : new UnconsumedEventError('Unconsumed event', { data: data })) | ||
consumers.forEach(function eventuateConsume (consume) { | ||
@@ -52,1 +53,3 @@ consume(data) | ||
} | ||
var UnconsumedEventError = errors.UnconsumedEventError |
{ | ||
"name": "eventuate", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "Handle events without emitters", | ||
@@ -40,2 +40,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"define-error": "~1.0.0", | ||
"object-assign": "~3.0.0", | ||
@@ -42,0 +43,0 @@ "shallow-copy": "0.0.1" |
@@ -61,3 +61,3 @@ # eventuate | ||
Produce an event. All `event` consumer functions will be called with `data`. If the `requireConsumption` option was provided, and nothing consumes the data, an error will be thrown. | ||
Produce an event. All `event` consumer functions will be called with `data`. If the `requireConsumption` option was provided, and nothing consumes the data, an error will be thrown. In this case, if the data being produced is an instanceof `Error`, it will be thrown directly, otherwise an `UnconsumedEventError` (see below) will be thrown, and the data that was produced will be attached to the error as a `data` property. | ||
@@ -120,3 +120,7 @@ ### event.removeConsumer(consumer) | ||
### var UnconsumedEventError = require('eventuate/errors').UnconsumedEventError | ||
Constructor of error potentially thrown on eventuates with `requireConsumption` set. | ||
## unmonitored eventuate | ||
@@ -123,0 +127,0 @@ |
var test = require('tape'), | ||
eventuate = require('..') | ||
eventuate = require('..'), | ||
errors = require('../errors') | ||
@@ -20,1 +21,15 @@ test('eventuate requiring consumption', function (t) { | ||
}) | ||
test('should throw UnconsumedEventError when unconsumed data is produced (with requireConsumption set)', function (t) { | ||
t.plan(3) | ||
var error = eventuate({ requireConsumption: true }) | ||
try { | ||
error.produce('explode') | ||
} | ||
catch (err) { | ||
t.ok(err instanceof errors.UnconsumedEventError, 'err is instanceof UnconsumedEventError') | ||
t.equal(err.message, 'Unconsumed event', 'message is Unconsumed event') | ||
t.equal(err.data, 'explode', 'data is produced data') | ||
} | ||
}) |
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
19619
18
244
161
3
+ Addeddefine-error@~1.0.0
+ Addedcapture-stack-trace@1.0.2(transitive)
+ Addeddefine-error@1.0.0(transitive)