@vandeurenglenn/little-pubsub 1.2.3 → 1.3.2
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/README.md +2 -2
- package/index.js +8 -15
- package/package.json +2 -4
- package/src/index.js +5 -10
- package/test.js +4 -4
package/README.md
CHANGED
|
@@ -66,11 +66,11 @@ pubsub.unsubscribe('event-name', data => {
|
|
|
66
66
|
pubsub.publish('event-name', 'data')
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
#### isLittlePubSub
|
|
69
|
+
<!-- #### isLittlePubSub
|
|
70
70
|
`instance`: instance to check<br>
|
|
71
71
|
```js
|
|
72
72
|
const LittlePubSub = require('little-pubsub')
|
|
73
73
|
const pubsub = new LittlePubSub()
|
|
74
74
|
|
|
75
75
|
LittlePubSub.isLittlePubSub(pubsub)
|
|
76
|
-
```
|
|
76
|
+
``` -->
|
package/index.js
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
/* @vandeurenglenn/little-pubsub version 1.
|
|
1
|
+
/* @vandeurenglenn/little-pubsub version 1.3.0 */
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
const ENVIRONMENT = {version: '1.
|
|
4
|
+
const ENVIRONMENT = {version: '1.3.0', production: true};
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var classIs = _interopDefault(require('class-is'));
|
|
9
|
-
|
|
10
|
-
var index = classIs(class LittlePubSub {
|
|
6
|
+
class LittlePubSub {
|
|
11
7
|
|
|
12
8
|
/**
|
|
13
9
|
* Creates handlers
|
|
@@ -42,9 +38,9 @@ var index = classIs(class LittlePubSub {
|
|
|
42
38
|
if (this.subscribers[event]) {
|
|
43
39
|
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
44
40
|
this.subscribers[event].handlers.splice(index);
|
|
45
|
-
if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
|
|
41
|
+
if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
|
|
46
42
|
}
|
|
47
|
-
|
|
43
|
+
|
|
48
44
|
}
|
|
49
45
|
|
|
50
46
|
/**
|
|
@@ -54,16 +50,13 @@ var index = classIs(class LittlePubSub {
|
|
|
54
50
|
publish(event, change) {
|
|
55
51
|
if (this.subscribers[event]) {
|
|
56
52
|
if (this.verbose || this.subscribers[event].value !== change) {
|
|
53
|
+
this.subscribers[event].value = change;
|
|
57
54
|
this.subscribers[event].handlers.forEach(handler => {
|
|
58
55
|
handler(change, this.subscribers[event].value);
|
|
59
56
|
});
|
|
60
|
-
this.subscribers[event].value = change;
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
}
|
|
64
|
-
}
|
|
65
|
-
className: 'LittlePubSub',
|
|
66
|
-
symbolName: 'little-pubsub/index'
|
|
67
|
-
})
|
|
60
|
+
}
|
|
68
61
|
|
|
69
|
-
module.exports =
|
|
62
|
+
module.exports = LittlePubSub;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vandeurenglenn/little-pubsub",
|
|
3
|
-
"version": "1.2
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Publish & Subscribe",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -22,7 +22,5 @@
|
|
|
22
22
|
"rollup": "^0.58.2",
|
|
23
23
|
"tape": "^4.13.0"
|
|
24
24
|
},
|
|
25
|
-
"dependencies": {
|
|
26
|
-
"class-is": "^1.1.0"
|
|
27
|
-
}
|
|
25
|
+
"dependencies": {}
|
|
28
26
|
}
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export default classIs(class LittlePubSub {
|
|
1
|
+
export default class LittlePubSub {
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Creates handlers
|
|
@@ -35,9 +33,9 @@ export default classIs(class LittlePubSub {
|
|
|
35
33
|
if (this.subscribers[event]) {
|
|
36
34
|
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
37
35
|
this.subscribers[event].handlers.splice(index);
|
|
38
|
-
if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
|
|
36
|
+
if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
|
|
41
39
|
}
|
|
42
40
|
|
|
43
41
|
/**
|
|
@@ -47,14 +45,11 @@ export default classIs(class LittlePubSub {
|
|
|
47
45
|
publish(event, change) {
|
|
48
46
|
if (this.subscribers[event]) {
|
|
49
47
|
if (this.verbose || this.subscribers[event].value !== change) {
|
|
48
|
+
this.subscribers[event].value = change;
|
|
50
49
|
this.subscribers[event].handlers.forEach(handler => {
|
|
51
50
|
handler(change, this.subscribers[event].value)
|
|
52
51
|
})
|
|
53
|
-
this.subscribers[event].value = change;
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
}
|
|
58
|
-
className: 'LittlePubSub',
|
|
59
|
-
symbolName: 'little-pubsub/index'
|
|
60
|
-
})
|
|
55
|
+
}
|
package/test.js
CHANGED
|
@@ -18,8 +18,8 @@ test('pubsub is defined', tape => {
|
|
|
18
18
|
tape.ok(Boolean(Object.keys(pubsub.subscribers).length === 0))
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
test('classIs', tape => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
})
|
|
21
|
+
// test('classIs', tape => {
|
|
22
|
+
// tape.plan(1)
|
|
23
|
+
// tape.ok(PubSub.isLittlePubSub(pubsub))
|
|
24
|
+
// })
|
|
25
25
|
});
|