@leancodepl/hook-pipe-client 7.6.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/index.cjs.d.ts +1 -0
- package/index.cjs.js +30 -0
- package/package.json +10 -0
- package/src/index.d.ts +1 -0
- package/src/lib/mkPipeClient.d.ts +12 -0
package/index.cjs.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./src/index";
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function mkPipeClient({ pipe }) {
|
|
8
|
+
return {
|
|
9
|
+
createTopic (topicType) {
|
|
10
|
+
return (topic, { onData })=>{
|
|
11
|
+
const [data, setData] = react.useState();
|
|
12
|
+
react.useEffect(()=>{
|
|
13
|
+
const subscription = pipe.topic(topicType, topic).subscribe((notification)=>{
|
|
14
|
+
onData == null ? void 0 : onData(notification);
|
|
15
|
+
setData(notification);
|
|
16
|
+
});
|
|
17
|
+
return ()=>subscription.unsubscribe();
|
|
18
|
+
}, [
|
|
19
|
+
onData,
|
|
20
|
+
topic
|
|
21
|
+
]);
|
|
22
|
+
return {
|
|
23
|
+
data
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
exports.mkPipeClient = mkPipeClient;
|
package/package.json
ADDED
package/src/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./lib/mkPipeClient";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NotificationsUnion, Pipe } from "@leancodepl/pipe";
|
|
2
|
+
export declare function mkPipeClient({ pipe }: {
|
|
3
|
+
pipe: Pipe;
|
|
4
|
+
}): {
|
|
5
|
+
createTopic<TTopic, TNotifications extends Record<string, unknown>>(topicType: string): (topic: TTopic, { onData }: UseSubscriptionOptions<TNotifications>) => {
|
|
6
|
+
data: NotificationsUnion<TNotifications> | undefined;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
type UseSubscriptionOptions<TNotifications extends Record<string, unknown>> = {
|
|
10
|
+
onData?: (data: NotificationsUnion<TNotifications>) => void;
|
|
11
|
+
};
|
|
12
|
+
export {};
|