@leancodepl/hook-pipe-client 8.4.0 → 8.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leancodepl/hook-pipe-client",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "dependencies": {
6
6
  "@leancodepl/pipe": "^1.0.0",
@@ -10,16 +10,55 @@
10
10
  "react": "*",
11
11
  "rxjs": ">=7.0.0"
12
12
  },
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
17
+ "engines": {
18
+ "node": ">=18.0.0"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/leancodepl/js_corelibrary.git",
23
+ "directory": "packages/pipe-clients/hook-pipe-client"
24
+ },
25
+ "homepage": "https://github.com/leancodepl/js_corelibrary",
26
+ "bugs": {
27
+ "url": "https://github.com/leancodepl/js_corelibrary/issues"
28
+ },
29
+ "description": "React hooks for real-time data streaming and subscriptions using @leancodepl/pipe",
30
+ "keywords": [
31
+ "react",
32
+ "hooks",
33
+ "real-time",
34
+ "streaming",
35
+ "websocket",
36
+ "signalr",
37
+ "leanpipe",
38
+ "typescript",
39
+ "javascript",
40
+ "leancode"
41
+ ],
42
+ "author": {
43
+ "name": "LeanCode",
44
+ "url": "https://leancode.co"
45
+ },
46
+ "files": [
47
+ "dist",
48
+ "README.md",
49
+ "CHANGELOG.md"
50
+ ],
51
+ "sideEffects": false,
13
52
  "exports": {
14
53
  "./package.json": "./package.json",
15
54
  ".": {
16
55
  "module": "./index.esm.js",
17
- "types": "./index.esm.d.ts",
56
+ "types": "./index.d.ts",
18
57
  "import": "./index.cjs.mjs",
19
58
  "default": "./index.cjs.js"
20
59
  }
21
60
  },
22
61
  "module": "./index.esm.js",
23
62
  "main": "./index.cjs.js",
24
- "types": "./index.esm.d.ts"
63
+ "types": "./index.d.ts"
25
64
  }
package/index.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
@@ -1 +0,0 @@
1
- exports._default = require('./index.cjs.js').default;
package/index.cjs.js DELETED
@@ -1,39 +0,0 @@
1
- 'use strict';
2
-
3
- var react = require('react');
4
- var deepEqual = require('deep-equal');
5
- var rxjs = require('rxjs');
6
-
7
- function mkPipeClient({ pipe }) {
8
- return {
9
- createTopic (topicType) {
10
- function useTopic(topic, { onData }) {
11
- const [data, setData] = react.useState();
12
- const onDataRef = react.useRef(onData);
13
- onDataRef.current = onData;
14
- const memoizedTopic = react.useRef();
15
- if (memoizedTopic.current === undefined || !deepEqual(memoizedTopic.current, topic)) {
16
- memoizedTopic.current = topic;
17
- }
18
- react.useEffect(()=>{
19
- const topic$ = pipe.topic(topicType, memoizedTopic.current).pipe(rxjs.share());
20
- const subscription = topic$.subscribe((data)=>{
21
- setData(data);
22
- onDataRef.current == null ? void 0 : onDataRef.current.call(onDataRef, data);
23
- });
24
- return ()=>subscription.unsubscribe();
25
- // eslint-disable-next-line react-hooks/exhaustive-deps
26
- }, [
27
- memoizedTopic.current
28
- ]);
29
- return {
30
- data
31
- };
32
- }
33
- useTopic.topic = (topic)=>pipe.topic(topicType, topic);
34
- return useTopic;
35
- }
36
- };
37
- }
38
-
39
- exports.mkPipeClient = mkPipeClient;
package/index.cjs.mjs DELETED
@@ -1,2 +0,0 @@
1
- export * from './index.cjs.js';
2
- export { _default as default } from './index.cjs.default.js';
package/index.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/index";
package/index.esm.js DELETED
@@ -1,37 +0,0 @@
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/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./lib/mkPipeClient";
@@ -1,14 +0,0 @@
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): {
6
- (topic: TTopic, { onData }: UseSubscriptionOptions<TNotifications>): {
7
- data: NotificationsUnion<TNotifications> | undefined;
8
- };
9
- topic(topic: TTopic): import("rxjs").Observable<NotificationsUnion<TNotifications>>;
10
- };
11
- };
12
- export type UseSubscriptionOptions<TNotifications extends Record<string, unknown>> = {
13
- onData?: (data: NotificationsUnion<TNotifications>) => void;
14
- };