Travis build: 1099
This commit is contained in:
@ -8,7 +8,7 @@ For `on`, create an array for the event if it does not yet exist, then use `Arra
|
||||
to the array.
|
||||
For `off`, use `Array.findIndex()` to find the index of the handler in the event array and remove it using `Array.splice()`.
|
||||
|
||||
```js
|
||||
```js
|
||||
const createEventHub = () => ({
|
||||
hub: Object.create(null),
|
||||
emit(event, data) {
|
||||
@ -25,7 +25,7 @@ const createEventHub = () => ({
|
||||
});
|
||||
```
|
||||
|
||||
```js
|
||||
```js
|
||||
const handler = data => console.log(data);
|
||||
const hub = createEventHub();
|
||||
let increment = 0;
|
||||
@ -41,5 +41,5 @@ hub.emit('message', { hello: 'world' }); // logs the object and 'Message event f
|
||||
hub.emit('increment'); // `increment` variable is now 1
|
||||
|
||||
// Unsubscribe: stop a specific handler from listening to the 'message' event
|
||||
hub.off('message', handler);
|
||||
hub.off('message', handler);
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user