@aiao/rxdb-react 0.0.15 → 0.0.17

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/README.md CHANGED
@@ -1 +1,36 @@
1
- # rxdb-react
1
+ # @aiao/rxdb-react
2
+
3
+ React 框架集成库,为 React 应用提供 RxDB 支持。基于 React Hooks 实现响应式数据流。
4
+
5
+ ## 功能特性
6
+
7
+ - **React Hooks 集成**: 使用 useRxdb、useCollection 等 Hooks
8
+ - **组件库**: 提供数据展示、编辑、表单等常用组件
9
+ - **TypeScript 支持**: 完整的类型定义
10
+
11
+ ## 安装
12
+
13
+ ```bash
14
+ npm install @aiao/rxdb @aiao/rxdb-react
15
+ # 或
16
+ pnpm add @aiao/rxdb @aiao/rxdb-react
17
+ ```
18
+
19
+ ## 使用
20
+
21
+ ```tsx
22
+ import { RxdbProvider } from '@aiao/rxdb-react';
23
+
24
+ function App() {
25
+ return (
26
+ <RxdbProvider>
27
+ <YourApp />
28
+ </RxdbProvider>
29
+ );
30
+ }
31
+ ```
32
+
33
+ ## 相关包
34
+
35
+ - [@aiao/rxdb](../rxdb) - 核心库
36
+ - [@aiao/code-editor-react](../code-editor-react) - 代码编辑器
package/dist/index.js CHANGED
@@ -1,41 +1,41 @@
1
1
  import { isFunction as H, cloneDeep as J } from "@aiao/utils";
2
- import { useState as a, useRef as f, useMemo as P, useEffect as N, createContext as Q, useContext as U, useCallback as m } from "react";
2
+ import { useState as l, useRef as a, useMemo as P, useEffect as N, createContext as Q, useContext as U, useCallback as m } from "react";
3
3
  import { jsx as W } from "react/jsx-runtime";
