@peter.naydenov/notice 1.0.0 → 1.0.1
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 +9 -1
- package/package.json +4 -4
- package/src/main.js +8 -6
- package/test/01-notice.js +41 -1
package/README.md
CHANGED
|
@@ -165,7 +165,7 @@ const
|
|
|
165
165
|
eBus.stop ( 'go' )
|
|
166
166
|
eBus.emit ( 'go', 2 )
|
|
167
167
|
// ---> result == 0
|
|
168
|
-
eBus.start ( 'go' )
|
|
168
|
+
eBus.start ( 'go', 2 )
|
|
169
169
|
eBus.emit ( 'go' )
|
|
170
170
|
// ---> result == 8
|
|
171
171
|
```
|
|
@@ -173,10 +173,18 @@ const
|
|
|
173
173
|
|
|
174
174
|
## Release History
|
|
175
175
|
|
|
176
|
+
### 1.0.1 ( 2022-08-15)
|
|
177
|
+
- [x] Fix: Event data is coming in Array;
|
|
178
|
+
- [x] Fix: Multiple instances of notice;
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
|
|
176
182
|
### 1.0.0 (2021-05-12)
|
|
177
183
|
- [x] Initial code;
|
|
178
184
|
- [x] Test package;
|
|
179
185
|
- [x] Documentation;
|
|
186
|
+
- [ ] Bug: Event data is coming in Array;
|
|
187
|
+
- [ ] Bug: Multiple instances of notice;
|
|
180
188
|
|
|
181
189
|
|
|
182
190
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/notice",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Event emmiter - NOTICE",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
],
|
|
18
18
|
"license": "ISC",
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"chai"
|
|
21
|
-
"mocha": "
|
|
22
|
-
"nyc"
|
|
20
|
+
"chai": "4.3.6",
|
|
21
|
+
"mocha": "9.2.1",
|
|
22
|
+
"nyc": "15.1.0"
|
|
23
23
|
},
|
|
24
24
|
"nyc": {
|
|
25
25
|
"include": [
|
package/src/main.js
CHANGED
|
@@ -5,7 +5,7 @@ function notice () {
|
|
|
5
5
|
, scrollOnce = {} // Single events with their subscribers
|
|
6
6
|
, ignore = [] // Ignore event names ( general and single )
|
|
7
7
|
;
|
|
8
|
-
|
|
8
|
+
function Notice () {
|
|
9
9
|
function on ( e, fn ) {
|
|
10
10
|
if ( !scroll[e] ) scroll[e] = []
|
|
11
11
|
scroll[e].push ( fn )
|
|
@@ -31,17 +31,17 @@ function notice () {
|
|
|
31
31
|
let evNames = Object.keys ( scroll )
|
|
32
32
|
evNames.forEach ( name => {
|
|
33
33
|
if ( ignore.includes(name) ) return
|
|
34
|
-
scroll[name].forEach ( fn => fn(args))
|
|
34
|
+
scroll[name].forEach ( fn => fn(...args))
|
|
35
35
|
})
|
|
36
36
|
}
|
|
37
37
|
if ( scrollOnce[e] ) {
|
|
38
38
|
if ( ignore.includes(e) ) return
|
|
39
|
-
scrollOnce[e].forEach ( fn => fn(args) )
|
|
39
|
+
scrollOnce[e].forEach ( fn => fn(...args) )
|
|
40
40
|
delete scrollOnce[e]
|
|
41
41
|
}
|
|
42
42
|
if ( scroll[e] ) {
|
|
43
43
|
if ( ignore.includes(e) ) return
|
|
44
|
-
scroll[e].forEach ( fn => fn(args) )
|
|
44
|
+
scroll[e].forEach ( fn => fn(...args) )
|
|
45
45
|
}
|
|
46
46
|
} // emit func.
|
|
47
47
|
function start ( e ) {
|
|
@@ -71,10 +71,12 @@ function notice () {
|
|
|
71
71
|
, stop // Ignore event for a while
|
|
72
72
|
, start // Remove event from ignore list
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
} // notice fn.
|
|
75
|
+
return new Notice ()
|
|
76
|
+
}
|
|
75
77
|
|
|
76
78
|
|
|
77
79
|
|
|
78
|
-
module.exports = notice
|
|
80
|
+
module.exports = notice
|
|
79
81
|
|
|
80
82
|
|
package/test/01-notice.js
CHANGED
|
@@ -10,7 +10,6 @@ describe ( 'Testing Notice', () => {
|
|
|
10
10
|
it ( 'Standard event', () => {
|
|
11
11
|
const eBus = notice ();
|
|
12
12
|
let result = 0;
|
|
13
|
-
|
|
14
13
|
eBus.on ( 'note', () => result += 1 )
|
|
15
14
|
eBus.emit ( 'note' )
|
|
16
15
|
eBus.emit ( 'note' )
|
|
@@ -218,6 +217,47 @@ it ( 'Unsubscribe a function from non existing event', () => {
|
|
|
218
217
|
}) // it unsibsribe a function
|
|
219
218
|
|
|
220
219
|
|
|
220
|
+
|
|
221
|
+
it ( 'Event with primitive data', () => {
|
|
222
|
+
const eBus = notice ();
|
|
223
|
+
eBus.on ( 'note' , a => expect (a).to.be.equal ( 12 ) )
|
|
224
|
+
eBus.emit ( 'note', 12 )
|
|
225
|
+
}) // it Event with primitive data
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
it ( 'Event with object', () => {
|
|
230
|
+
const eBus = notice ();
|
|
231
|
+
eBus.on ( 'note' , a => expect ( a['val'] ).to.be.equal ( 12 ) )
|
|
232
|
+
eBus.emit ( 'note', {val:12} )
|
|
233
|
+
}) // it Event with primitive data
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
it ( 'Event with two values', () => {
|
|
238
|
+
const eBus = notice ();
|
|
239
|
+
eBus.on ( 'note' , (str,a) => {
|
|
240
|
+
expect ( str ).to.be.equal ( 'test' )
|
|
241
|
+
expect (a.val).to.be.equal ( 12 )
|
|
242
|
+
})
|
|
243
|
+
eBus.emit ( 'note', 'test', {val:12} )
|
|
244
|
+
}) // it Event with primitive data
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
it ( 'Multiple Notice instances', () => {
|
|
249
|
+
const
|
|
250
|
+
eBus1 = notice ()
|
|
251
|
+
, eBus2 = notice ()
|
|
252
|
+
;
|
|
253
|
+
|
|
254
|
+
eBus1.on ( 'test', x => expect ( x ).to.be.equal ( 12 ) )
|
|
255
|
+
eBus2.on ( 'test', x => expect ( x ).to.be.equal ( 73 ) )
|
|
256
|
+
eBus1.emit ( 'test', 12 )
|
|
257
|
+
eBus2.emit ( 'test', 73 )
|
|
258
|
+
}) // it Multiple Notice instances
|
|
259
|
+
|
|
260
|
+
|
|
221
261
|
}) // define
|
|
222
262
|
|
|
223
263
|
|