From c7310ca70be2aa4d00f3e3b2601c0d353d611bac Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 9 Jan 2018 14:17:33 +0200 Subject: [PATCH] Update createEventHub.md --- snippets/createEventHub.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md index c368d5d6e..de2b0139e 100644 --- a/snippets/createEventHub.md +++ b/snippets/createEventHub.md @@ -2,14 +2,10 @@ Creates a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with `emit`, `on`, and `off` methods. -Set a `hub` property using `Object.create(null)` to create a truly empty object that does not inherit properties from `Object.prototype` (which would be resolved if the event name matched one of the properties). - -For `emit`, resolve the array of handlers based on the `event` argument and then run -each one with `Array.forEach()` by passing in the data as an argument. - +Use `Object.create(null)` to create an empty `hub` object that does not inherit properties from `Object.prototype`. +For `emit`, resolve the array of handlers based on the `event` argument and then run each one with `Array.forEach()` by passing in the data as an argument. For `on`, create an array for the event if it does not yet exist, then use `Array.push()` to add the handler 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