4
- const s = (r, e, c, g) => {
5
- const [D, p] = a(c), [y, l] = a(void 0), [B, d] = a(!0), [u, C] = a(void 0), [I, b] = a(!1), o = f(void 0), i = f(!0), M = P(() => H(g) ? g() : g, [g]);
4
+ const s = (r, e, c, h) => {
5
+ const [D, p] = l(c), [y, d] = l(void 0), [B, u] = l(!0), [i, C] = l(void 0), [I, b] = l(!1), o = a(void 0), f = a(!0), M = P(() => H(h) ? h() : h, [h]);
6
6
  return N(() => {
7
- i.current = !0, o.current && (o.current.unsubscribe(), o.current = void 0);
8
- const h = r[e];
9
- if (!h || typeof h != "function") {
7
+ f.current = !0, o.current && (o.current.unsubscribe(), o.current = void 0);
8
+ const g = r[e];
9
+ if (!g || typeof g != "function") {
10
10
  const t = new Error(`Method "${String(e)}" not found on EntityType`);
11
11
  Promise.resolve().then(() => {
12
- i.current && (l(t), d(!1));
12
+ f.current && (d(t), u(!1));
13
13
  });
14
14
  return;
15
15
  }
16
16
  try {
17
- o.current = h(M).subscribe({
17
+ o.current = g(M).subscribe({
18
18
  next: (t) => {
19
- i.current && (d(!1), b(!0), l(void 0), Array.isArray(t) ? C(t.length === 0) : C(t == null), p(t));
19
+ f.current && (u(!1), b(!0), d(void 0), Array.isArray(t) ? C(t.length === 0) : C(t == null), p(t));
20
20
  },
21
21
  error: (t) => {
22
- i.current && (d(!1), b(!1), l(t), console.error(`RxDB query error in ${String(e)}:`, t));
22
+ f.current && (u(!1), b(!1), d(t), console.error(`RxDB query error in ${String(e)}:`, t));
23
23
  }
24
24
  });
25
25
  } catch (t) {
26
26
  const x = t instanceof Error ? t : new Error(String(t));
27
27
  Promise.resolve().then(() => {
28
- i.current && (d(!1), l(x));
28
+ f.current && (u(!1), d(x));
29
29
  });
30
30
  }
31
31
  return () => {
32
- i.current = !1, o.current && (o.current.unsubscribe(), o.current = void 0);
32
+ f.current = !1, o.current && (o.current.unsubscribe(), o.current = void 0);
33
33
  };
34
34
  }, [r, e, M]), {
35
35
  value: D,
36
36
  error: y,
37
37
  isLoading: B,
38
- isEmpty: u,
38
+ isEmpty: i,
39
39
  hasValue: I
40
40
  };
41
41
  }, re = (r, e) => s(r, "get", void 0, e), te = (r, e) => s(r, "findOne", void 0, e), ne = (r, e) => s(r, "findOneOrFail", void 0, e), se = (r, e) => s(r, "find", [], e), oe = (r, e) => s(r, "findByCursor", [], e), ce = (r, e) => s(r, "findAll", [], e), ue = (r, e) => s(r, "count", 0, e), ie = (r, e) => s(r, "findDescendants", [], e), fe = (r, e) => s(r, "countDescendants", 0, e), ae = (r, e) => s(r, "findAncestors", [], e), le = (r, e) => s(r, "countAncestors", 0, e), de = (r, e) => s(r, "findNeighbors", [], e), ge = (r, e) => s(r, "countNeighbors", 0, e), he = (r, e) => s(r, "findPaths", [], e);
@@ -53,24 +53,24 @@ function X() {
53
53
  }
54
54
  const { RxDBProvider: ve, useRxDB: Y } = X();
55
55
  function pe(r, e) {
56
- const c = Y(), [g, D] = a([]), p = f([]), y = m(
56
+ const c = Y(), [h, D] = l([]), p = a([]), y = m(
57
57
  (n) => {
58
58
  const F = typeof n == "function" ? n(p.current) : n;
59
59
  p.current = F, D(F);
60
60
  },
61
61
  []
62
- ), [l, B] = a(!1), d = f(!1), u = m((n) => {
63
- d.current = n, B(n);
64
- }, []), [C, I] = a(!0), b = f(!0), o = m((n) => {
62
+ ), [d, B] = l(!1), u = a(!1), i = m((n) => {
63
+ u.current = n, B(n);
64
+ }, []), [C, I] = l(!0), b = a(!0), o = m((n) => {
65
65
  b.current = n, I(n);
66
- }, []), [i, M] = a(!1), h = f(!1), t = f(!1), x = f([]), O = P(() => H(e) ? e() : e, [e]), E = P(() => JSON.stringify(O), [O]), A = P(() => g.flat(), [g]), V = P(
67
- () => A.length === 0 && !l && i,
68
- [A.length, l, i]
66
+ }, []), [f, M] = l(!1), g = a(!1), t = a(!1), x = a([]), O = P(() => H(e) ? e() : e, [e]), E = P(() => JSON.stringify(O), [O]), A = P(() => h.flat(), [h]), V = P(
67
+ () => A.length === 0 && !d && f,
68
+ [A.length, d, f]
69
69
  ), R = m(() => {
70
70
  x.current.forEach((n) => n.unsubscribe()), x.current = [];
71
71
  }, []), v = m(() => {
72
- if (d.current || !b.current || !t.current) return;
73
- u(!0);
72
+ if (u.current || !b.current || !t.current) return;
73
+ i(!0);
74
74
  const n = p.current, F = n.length, S = n.length > 0 ? n[n.length - 1] : void 0, q = S && S.length > 0 ? S[S.length - 1] : void 0, L = J(O);
75
75
  q && (L.after = q);
76
76
  const K = c.entityManager.getRepository(r).findByCursor(L).subscribe({
@@ -81,33 +81,33 @@ function pe(r, e) {
81
81
  return G[F] = z, G;
82
82
  });
83
83
  const $ = L.limit || 100;
84
- z.length < $ && o(!1), u(!1);
84
+ z.length < $ && o(!1), i(!1);
85
85
  },
86
86
  error: () => {
87
- t.current && u(!1);
87
+ t.current && i(!1);
88
88
  },
89
89
  complete: () => {
90
- t.current && u(!1);
90
+ t.current && i(!1);
91
91
  }
92
92
  });
93
93
  x.current.push(K);
94
- }, [r, O, c, o, u, y]), k = m(() => {
94
+ }, [r, O, c, o, i, y]), k = m(() => {
95
95
  if (!t.current) {
96
96
  console.warn("Cannot refresh: component is unmounted");
97
97
  return;
98
98
  }
99
- R(), y([]), u(!1), o(!0), v();
100
- }, [R, v, o, u, y]);
101
- N(() => (t.current = !0, h.current || (h.current = !0, M(!0), v()), () => {
102
- t.current = !1, R();
99
+ R(), y([]), i(!1), o(!0), v();
100
+ }, [R, v, o, i, y]);
101
+ N(() => (t.current = !0, g.current || (g.current = !0, M(!0), v()), () => {
102
+ t.current = !1, g.current = !1, u.current = !1, R();
103
103
  }), [R, v]);
104
- const w = f(E);
104
+ const w = a(E);
105
105
  return N(() => {
106
- h.current && w.current !== E && (w.current = E, R(), p.current = [], d.current = !1, b.current = !0, D([]), B(!1), I(!0), v());
106
+ g.current && w.current !== E && (w.current = E, R(), p.current = [], u.current = !1, b.current = !0, D([]), B(!1), I(!0), v());
107
107
  }, [E, R, v]), {
108
108
  value: A,
109
109
  isEmpty: V,
110
- isLoading: l,
110
+ isLoading: d,
111
111
  hasMore: C,
112
112
  loadMore: v,
113
113
  refresh: k
@@ -1 +1 @@
1
- {"version":3,"file":"useInfiniteScroll.d.ts","sourceRoot":"","sources":["../src/useInfiniteScroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,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AAC,YAAY,CAAC,CAAC,CAAC,CAAC,CA2JzC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiao/rxdb-react",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -15,8 +15,8 @@
15
15
  }
16
16
  },
17
17
  "dependencies": {
18
- "@aiao/rxdb": "0.0.15",
19
- "@aiao/utils": "0.0.15"
18
+ "@aiao/rxdb": "0.0.17",
19
+ "@aiao/utils": "0.0.17"
20
20
  },
21
21
  "peerDependencies": {
22
22
  "react": ">=19.0.0",
@@ -155,6 +155,8 @@ export function useInfiniteScroll<T extends EntityType>(
155
155
 
156
156
  return () => {
157
157
  isMounted.current = false;
158
+ isInitializedRef.current = false;
159
+ isLoadingRef.current = false;
158
160
  clearSubscriptions();
159
161
  };
160
162
  }, [clearSubscriptions, loadMore]);