@leancodepl/hook-pipe-client 7.8.1 → 7.8.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.
@@ -0,0 +1 @@
1
+ exports._default = require('./index.cjs.js').default;
package/index.cjs.mjs ADDED
@@ -0,0 +1,2 @@
1
+ export * from './index.cjs.js';
2
+ export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from "./src/index";
package/index.esm.js ADDED
@@ -0,0 +1,37 @@
1
+ import { useState, useRef, useEffect } from 'react';
2
+ import deepEqual from 'deep-equal';
3
+ import { share } from 'rxjs';
4
+
5
+ function mkPipeClient({ pipe }) {
6
+ return {
7
+ createTopic (topicType) {
8
+ function useTopic(topic, { onData }) {
9
+ const [data, setData] = useState();
10
+ const onDataRef = useRef(onData);
11
+ onDataRef.current = onData;
12
+ const memoizedTopic = useRef();
13
+ if (memoizedTopic.current === undefined || !deepEqual(memoizedTopic.current, topic)) {
14
+ memoizedTopic.current = topic;
15
+ }
16
+ useEffect(()=>{
17
+ const topic$ = pipe.topic(topicType, memoizedTopic.current).pipe(share());
18
+ const subscription = topic$.subscribe((data)=>{
19
+ setData(data);
20
+ onDataRef.current == null ? void 0 : onDataRef.current.call(onDataRef, data);
21
+ });
22
+ return ()=>subscription.unsubscribe();
23
+ // eslint-disable-next-line react-hooks/exhaustive-deps
24
+ }, [
25
+ memoizedTopic.current
26
+ ]);
27
+ return {
28
+ data
29
+ };
30
+ }
31
+ useTopic.topic = (topic)=>pipe.topic(topicType, topic);
32
+ return useTopic;
33
+ }
34
+ };
35
+ }
36
+
37
+ export { mkPipeClient };
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@leancodepl/hook-pipe-client",
3
- "version": "7.8.1",
3
+ "version": "7.8.2",
4
+ "license": "Apache-2.0",
4
5
  "dependencies": {
5
6
  "@leancodepl/pipe": "^1.0.0",
6
7
  "deep-equal": "^2.0.0"
@@ -8,7 +9,14 @@
8
9
  "peerDependencies": {
9
10
  "rxjs": ">=7.0.0"
10
11
  },
11
- "type": "commonjs",
12
- "main": "./index.cjs.js",
13
- "module": "./index.js"
12
+ "exports": {
13
+ "./package.json": "./package.json",
14
+ ".": {
15
+ "module": "./index.esm.js",
16
+ "import": "./index.cjs.mjs",
17
+ "default": "./index.cjs.js"
18
+ }
19
+ },
20
+ "module": "./index.esm.js",
21
+ "main": "./index.cjs.js"
14
22
  }