@vnejs/observer 0.0.1 → 0.0.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/index.js +8 -3
- package/package.json +8 -2
package/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
const
|
|
1
|
+
const notUndef = (e) => e !== undefined;
|
|
2
|
+
const getFirstArrayElement = (arr) => arr[0];
|
|
3
|
+
const getFirstRealArrayElement = (arr) => arr.filter(Boolean)[0];
|
|
4
|
+
const getRealArrayElements = (arr) => arr.filter(Boolean);
|
|
2
5
|
|
|
3
6
|
export class Observer {
|
|
4
7
|
subscribers = {};
|
|
@@ -14,7 +17,7 @@ export class Observer {
|
|
|
14
17
|
this.subscribers[event].push(func);
|
|
15
18
|
};
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
emit = async (e, ...args) => {
|
|
18
21
|
if (!e || !this.subscribers[e]) {
|
|
19
22
|
console.error("Event is undefined or no subscribers:", e, "| args:", args);
|
|
20
23
|
return [];
|
|
@@ -23,5 +26,7 @@ export class Observer {
|
|
|
23
26
|
return Promise.all(this.subscribers[e].map((func) => func(...args)));
|
|
24
27
|
};
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
emitOne = (e, ...args) => this.emit(e, ...args).then(getFirstArrayElement);
|
|
30
|
+
emitReal = (e, ...args) => this.emit(e, ...args).then(getFirstRealArrayElement);
|
|
31
|
+
emitReals = (e, ...args) => this.emit(e, ...args).then(getRealArrayElements);
|
|
27
32
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
8
|
+
"publish:major:plugin": "npm run publish:major",
|
|
9
|
+
"publish:minor:plugin": "npm run publish:minor",
|
|
10
|
+
"publish:patch:plugin": "npm run publish:patch",
|
|
11
|
+
"publish:major": "npm version major && npm publish --access public",
|
|
12
|
+
"publish:minor": "npm version minor && npm publish --access public",
|
|
13
|
+
"publish:patch": "npm version patch && npm publish --access public"
|
|
8
14
|
},
|
|
9
15
|
"author": "",
|
|
10
16
|
"license": "ISC"
|