@vandeurenglenn/little-pubsub 1.4.5 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +3 -1
- package/package.json +1 -1
- package/src/index.ts +3 -1
- package/test.js +11 -0
package/index.js
CHANGED
|
@@ -31,7 +31,9 @@ export default class LittlePubSub {
|
|
|
31
31
|
publish(event, value) {
|
|
32
32
|
// always set value even when having no subscribers
|
|
33
33
|
if (!this.hasSubscribers(event))
|
|
34
|
-
this.subscribers[event] = {
|
|
34
|
+
this.subscribers[event] = {
|
|
35
|
+
handlers: []
|
|
36
|
+
};
|
|
35
37
|
const oldValue = this.subscribers[event]?.value;
|
|
36
38
|
this.subscribers[event].value = value;
|
|
37
39
|
if (this.verbose || oldValue !== value)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -35,7 +35,9 @@ export default class LittlePubSub {
|
|
|
35
35
|
|
|
36
36
|
publish(event: string, value: string | number | boolean | object | Array<any>): void {
|
|
37
37
|
// always set value even when having no subscribers
|
|
38
|
-
if (!this.hasSubscribers(event)) this.subscribers[event] = {
|
|
38
|
+
if (!this.hasSubscribers(event)) this.subscribers[event] = {
|
|
39
|
+
handlers: []
|
|
40
|
+
}
|
|
39
41
|
const oldValue = this.subscribers[event]?.value
|
|
40
42
|
this.subscribers[event].value = value;
|
|
41
43
|
|
package/test.js
CHANGED
|
@@ -24,4 +24,15 @@ test('pubsub is defined', tape => {
|
|
|
24
24
|
let value = await pubsub.once('on')
|
|
25
25
|
tape.ok((value === true))
|
|
26
26
|
})
|
|
27
|
+
|
|
28
|
+
test('pubsub without subscribers', async (tape) => {
|
|
29
|
+
tape.plan(1)
|
|
30
|
+
try {
|
|
31
|
+
pubsub.publish('on', true)
|
|
32
|
+
tape.ok(true)
|
|
33
|
+
|
|
34
|
+
} catch (error) {
|
|
35
|
+
tape.ok(false)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
27
38
|
});
|