@oimdb/react 1.0.5 → 1.0.6
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/dist/index.cjs +120 -20
- package/dist/index.js +121 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -41,72 +41,172 @@ var useSelectPksByIndexKeys = (reactiveIndex, keys) => {
|
|
|
41
41
|
const snapshotValueRef = (0, import_react.useRef)(
|
|
42
42
|
keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat()
|
|
43
43
|
);
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const listener = (0, import_react.useRef)(
|
|
45
|
+
() => () => {
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
49
|
+
const list = (onStoreChange) => {
|
|
46
50
|
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
47
51
|
onStoreChange();
|
|
48
|
-
|
|
49
|
-
|
|
52
|
+
return () => {
|
|
53
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
54
|
+
keys,
|
|
55
|
+
list
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
reactiveIndex.updateEventEmitter.subscribeOnKeys(
|
|
60
|
+
keys,
|
|
61
|
+
list
|
|
62
|
+
);
|
|
63
|
+
listener.current = list;
|
|
64
|
+
return () => {
|
|
65
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
66
|
+
keys,
|
|
67
|
+
list
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
}, [keys, reactiveIndex.updateEventEmitter, reactiveIndex]);
|
|
50
71
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
51
72
|
return () => {
|
|
52
73
|
return snapshotValueRef.current;
|
|
53
74
|
};
|
|
54
75
|
}, []);
|
|
55
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
76
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
77
|
+
listener.current,
|
|
78
|
+
getSnapshot,
|
|
79
|
+
getSnapshot
|
|
80
|
+
);
|
|
56
81
|
return snapshot;
|
|
57
82
|
};
|
|
58
83
|
var useSelectPksByIndexKey = (reactiveIndex, key) => {
|
|
59
84
|
const snapshotValueRef = (0, import_react.useRef)(
|
|
60
85
|
Array.from(reactiveIndex.getPksByKey(key))
|
|
61
86
|
);
|
|
62
|
-
const
|
|
63
|
-
|
|
87
|
+
const listener = (0, import_react.useRef)(
|
|
88
|
+
() => () => {
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
(0, import_react.useEffect)(() => {
|
|
92
|
+
const list = (onStoreChange) => {
|
|
64
93
|
snapshotValueRef.current = Array.from(
|
|
65
94
|
reactiveIndex.getPksByKey(key)
|
|
66
95
|
);
|
|
67
96
|
onStoreChange();
|
|
68
|
-
|
|
69
|
-
|
|
97
|
+
return () => {
|
|
98
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
99
|
+
key,
|
|
100
|
+
list
|
|
101
|
+
);
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
reactiveIndex.updateEventEmitter.subscribeOnKey(
|
|
105
|
+
key,
|
|
106
|
+
list
|
|
107
|
+
);
|
|
108
|
+
listener.current = list;
|
|
109
|
+
return () => {
|
|
110
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
111
|
+
key,
|
|
112
|
+
list
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
}, [key, reactiveIndex.updateEventEmitter, reactiveIndex]);
|
|
70
116
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
71
117
|
return () => {
|
|
72
118
|
return snapshotValueRef.current;
|
|
73
119
|
};
|
|
74
120
|
}, []);
|
|
75
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
121
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
122
|
+
listener.current,
|
|
123
|
+
getSnapshot,
|
|
124
|
+
getSnapshot
|
|
125
|
+
);
|
|
76
126
|
return snapshot;
|
|
77
127
|
};
|
|
78
128
|
var selectEntityByPk = (reactiveCollection, pk) => {
|
|
79
129
|
const snapshotValueRef = (0, import_react.useRef)(
|
|
80
130
|
reactiveCollection.getOneByPk(pk)
|
|
81
131
|
);
|
|
82
|
-
const
|
|
83
|
-
|
|
132
|
+
const listener = (0, import_react.useRef)(
|
|
133
|
+
() => () => {
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
(0, import_react.useEffect)(() => {
|
|
137
|
+
const list = (onStoreChange) => {
|
|
84
138
|
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
85
139
|
onStoreChange();
|
|
86
|
-
|
|
87
|
-
|
|
140
|
+
return () => {
|
|
141
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
142
|
+
pk,
|
|
143
|
+
list
|
|
144
|
+
);
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
reactiveCollection.updateEventEmitter.subscribeOnKey(
|
|
148
|
+
pk,
|
|
149
|
+
list
|
|
150
|
+
);
|
|
151
|
+
listener.current = list;
|
|
152
|
+
return () => {
|
|
153
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
154
|
+
pk,
|
|
155
|
+
list
|
|
156
|
+
);
|
|
157
|
+
};
|
|
158
|
+
}, [pk, reactiveCollection.updateEventEmitter, reactiveCollection]);
|
|
88
159
|
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
|
|
89
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
160
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
161
|
+
listener.current,
|
|
162
|
+
getSnapshot,
|
|
163
|
+
getSnapshot
|
|
164
|
+
);
|
|
90
165
|
return snapshot;
|
|
91
166
|
};
|
|
92
167
|
var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
93
168
|
const snapshotValueRef = (0, import_react.useRef)(
|
|
94
169
|
pks.map((pk) => reactiveCollection.getOneByPk(pk))
|
|
95
170
|
);
|
|
96
|
-
const
|
|
97
|
-
|
|
171
|
+
const listener = (0, import_react.useRef)(
|
|
172
|
+
() => () => {
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
(0, import_react.useEffect)(() => {
|
|
176
|
+
const list = (onStoreChange) => {
|
|
98
177
|
snapshotValueRef.current = pks.map(
|
|
99
178
|
(pk) => reactiveCollection.getOneByPk(pk)
|
|
100
179
|
);
|
|
101
180
|
onStoreChange();
|
|
102
|
-
|
|
103
|
-
|
|
181
|
+
return () => {
|
|
182
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
183
|
+
pks,
|
|
184
|
+
list
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
reactiveCollection.updateEventEmitter.subscribeOnKeys(
|
|
189
|
+
pks,
|
|
190
|
+
list
|
|
191
|
+
);
|
|
192
|
+
listener.current = list;
|
|
193
|
+
return () => {
|
|
194
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
195
|
+
pks,
|
|
196
|
+
list
|
|
197
|
+
);
|
|
198
|
+
};
|
|
199
|
+
}, [pks, reactiveCollection.updateEventEmitter, reactiveCollection]);
|
|
104
200
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
105
201
|
return () => {
|
|
106
202
|
return snapshotValueRef.current;
|
|
107
203
|
};
|
|
108
204
|
}, []);
|
|
109
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
205
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
206
|
+
listener.current,
|
|
207
|
+
getSnapshot,
|
|
208
|
+
getSnapshot
|
|
209
|
+
);
|
|
110
210
|
return snapshot;
|
|
111
211
|
};
|
|
112
212
|
var selectEntitiesByIndexKey = (reactiveCollection, reactiveIndex, key) => {
|
package/dist/index.js
CHANGED
|
@@ -1,77 +1,177 @@
|
|
|
1
1
|
// src/hooks/index.ts
|
|
2
|
-
import { useMemo, useRef } from "react";
|
|
2
|
+
import { useMemo, useRef, useEffect } from "react";
|
|
3
3
|
import { useSyncExternalStore } from "react";
|
|
4
4
|
var EMPTY_ARRAY = [];
|
|
5
5
|
var useSelectPksByIndexKeys = (reactiveIndex, keys) => {
|
|
6
6
|
const snapshotValueRef = useRef(
|
|
7
7
|
keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat()
|
|
8
8
|
);
|
|
9
|
-
const
|
|
10
|
-
|
|
9
|
+
const listener = useRef(
|
|
10
|
+
() => () => {
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const list = (onStoreChange) => {
|
|
11
15
|
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
12
16
|
onStoreChange();
|
|
13
|
-
|
|
14
|
-
|
|
17
|
+
return () => {
|
|
18
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
19
|
+
keys,
|
|
20
|
+
list
|
|
21
|
+
);
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
reactiveIndex.updateEventEmitter.subscribeOnKeys(
|
|
25
|
+
keys,
|
|
26
|
+
list
|
|
27
|
+
);
|
|
28
|
+
listener.current = list;
|
|
29
|
+
return () => {
|
|
30
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKeys(
|
|
31
|
+
keys,
|
|
32
|
+
list
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
}, [keys, reactiveIndex.updateEventEmitter, reactiveIndex]);
|
|
15
36
|
const getSnapshot = useMemo(() => {
|
|
16
37
|
return () => {
|
|
17
38
|
return snapshotValueRef.current;
|
|
18
39
|
};
|
|
19
40
|
}, []);
|
|
20
|
-
const snapshot = useSyncExternalStore(
|
|
41
|
+
const snapshot = useSyncExternalStore(
|
|
42
|
+
listener.current,
|
|
43
|
+
getSnapshot,
|
|
44
|
+
getSnapshot
|
|
45
|
+
);
|
|
21
46
|
return snapshot;
|
|
22
47
|
};
|
|
23
48
|
var useSelectPksByIndexKey = (reactiveIndex, key) => {
|
|
24
49
|
const snapshotValueRef = useRef(
|
|
25
50
|
Array.from(reactiveIndex.getPksByKey(key))
|
|
26
51
|
);
|
|
27
|
-
const
|
|
28
|
-
|
|
52
|
+
const listener = useRef(
|
|
53
|
+
() => () => {
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const list = (onStoreChange) => {
|
|
29
58
|
snapshotValueRef.current = Array.from(
|
|
30
59
|
reactiveIndex.getPksByKey(key)
|
|
31
60
|
);
|
|
32
61
|
onStoreChange();
|
|
33
|
-
|
|
34
|
-
|
|
62
|
+
return () => {
|
|
63
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
64
|
+
key,
|
|
65
|
+
list
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
reactiveIndex.updateEventEmitter.subscribeOnKey(
|
|
70
|
+
key,
|
|
71
|
+
list
|
|
72
|
+
);
|
|
73
|
+
listener.current = list;
|
|
74
|
+
return () => {
|
|
75
|
+
reactiveIndex.updateEventEmitter.unsubscribeFromKey(
|
|
76
|
+
key,
|
|
77
|
+
list
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
}, [key, reactiveIndex.updateEventEmitter, reactiveIndex]);
|
|
35
81
|
const getSnapshot = useMemo(() => {
|
|
36
82
|
return () => {
|
|
37
83
|
return snapshotValueRef.current;
|
|
38
84
|
};
|
|
39
85
|
}, []);
|
|
40
|
-
const snapshot = useSyncExternalStore(
|
|
86
|
+
const snapshot = useSyncExternalStore(
|
|
87
|
+
listener.current,
|
|
88
|
+
getSnapshot,
|
|
89
|
+
getSnapshot
|
|
90
|
+
);
|
|
41
91
|
return snapshot;
|
|
42
92
|
};
|
|
43
93
|
var selectEntityByPk = (reactiveCollection, pk) => {
|
|
44
94
|
const snapshotValueRef = useRef(
|
|
45
95
|
reactiveCollection.getOneByPk(pk)
|
|
46
96
|
);
|
|
47
|
-
const
|
|
48
|
-
|
|
97
|
+
const listener = useRef(
|
|
98
|
+
() => () => {
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const list = (onStoreChange) => {
|
|
49
103
|
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
50
104
|
onStoreChange();
|
|
51
|
-
|
|
52
|
-
|
|
105
|
+
return () => {
|
|
106
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
107
|
+
pk,
|
|
108
|
+
list
|
|
109
|
+
);
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
reactiveCollection.updateEventEmitter.subscribeOnKey(
|
|
113
|
+
pk,
|
|
114
|
+
list
|
|
115
|
+
);
|
|
116
|
+
listener.current = list;
|
|
117
|
+
return () => {
|
|
118
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKey(
|
|
119
|
+
pk,
|
|
120
|
+
list
|
|
121
|
+
);
|
|
122
|
+
};
|
|
123
|
+
}, [pk, reactiveCollection.updateEventEmitter, reactiveCollection]);
|
|
53
124
|
const getSnapshot = useMemo(() => () => snapshotValueRef.current, []);
|
|
54
|
-
const snapshot = useSyncExternalStore(
|
|
125
|
+
const snapshot = useSyncExternalStore(
|
|
126
|
+
listener.current,
|
|
127
|
+
getSnapshot,
|
|
128
|
+
getSnapshot
|
|
129
|
+
);
|
|
55
130
|
return snapshot;
|
|
56
131
|
};
|
|
57
132
|
var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
58
133
|
const snapshotValueRef = useRef(
|
|
59
134
|
pks.map((pk) => reactiveCollection.getOneByPk(pk))
|
|
60
135
|
);
|
|
61
|
-
const
|
|
62
|
-
|
|
136
|
+
const listener = useRef(
|
|
137
|
+
() => () => {
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const list = (onStoreChange) => {
|
|
63
142
|
snapshotValueRef.current = pks.map(
|
|
64
143
|
(pk) => reactiveCollection.getOneByPk(pk)
|
|
65
144
|
);
|
|
66
145
|
onStoreChange();
|
|
67
|
-
|
|
68
|
-
|
|
146
|
+
return () => {
|
|
147
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
148
|
+
pks,
|
|
149
|
+
list
|
|
150
|
+
);
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
reactiveCollection.updateEventEmitter.subscribeOnKeys(
|
|
154
|
+
pks,
|
|
155
|
+
list
|
|
156
|
+
);
|
|
157
|
+
listener.current = list;
|
|
158
|
+
return () => {
|
|
159
|
+
reactiveCollection.updateEventEmitter.unsubscribeFromKeys(
|
|
160
|
+
pks,
|
|
161
|
+
list
|
|
162
|
+
);
|
|
163
|
+
};
|
|
164
|
+
}, [pks, reactiveCollection.updateEventEmitter, reactiveCollection]);
|
|
69
165
|
const getSnapshot = useMemo(() => {
|
|
70
166
|
return () => {
|
|
71
167
|
return snapshotValueRef.current;
|
|
72
168
|
};
|
|
73
169
|
}, []);
|
|
74
|
-
const snapshot = useSyncExternalStore(
|
|
170
|
+
const snapshot = useSyncExternalStore(
|
|
171
|
+
listener.current,
|
|
172
|
+
getSnapshot,
|
|
173
|
+
getSnapshot
|
|
174
|
+
);
|
|
75
175
|
return snapshot;
|
|
76
176
|
};
|
|
77
177
|
var selectEntitiesByIndexKey = (reactiveCollection, reactiveIndex, key) => {
|