Skip to content

Commit

Permalink
Updated README.md example;
Browse files Browse the repository at this point in the history
Refactored stopListening to stopListeningTo;
  • Loading branch information
DigitalBrainJS committed May 4, 2020
1 parent f6f7dfa commit 10497db
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
18 changes: 9 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ For changes before version 2.2.0, please see the commit history

### Added

- Symbol events support for simple and wildcard emitters #201
- `emitter.hasListeners` method #251
- `emitter.listenTo` & `emitter.stopListening` methods for listening to an external event emitter of any kind and propagate its events through itself using optional reducers/filters
- async listeners for invoking handlers using setImmediate|setTimeout|nextTick (see `async`, `promisify` and `nextTicks` options for subscription methods)
- Ability for subscription methods to return a listener object to simplify subscription management (see the `objectify` option)
- micro optimizations for performance reasons
- Symbol events support for simple and wildcard emitters #201 @DigitalBrainJS
- `emitter.hasListeners` method #251 @DigitalBrainJS
- `emitter.listenTo` & `emitter.stopListeningTo` methods for listening to an external event emitter of any kind and propagate its events through itself using optional reducers/filters @DigitalBrainJS
- async listeners for invoking handlers using setImmediate|setTimeout|nextTick (see `async`, `promisify` and `nextTicks` options for subscription methods) @DigitalBrainJS
- Ability for subscription methods to return a listener object to simplify subscription management (see the `objectify` option) @DigitalBrainJS
- micro optimizations for performance reasons @DigitalBrainJS

### Fixed

- Event name/reference normalization for the `this.event` property #162
- Bug with data arguments for `Any` listeners #254
- `emitter.eventNames` now supports wildcard emitters #214
- Event name/reference normalization for the `this.event` property #162 @DigitalBrainJS
- Bug with data arguments for `Any` listeners #254 @DigitalBrainJS
- `emitter.eventNames` now supports wildcard emitters #214 @DigitalBrainJS

## [6.3.0] - 2020-03-28

Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ If you like this project please show your support with a [GitHub :star:](https:/
- Subscription methods ([on](#emitteronevent-listener-options-objectboolean), [once](#emitterprependoncelistenerevent--eventns-listener-options), [many](#emittermanyevent--eventns-timestolisten-listener-options), ...) can return a
[listener](#listener) object that makes it easy to remove the subscription when needed - just call the listener.off() method.
- Feature-rich [waitFor](#emitterwaitforevent--eventns-options) method to wait for events using promises
- [listenTo](#listentotargetemitter-events-event--eventns-options) & [stopListening](#stoplisteningtarget-object-event-event--eventns-boolean) methods
- [listenTo](#listentotargetemitter-events-objectevent--eventns-function-options) & [stopListeningTo](#stoplisteningtotarget-object-event-event--eventns-boolean) methods
for listening to an external event emitter of any kind and propagate its events through itself using optional reducers/filters
- Extended version of the [events.once](#eventemitter2onceemitter-event--eventns-options) method from the [node events API](https://nodejs.org/api/events.html#events_events_once_emitter_name)
- Browser & Workers environment compatibility
Expand Down Expand Up @@ -77,15 +77,15 @@ var emitter = new EventEmitter2({
- Getting the actual event that fired.

```javascript
server.on('foo.*', function() {
console.log(this.event);
emitter.on('foo.*', function(value1, value2) {
console.log(this.event, value1, value2);
});

server.emit('foo.bar'); // foo.bar
server.emit(['foo', 'bar']); // foo.bar
emitter.emit('foo.bar', 1, 2); // 'foo.bar' 1 2
emitter.emit(['foo', 'bar'], 3, 4); // 'foo.bar' 3 4

server.emit(Symbol()); // Symbol()
server.emit(['foo', Symbol()]); // ['foo', Symbol())
emitter.emit(Symbol(), 5, 6); // Symbol() 5 6
emitter.emit(['foo', Symbol(), 7, 8]); // ['foo', Symbol()] 7 8
```
**Note**: Generally this.event is normalized to a string ('event', 'event.test'),
except the cases when event is a symbol or namespace contains a symbol.
Expand Down Expand Up @@ -178,7 +178,7 @@ Or you can use unpkg.com CDN to import this [module](https://unpkg.com/eventemit

- [listenTo(target: GeneralEventEmitter, events: Object<event | eventNS, Function>, options?: ListenToOptions): this](#listentotargetemitter-events-objectevent--eventns-function-options)

- [stopListening(target?: GeneralEventEmitter, event?: event | eventNS): Boolean](#stoplisteningtarget-object-event-event--eventns-boolean)
- [stopListeningTo(target?: GeneralEventEmitter, event?: event | eventNS): Boolean](#stoplisteningtarget-object-event-event--eventns-boolean)

### static:

Expand Down Expand Up @@ -666,11 +666,11 @@ emitter.on('localConnection', function(socket){
});
setTimeout(function(){
emitter.stopListening(server);
emitter.stopListeningTo(server);
}, 30000);
````
### stopListening(target?: Object, event: event | eventNS): Boolean
### stopListeningTo(target?: Object, event: event | eventNS): Boolean
Stops listening the targets. Returns true if some listener was removed.
Expand Down
2 changes: 1 addition & 1 deletion eventemitter2.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export declare class EventEmitter2 {
listenTo(target: GeneralEventEmitter, events: event | eventNS, options?: ListenToOptions): this;
listenTo(target: GeneralEventEmitter, events: event[], options?: ListenToOptions): this;
listenTo(target: GeneralEventEmitter, events: Object, options?: ListenToOptions): this;
stopListening(target?: GeneralEventEmitter, event?: event | eventNS): Boolean;
stopListeningTo(target?: GeneralEventEmitter, event?: event | eventNS): Boolean;
hasListeners(event?: String): Boolean
static once(emitter: EventEmitter2, event: event | eventNS, options?: OnceOptions): CancelablePromise<any[]>;
static defaultMaxListeners: number;
Expand Down
2 changes: 1 addition & 1 deletion lib/eventemitter2.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@
return this;
};

EventEmitter.prototype.stopListening = function (target, event) {
EventEmitter.prototype.stopListeningTo = function (target, event) {
var observers = this._observers;
var i = observers.length;
var observer;
Expand Down
4 changes: 2 additions & 2 deletions test/simple/listenTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module.exports = {
assert.equal(isEmitted, true);
},

'4. should support stop listening method': function () {
'4. should support stopListeningTo method': function () {
var counter= 0;
var ee = new EventEmitter();
var ee2 = new EventEmitter2();
Expand All @@ -89,7 +89,7 @@ module.exports = {
ee.emit('test');
ee.emit('test');

ee2.stopListening(ee);
ee2.stopListeningTo(ee);

ee.emit('test');

Expand Down

0 comments on commit 10497db

Please sign in to comment.