Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d814d9
commit 3b7db43
Showing
13 changed files
with
348 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const Emittery = require('..'); | ||
import Emittery from '../index.js'; | ||
|
||
const myEmitter = new Emittery(); | ||
|
||
// Register listener | ||
myEmitter.on('event', () => console.log('an event occurred!')); | ||
myEmitter.onAny(eventName => console.log('"%s" event occurred!', eventName)); | ||
myEmitter.on('event', () => { | ||
console.log('an event occurred!'); | ||
}); | ||
|
||
myEmitter.onAny(eventName => { | ||
console.log('`%s` event occurred!', eventName); | ||
}); | ||
|
||
// Emit event in next tick | ||
myEmitter.emit('event'); | ||
|
||
// Prints: | ||
// an event occurred! | ||
// "event" event occurred! | ||
// `event` event occurred! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
#!/usr/bin/env node | ||
|
||
'use strict'; | ||
|
||
const Emittery = require('..'); | ||
import Emittery from '../index.js'; | ||
|
||
const myEmitter = new Emittery(); | ||
|
||
// Register listener for only the one event | ||
myEmitter.once('event') | ||
.then(count => console.log('an event occurred (#%d).', count)); | ||
(async () => { | ||
console.log('An event occurred (#%d).', await myEmitter.once('event')); | ||
})(); | ||
|
||
// Emit events in next tick | ||
myEmitter.emit('event', 1); | ||
myEmitter.emit('event', 2); | ||
|
||
// Prints: | ||
// an event occurred (#1). | ||
// An event occurred (#1). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.