contra.emitter
Advanced tools
Comparing version 1.0.1 to 1.1.0
104
CHANGELOG.md
@@ -1,105 +0,11 @@ | ||
# 1.6.9 Context Mayhem | ||
# 1.1.0 Snapshot | ||
- Fixed an issue where you weren't able to change the event context using `.apply` on event emissions | ||
- Introduced `emitterSnapshot(type)` method | ||
# 1.6.8 Cascade of Events | ||
# 1.0.1 Context Mayhem | ||
- `λ.emitter` methods return the emitter object for chaining | ||
- Fixed an issue where you weren't able to change the event context using `.apply` on event emissions | ||
# 1.6.7 Carbon Emitter | ||
# 1.0.0 IPO Beast | ||
- New options to turn off event listeners on `λ.emitter` objects | ||
# 1.6.5 Throw Up | ||
- `λ.emitter` takes a `throws` option that can turn off error-throwing | ||
# 1.6.4 Context Emission | ||
- `λ.emitter` properly sets `this` to the event emitter object | ||
# 1.6.1 Much Synchronous | ||
- `λ.emitter` takes an optional `options` object | ||
Changes | ||
- `λ.emitter` runs _synchronously_ by default | ||
# 1.5.6 Such Very Golf | ||
- Some more code reduction | ||
# 1.5.5 Stroke Cure | ||
- Reduced source code footprint | ||
Fixes | ||
- Fixed a bug where `done` was mandatory | ||
# 1.5.4 Keyhole Variation | ||
- `λ.each`, `λ.filter`, and `λ.map` support an optional `key` argument in the iterator function. | ||
# 1.5.1 Emitter of Things | ||
- `λ.emitter` can create emitters without passing it any object | ||
# 1.5.0 `<head>` | ||
- Distribution file headers | ||
# 1.4.3 Wonderboy | ||
- Source code readability | ||
# 1.4.0 Baseball Cap | ||
- Added optional _concurrency cap_ argument to remaining concurrent methods: `filter`, `map`, `each` | ||
# 1.3.0 Queue Up! | ||
- Concurrent methods now use a queue internally | ||
- `λ.concurrent` has an optional _concurrency cap_ argument | ||
- Series now use a concurrent queue internally, with `concurrency = 1` | ||
Fixes | ||
- Fixed a bug where queues weren't working concurrently | ||
- Fixed an issue where queues would emit `drain` while processing jobs | ||
# 1.2.2 Polyglot | ||
- Polyfill for `Array.prototype.indexOf` added to `contra.shim.js` | ||
# 1.2.1 This, That | ||
- Switched `window` for `root` | ||
# 1.2.0 Event Organizer | ||
- Added `.off` and `.once` support to event emitter API | ||
# 1.1.2 Clown Car | ||
- Removed unnecessary context from event listeners | ||
# 1.1.1 Down the Drain | ||
- Queue is an emitter | ||
- Queue emits `drain` events | ||
# 1.1.0 Obama Cares | ||
**BREAKING** | ||
- Rename `λ.apply` to `λ.curry` | ||
# 1.0.29 Dot Com Bubble | ||
- Ignore dotfiles in Bower distribution | ||
# 1.0.12 IPO Beast | ||
- Initial Public Release |
{ | ||
"name": "contra.emitter", | ||
"description": "A sane event emitter component", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/bevacqua/contra.emitter", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -38,3 +38,4 @@ ![contra.png][logo] | ||
- `thing` Optional. Writable JavaScript object | ||
- `emit(type, ...arguments)` Emits an event of type `type`, passing arguments | ||
- `emit(type, ...arguments)` Emits an event of type `type`, passing any `...arguments` | ||
- `emitterSnapshot(type)` Returns a function you can call, passing any `...arguments` | ||
- `on(type, fn)` Registers an event listener `fn` for `type` events | ||
@@ -46,2 +47,18 @@ - `once(type, fn)` Same as `on`, but the listener is discarded after one callback | ||
The `emitterSnapshot(type)` method lets you remove all event listeners before emitting an event that might add more event listeners which shouldn't be removed. In the example below, `thing` removes all events and then emits a `'destroy'` event, resulting in a `'create'` event handler being attached. If we just used `thing.off()` after emitting the destroy event, the `'create'` event handler would be wiped out too _(or the consumer would have to know implementation details as to avoid this issue)_. | ||
```js | ||
var thing = λ.emitter(); | ||
thing.on('foo', foo); | ||
thing.on('bar', bar); | ||
thing.on('destroy', function () { | ||
thing.on('create', reinitialize); | ||
}); | ||
var destroy = thing.emitterSnapshot('destroy'); | ||
thing.off(); | ||
destroy(); | ||
``` | ||
The emitter can be configured with the following options, too. | ||
@@ -48,0 +65,0 @@ |
@@ -49,14 +49,18 @@ (function (root, undefined) { | ||
thing.emit = function () { | ||
var ctx = this; | ||
var args = atoa(arguments); | ||
var type = args.shift(); | ||
var et = evt[type]; | ||
if (type === 'error' && opts.throws !== false && !et) { throw args.length === 1 ? args[0] : args; } | ||
if (!et) { return thing; } | ||
evt[type] = et.filter(function emitter (listen) { | ||
if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); } | ||
return !listen._once; | ||
}); | ||
return thing; | ||
return thing.emitterSnapshot(args.shift()).apply(this, args); | ||
}; | ||
thing.emitterSnapshot = function (type) { | ||
var et = (evt[type] || []).slice(0); | ||
return function () { | ||
var args = atoa(arguments); | ||
var ctx = this || thing; | ||
if (type === 'error' && opts.throws !== false && !et.length) { throw args.length === 1 ? args[0] : args; } | ||
evt[type] = et.filter(function emitter (listen) { | ||
if (opts.async) { debounce(listen, args, ctx); } else { listen.apply(ctx, args); } | ||
return !listen._once; | ||
}); | ||
return thing; | ||
}; | ||
} | ||
return thing; | ||
@@ -63,0 +67,0 @@ } |
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
300
119
16269