@kuindji/reactive 1.0.8 → 1.0.9
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.
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { BaseActionBus } from "../actionBus";
|
|
2
|
+
import type { ListenerOptions } from "../event";
|
|
3
|
+
import type { ErrorListenerSignature, KeyOf } from "../lib/types";
|
|
4
|
+
export type { BaseActionBus, ErrorListenerSignature, ListenerOptions };
|
|
5
|
+
export declare function useListenToActionBus<TActionBus extends BaseActionBus, TKey extends KeyOf<TActionBus["__type"]["actions"]>, TListener extends TActionBus["__type"]["actions"][TKey]["listenerSignature"]>(actionBus: TActionBus, actionName: TKey, listener: TListener, options?: ListenerOptions, errorListener?: ErrorListenerSignature<any[]>): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useListenToActionBus = useListenToActionBus;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function useListenToActionBus(actionBus, actionName, listener, options, errorListener) {
|
|
6
|
+
const listenerRef = (0, react_1.useRef)(listener);
|
|
7
|
+
const actionBusRef = (0, react_1.useRef)(actionBus);
|
|
8
|
+
const errorListenerRef = (0, react_1.useRef)(errorListener);
|
|
9
|
+
listenerRef.current = listener;
|
|
10
|
+
const genericHandler = (0, react_1.useCallback)((arg) => {
|
|
11
|
+
var _a;
|
|
12
|
+
return (_a = listenerRef.current) === null || _a === void 0 ? void 0 : _a.call(listenerRef, arg);
|
|
13
|
+
}, []);
|
|
14
|
+
(0, react_1.useEffect)(() => {
|
|
15
|
+
return () => {
|
|
16
|
+
actionBusRef.current.removeListener(actionName, genericHandler);
|
|
17
|
+
if (errorListenerRef.current) {
|
|
18
|
+
actionBusRef.current.removeErrorListener(errorListenerRef.current);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}, []);
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
actionBusRef.current.removeListener(actionName, genericHandler);
|
|
24
|
+
actionBusRef.current = actionBus;
|
|
25
|
+
actionBusRef.current.addListener(actionName, genericHandler, options);
|
|
26
|
+
}, [actionBus]);
|
|
27
|
+
(0, react_1.useEffect)(() => {
|
|
28
|
+
if (errorListenerRef.current !== errorListener) {
|
|
29
|
+
if (errorListenerRef.current) {
|
|
30
|
+
actionBusRef.current.removeErrorListener(errorListenerRef.current);
|
|
31
|
+
}
|
|
32
|
+
errorListenerRef.current = errorListener;
|
|
33
|
+
if (errorListener) {
|
|
34
|
+
actionBusRef.current.addErrorListener(errorListener);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}, [errorListener]);
|
|
38
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BaseEvent, ListenerOptions } from "
|
|
1
|
+
import type { BaseEvent, ListenerOptions } from "../event";
|
|
2
2
|
import type { ErrorListenerSignature } from "../lib/types";
|
|
3
3
|
export type { BaseEvent, ErrorListenerSignature, ListenerOptions };
|
|
4
4
|
export declare function useListenToEvent<TEvent extends BaseEvent, TListenerSignature extends TEvent["__type"]["signature"], TErrorListenerSignature extends TEvent["__type"]["errorListenerSignature"]>(event: TEvent, listener: TListenerSignature, options?: ListenerOptions, errorListener?: TErrorListenerSignature): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { BaseEventBus } from "../../src/eventBus";
|
|
2
|
-
import type { ErrorListenerSignature, KeyOf } from "../../src/lib/types";
|
|
3
1
|
import type { ListenerOptions } from "../event";
|
|
2
|
+
import type { BaseEventBus } from "../eventBus";
|
|
3
|
+
import type { ErrorListenerSignature, KeyOf } from "../lib/types";
|
|
4
4
|
export type { BaseEventBus, ErrorListenerSignature, ListenerOptions };
|
|
5
5
|
export declare function useListenToEventBus<TEventBus extends BaseEventBus, TKey extends KeyOf<TEventBus["__type"]["eventSignatures"]>, TListener extends TEventBus["__type"]["eventSignatures"][TKey]>(eventBus: TEventBus, eventName: TKey, listener: TListener, options?: ListenerOptions, errorListener?: ErrorListenerSignature<any[]>): void;
|
package/dist/react.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export * from "./react/useActionMap";
|
|
|
4
4
|
export * from "./react/useEvent";
|
|
5
5
|
export * from "./react/useEventBus";
|
|
6
6
|
export * from "./react/useListenToAction";
|
|
7
|
+
export * from "./react/useListenToActionBus";
|
|
7
8
|
export * from "./react/useListenToEvent";
|
|
8
9
|
export * from "./react/useListenToEventBus";
|
|
9
10
|
export * from "./react/useListenToStoreChanges";
|
package/dist/react.js
CHANGED
|
@@ -20,6 +20,7 @@ __exportStar(require("./react/useActionMap"), exports);
|
|
|
20
20
|
__exportStar(require("./react/useEvent"), exports);
|
|
21
21
|
__exportStar(require("./react/useEventBus"), exports);
|
|
22
22
|
__exportStar(require("./react/useListenToAction"), exports);
|
|
23
|
+
__exportStar(require("./react/useListenToActionBus"), exports);
|
|
23
24
|
__exportStar(require("./react/useListenToEvent"), exports);
|
|
24
25
|
__exportStar(require("./react/useListenToEventBus"), exports);
|
|
25
26
|
__exportStar(require("./react/useListenToStoreChanges"), exports);
|
package/package.json
CHANGED