This was quite helpful when I was looking for a sub-pub model in vanilla ES6. However, it led to a bit of confusion when I expanded on it due to it using an array of arrays internally with a named index. It works, but "topic 1" & "topic 2" subscriptions are not elements of the subscription array, they are stored as properties on the array instance. If you access subscriptions.length you get 0, not 2. Subscribers should instead be a Map() with get() & set() with the subscription name. While Array() does work and handles access through the [] accessor, this is pretty misleading as the callbacks aren't elements of the array, but rather separate named properties on the instance.
This was quite helpful when I was looking for a sub-pub model in vanilla ES6. However, it led to a bit of confusion when I expanded on it due to it using an array of arrays internally with a named index. It works, but "topic 1" & "topic 2" subscriptions are not elements of the subscription array, they are stored as properties on the array instance. If you access subscriptions.length you get 0, not 2. Subscribers should instead be a Map() with get() & set() with the subscription name. While Array() does work and handles access through the [] accessor, this is pretty misleading as the callbacks aren't elements of the array, but rather separate named properties on the instance.