@peter.naydenov/notice 1.1.0 → 2.1.0
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/Changelog.md +34 -0
- package/LICENSE +21 -0
- package/README.md +36 -30
- package/package.json +12 -7
- package/src/main.js +7 -1
- package/test/01-notice.js +23 -4
package/Changelog.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Release History
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### 2.1.0 ( 2023-07-17)
|
|
5
|
+
- [x] Method 'reset' was added. It removes all events and functions from the event emitter;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### 2.0.0 ( 2023-06-15)
|
|
10
|
+
- [x] Library was converted to ES6 module;
|
|
11
|
+
- [x] License was changed from ISC to MIT;
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### 1.1.0 ( 2022-10-21)
|
|
16
|
+
- [x] Method 'debug' was added;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### 1.0.1 ( 2022-08-15)
|
|
22
|
+
- [x] Fix: Event data is coming in Array;
|
|
23
|
+
- [x] Fix: Multiple instances of notice;
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
### 1.0.0 (2021-05-12)
|
|
28
|
+
- [x] Initial code;
|
|
29
|
+
- [x] Test package;
|
|
30
|
+
- [x] Documentation;
|
|
31
|
+
- [ ] Bug: Event data is coming in Array;
|
|
32
|
+
- [ ] Bug: Multiple instances of notice;
|
|
33
|
+
|
|
34
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Peter Naydenov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -35,6 +35,7 @@ eBus.emit ( 'note' )
|
|
|
35
35
|
on : 'Register a event'
|
|
36
36
|
, once : 'Register a single event'
|
|
37
37
|
, off : 'Unregister regular and single events'
|
|
38
|
+
, reset : 'Remove all events and functions from the event emitter' // After version 2.1.0
|
|
38
39
|
, emit : 'Trigger a event'
|
|
39
40
|
, stop : 'Ignore event for a while'
|
|
40
41
|
, start : 'Remove event from ignore list'
|
|
@@ -103,7 +104,25 @@ const
|
|
|
103
104
|
// ---> result == 5. Nothing changed
|
|
104
105
|
```
|
|
105
106
|
|
|
107
|
+
### Notice.reset ( )
|
|
108
|
+
Will remove all events and functions from the event emitter.
|
|
109
|
+
```js
|
|
110
|
+
let result = 0;
|
|
111
|
+
const
|
|
112
|
+
eBus = notice ()
|
|
113
|
+
, fn1 = () => result += 1
|
|
114
|
+
, fn2 = () => result += 3
|
|
115
|
+
, fn3 = () => result += 20
|
|
116
|
+
;
|
|
106
117
|
|
|
118
|
+
eBus.on ( 'go', fn1 )
|
|
119
|
+
eBus.on ( 'go', fn2 )
|
|
120
|
+
eBus.on ( 'load', fn3 )
|
|
121
|
+
eBus.reset () // Remove all events and functions
|
|
122
|
+
eBus.emit ( 'go' )
|
|
123
|
+
eBus.emit ( 'load' )
|
|
124
|
+
// ---> result == 0
|
|
125
|
+
```
|
|
107
126
|
|
|
108
127
|
|
|
109
128
|
### Notice.emit ( eventName, data )
|
|
@@ -156,19 +175,20 @@ Enable again specified event.
|
|
|
156
175
|
|
|
157
176
|
```js
|
|
158
177
|
let result = 0;
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// ---> result == 0
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
178
|
+
const
|
|
179
|
+
eBus = notice ()
|
|
180
|
+
, fn1 = x => result += 1 + x
|
|
181
|
+
, fn2 = x => result += 3 + x
|
|
182
|
+
;
|
|
183
|
+
eBus.on ( 'go', fn1 )
|
|
184
|
+
eBus.on ( 'go', fn2 )
|
|
185
|
+
eBus.stop ( 'go' )
|
|
186
|
+
eBus.emit ( 'go', 2 )
|
|
187
|
+
// ---> result == 0
|
|
188
|
+
eBus.start ( 'go' )
|
|
189
|
+
eBus.emit ( 'go', 1 )
|
|
190
|
+
console.log ( result )
|
|
191
|
+
// ---> result == 6
|
|
172
192
|
```
|
|
173
193
|
|
|
174
194
|
|
|
@@ -189,25 +209,11 @@ eBus.emit ( 'dummy' )
|
|
|
189
209
|
```
|
|
190
210
|
|
|
191
211
|
|
|
192
|
-
## Release History
|
|
193
|
-
|
|
194
|
-
### 1.1.0 ( 2022-10-21)
|
|
195
|
-
- [x] Method 'debug' was added;
|
|
196
|
-
|
|
197
|
-
### 1.0.1 ( 2022-08-15)
|
|
198
|
-
- [x] Fix: Event data is coming in Array;
|
|
199
|
-
- [x] Fix: Multiple instances of notice;
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
### 1.0.0 (2021-05-12)
|
|
204
|
-
- [x] Initial code;
|
|
205
|
-
- [x] Test package;
|
|
206
|
-
- [x] Documentation;
|
|
207
|
-
- [ ] Bug: Event data is coming in Array;
|
|
208
|
-
- [ ] Bug: Multiple instances of notice;
|
|
209
212
|
|
|
213
|
+
## External Links
|
|
210
214
|
|
|
215
|
+
- [History of changes](https://github.com/PeterNaydenov/notice/Changelog.md)
|
|
216
|
+
- [MIT License](https://github.com/PeterNaydenov/notice/LICENSE)
|
|
211
217
|
|
|
212
218
|
|
|
213
219
|
|
package/package.json
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peter.naydenov/notice",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "Event emmiter - NOTICE",
|
|
5
5
|
"main": "src/main.js",
|
|
6
|
+
"type": "module",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"test": "mocha test",
|
|
8
|
-
"cover": "
|
|
9
|
+
"cover": "c8 mocha"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/PeterNaydenov/notice"
|
|
9
14
|
},
|
|
10
15
|
"author": "Peter Naydenov",
|
|
11
16
|
"keywords": [
|
|
@@ -15,13 +20,13 @@
|
|
|
15
20
|
"subscriber",
|
|
16
21
|
"pubsub"
|
|
17
22
|
],
|
|
18
|
-
"license": "
|
|
23
|
+
"license": "MIT",
|
|
19
24
|
"devDependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
25
|
+
"c8": "^8.0.0",
|
|
26
|
+
"chai": "4.3.7",
|
|
27
|
+
"mocha": "10.2.0"
|
|
23
28
|
},
|
|
24
|
-
"
|
|
29
|
+
"c8": {
|
|
25
30
|
"include": [
|
|
26
31
|
"src/**/*.js"
|
|
27
32
|
],
|
package/src/main.js
CHANGED
|
@@ -27,6 +27,11 @@ function notice () {
|
|
|
27
27
|
if ( scrollOnce[e] ) delete scrollOnce[e]
|
|
28
28
|
if ( scroll[e] ) delete scroll[e]
|
|
29
29
|
} // off func.
|
|
30
|
+
function reset () {
|
|
31
|
+
scroll = {}
|
|
32
|
+
scrollOnce = {}
|
|
33
|
+
ignore = []
|
|
34
|
+
} // reset func.
|
|
30
35
|
function debug ( val, header ) {
|
|
31
36
|
debugFlag = val ? true : false
|
|
32
37
|
if ( header && (typeof header === 'string') ) debugHeader = header
|
|
@@ -82,6 +87,7 @@ function notice () {
|
|
|
82
87
|
on // Register a event
|
|
83
88
|
, once // Register a single event
|
|
84
89
|
, off // Unregister regular and single events
|
|
90
|
+
, reset // Unregister all events
|
|
85
91
|
, emit // Trigger a event
|
|
86
92
|
, stop // Ignore event for a while
|
|
87
93
|
, start // Remove event from ignore list
|
|
@@ -93,6 +99,6 @@ function notice () {
|
|
|
93
99
|
|
|
94
100
|
|
|
95
101
|
|
|
96
|
-
|
|
102
|
+
export default notice
|
|
97
103
|
|
|
98
104
|
|
package/test/01-notice.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict"
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import notice from '../src/main.js'
|
|
4
|
+
import { expect } from 'chai'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
7
9
|
|
|
8
10
|
describe ( 'Testing Notice', () => {
|
|
9
11
|
|
|
12
|
+
|
|
13
|
+
|
|
10
14
|
it ( 'Standard event', () => {
|
|
11
15
|
const eBus = notice ();
|
|
12
16
|
let result = 0;
|
|
@@ -65,6 +69,20 @@ it ( 'Remove single event', () => {
|
|
|
65
69
|
|
|
66
70
|
|
|
67
71
|
|
|
72
|
+
it ( 'Reset the emitter', () => {
|
|
73
|
+
const eBus = notice ();
|
|
74
|
+
let result = 0;
|
|
75
|
+
|
|
76
|
+
eBus.once ( 'note', () => result += 1 )
|
|
77
|
+
eBus.on ( 'note', () => result += 3 )
|
|
78
|
+
eBus.on ( 'boom', () => result += 9 )
|
|
79
|
+
eBus.reset ()
|
|
80
|
+
eBus.emit ( 'note' )
|
|
81
|
+
eBus.emit ( 'boom' )
|
|
82
|
+
expect ( result ).to.be.equal ( 0 )
|
|
83
|
+
}) // it reset the emitter
|
|
84
|
+
|
|
85
|
+
|
|
68
86
|
it ( 'Stop and resume standard event', () => {
|
|
69
87
|
const eBus = notice ();
|
|
70
88
|
let result = 0;
|
|
@@ -258,6 +276,7 @@ it ( 'Multiple Notice instances', () => {
|
|
|
258
276
|
}) // it Multiple Notice instances
|
|
259
277
|
|
|
260
278
|
|
|
279
|
+
|
|
261
280
|
}) // define
|
|
262
281
|
|
|
263
282
|
|