From cc754ff8c833d839127305c3fcafafda987b1970 Mon Sep 17 00:00:00 2001 From: atomiks Date: Tue, 9 Jan 2018 05:46:17 +1100 Subject: [PATCH] Update createEventHub.md --- snippets/createEventHub.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snippets/createEventHub.md b/snippets/createEventHub.md index decc156b7..3b0e10c33 100644 --- a/snippets/createEventHub.md +++ b/snippets/createEventHub.md @@ -2,7 +2,7 @@ Creates a pub/sub ([publish–subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern)) event hub with `emit`, `on`, and `off` methods. -Instantiate a new `Map` object to allow any event type (including objects) to be the key, and also so object prototype property names are not resolved. +Instantiate a new `Map` object to allow any event type (including objects) to be the key, and also so `Object.prototype` property names are not resolved. 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. @@ -37,6 +37,6 @@ const hub = createEventHub(); hub.on('message', fn); // subscribe a handler to listen for 'message' events hub.on(obj, fn); // subscribe a handler to listen for the object hub.emit('message', 'hello!'); // console logs 'hello!' -hub.emit(obj, 'hello!'); // console logs 'hello' +hub.emit(obj, 'hello!'); // console logs 'hello!' hub.off('message', fn); // unsubscribe our handler from 'message', the obj event will still work ```