@lincode/events 1.0.26 → 1.0.28
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/lib/event.d.ts +18 -3
- package/lib/event.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib-commonjs/event.js +2 -0
- package/package.json +4 -5
- package/src/event.ts +11 -4
- package/src/index.ts +1 -1
package/lib/event.d.ts
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
import { Cancellable } from "@lincode/promiselikes";
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare class Event<Payload = void> {
|
|
3
|
+
private cbs;
|
|
4
|
+
private state?;
|
|
5
|
+
on(cb: (val: Payload) => void): Cancellable;
|
|
6
|
+
once(cb: (val: Payload) => void): Cancellable;
|
|
7
|
+
emit(value: Payload): void;
|
|
8
|
+
setState(value: Payload): void;
|
|
9
|
+
getState(): Payload | undefined;
|
|
10
|
+
}
|
|
11
|
+
type Emit<T> = (val: T, isState?: boolean) => void;
|
|
12
|
+
type On<T> = (cb: (val: T) => void, once?: boolean) => Cancellable;
|
|
13
|
+
type GetState<T> = () => T | undefined;
|
|
14
|
+
export type EventFunctions = readonly [
|
|
15
|
+
Emit<void>,
|
|
16
|
+
On<void>,
|
|
17
|
+
Emit<void>,
|
|
18
|
+
GetState<void>
|
|
19
|
+
];
|
|
5
20
|
declare const _default: <T = void>() => readonly [Emit<T>, On<T>, Emit<T>, GetState<T>];
|
|
6
21
|
export default _default;
|
package/lib/event.js
CHANGED
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default, default as Events } from "./Events";
|
|
2
|
-
export { default as event,
|
|
2
|
+
export { default as event, EventFunctions } from "./event";
|
package/lib-commonjs/event.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Event = void 0;
|
|
3
4
|
const promiselikes_1 = require("@lincode/promiselikes");
|
|
4
5
|
class Event {
|
|
5
6
|
constructor() {
|
|
@@ -33,6 +34,7 @@ class Event {
|
|
|
33
34
|
return this.state;
|
|
34
35
|
}
|
|
35
36
|
}
|
|
37
|
+
exports.Event = Event;
|
|
36
38
|
exports.default = () => {
|
|
37
39
|
const event = new Event();
|
|
38
40
|
const emit = (val) => event.emit(val);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lincode/events",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.28",
|
|
4
4
|
"description": "Generated by ambients-cli",
|
|
5
5
|
"author": "Lai Schwe",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,12 +8,11 @@
|
|
|
8
8
|
"ambients"
|
|
9
9
|
],
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@lincode/promiselikes": "
|
|
12
|
-
"@lincode/utils": "
|
|
11
|
+
"@lincode/promiselikes": "^1.0.24",
|
|
12
|
+
"@lincode/utils": "^1.3.5"
|
|
13
13
|
},
|
|
14
|
-
"peerDependencies": {},
|
|
15
14
|
"devDependencies": {
|
|
16
|
-
"typescript": "
|
|
15
|
+
"typescript": "^4.9.4"
|
|
17
16
|
},
|
|
18
17
|
"scripts": {
|
|
19
18
|
"build": "ambients clean && yarn tsc && yarn tsc -p tsconfig-commonjs.json",
|
package/src/event.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cancellable } from "@lincode/promiselikes"
|
|
2
2
|
|
|
3
|
-
class Event<Payload = void> {
|
|
3
|
+
export class Event<Payload = void> {
|
|
4
4
|
private cbs = new Set<(val: Payload) => void>()
|
|
5
5
|
private state?: Payload
|
|
6
6
|
|
|
@@ -37,9 +37,16 @@ class Event<Payload = void> {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
type Emit<T> = (val: T, isState?: boolean) => void
|
|
41
|
+
type On<T> = (cb: (val: T) => void, once?: boolean) => Cancellable
|
|
42
|
+
type GetState<T> = () => T | undefined
|
|
43
|
+
|
|
44
|
+
export type EventFunctions = readonly [
|
|
45
|
+
Emit<void>,
|
|
46
|
+
On<void>,
|
|
47
|
+
Emit<void>,
|
|
48
|
+
GetState<void>
|
|
49
|
+
]
|
|
43
50
|
|
|
44
51
|
export default <T = void>() => {
|
|
45
52
|
const event = new Event<T>()
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default, default as Events } from "./Events"
|
|
2
|
-
export { default as event,
|
|
2
|
+
export { default as event, EventFunctions } from "./event"
|