@oimdb/react 1.0.3 → 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 +132 -24
- package/dist/index.js +133 -25
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -38,67 +38,175 @@ var import_react = require("react");
|
|
|
38
38
|
var import_react2 = require("react");
|
|
39
39
|
var EMPTY_ARRAY = [];
|
|
40
40
|
var useSelectPksByIndexKeys = (reactiveIndex, keys) => {
|
|
41
|
-
const snapshotValueRef = (0, import_react.useRef)(
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
const snapshotValueRef = (0, import_react.useRef)(
|
|
42
|
+
keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat()
|
|
43
|
+
);
|
|
44
|
+
const listener = (0, import_react.useRef)(
|
|
45
|
+
() => () => {
|
|
46
|
+
}
|
|
47
|
+
);
|
|
48
|
+
(0, import_react.useEffect)(() => {
|
|
49
|
+
const list = (onStoreChange) => {
|
|
44
50
|
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
45
51
|
onStoreChange();
|
|
46
|
-
|
|
47
|
-
|
|
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]);
|
|
48
71
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
49
72
|
return () => {
|
|
50
73
|
return snapshotValueRef.current;
|
|
51
74
|
};
|
|
52
75
|
}, []);
|
|
53
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
76
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
77
|
+
listener.current,
|
|
78
|
+
getSnapshot,
|
|
79
|
+
getSnapshot
|
|
80
|
+
);
|
|
54
81
|
return snapshot;
|
|
55
82
|
};
|
|
56
83
|
var useSelectPksByIndexKey = (reactiveIndex, key) => {
|
|
57
|
-
const snapshotValueRef = (0, import_react.useRef)(
|
|
58
|
-
|
|
59
|
-
|
|
84
|
+
const snapshotValueRef = (0, import_react.useRef)(
|
|
85
|
+
Array.from(reactiveIndex.getPksByKey(key))
|
|
86
|
+
);
|
|
87
|
+
const listener = (0, import_react.useRef)(
|
|
88
|
+
() => () => {
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
(0, import_react.useEffect)(() => {
|
|
92
|
+
const list = (onStoreChange) => {
|
|
60
93
|
snapshotValueRef.current = Array.from(
|
|
61
94
|
reactiveIndex.getPksByKey(key)
|
|
62
95
|
);
|
|
63
96
|
onStoreChange();
|
|
64
|
-
|
|
65
|
-
|
|
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]);
|
|
66
116
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
67
117
|
return () => {
|
|
68
118
|
return snapshotValueRef.current;
|
|
69
119
|
};
|
|
70
120
|
}, []);
|
|
71
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
121
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
122
|
+
listener.current,
|
|
123
|
+
getSnapshot,
|
|
124
|
+
getSnapshot
|
|
125
|
+
);
|
|
72
126
|
return snapshot;
|
|
73
127
|
};
|
|
74
128
|
var selectEntityByPk = (reactiveCollection, pk) => {
|
|
75
|
-
const snapshotValueRef = (0, import_react.useRef)(
|
|
76
|
-
|
|
77
|
-
|
|
129
|
+
const snapshotValueRef = (0, import_react.useRef)(
|
|
130
|
+
reactiveCollection.getOneByPk(pk)
|
|
131
|
+
);
|
|
132
|
+
const listener = (0, import_react.useRef)(
|
|
133
|
+
() => () => {
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
(0, import_react.useEffect)(() => {
|
|
137
|
+
const list = (onStoreChange) => {
|
|
78
138
|
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
79
139
|
onStoreChange();
|
|
80
|
-
|
|
81
|
-
|
|
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]);
|
|
82
159
|
const getSnapshot = (0, import_react.useMemo)(() => () => snapshotValueRef.current, []);
|
|
83
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
160
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
161
|
+
listener.current,
|
|
162
|
+
getSnapshot,
|
|
163
|
+
getSnapshot
|
|
164
|
+
);
|
|
84
165
|
return snapshot;
|
|
85
166
|
};
|
|
86
167
|
var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
87
|
-
const snapshotValueRef = (0, import_react.useRef)(
|
|
88
|
-
|
|
89
|
-
|
|
168
|
+
const snapshotValueRef = (0, import_react.useRef)(
|
|
169
|
+
pks.map((pk) => reactiveCollection.getOneByPk(pk))
|
|
170
|
+
);
|
|
171
|
+
const listener = (0, import_react.useRef)(
|
|
172
|
+
() => () => {
|
|
173
|
+
}
|
|
174
|
+
);
|
|
175
|
+
(0, import_react.useEffect)(() => {
|
|
176
|
+
const list = (onStoreChange) => {
|
|
90
177
|
snapshotValueRef.current = pks.map(
|
|
91
178
|
(pk) => reactiveCollection.getOneByPk(pk)
|
|
92
179
|
);
|
|
93
180
|
onStoreChange();
|
|
94
|
-
|
|
95
|
-
|
|
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]);
|
|
96
200
|
const getSnapshot = (0, import_react.useMemo)(() => {
|
|
97
201
|
return () => {
|
|
98
202
|
return snapshotValueRef.current;
|
|
99
203
|
};
|
|
100
204
|
}, []);
|
|
101
|
-
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
205
|
+
const snapshot = (0, import_react2.useSyncExternalStore)(
|
|
206
|
+
listener.current,
|
|
207
|
+
getSnapshot,
|
|
208
|
+
getSnapshot
|
|
209
|
+
);
|
|
102
210
|
return snapshot;
|
|
103
211
|
};
|
|
104
212
|
var selectEntitiesByIndexKey = (reactiveCollection, reactiveIndex, key) => {
|
package/dist/index.js
CHANGED
|
@@ -1,69 +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
|
-
const snapshotValueRef = useRef(
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const snapshotValueRef = useRef(
|
|
7
|
+
keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat()
|
|
8
|
+
);
|
|
9
|
+
const listener = useRef(
|
|
10
|
+
() => () => {
|
|
11
|
+
}
|
|
12
|
+
);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
const list = (onStoreChange) => {
|
|
9
15
|
snapshotValueRef.current = keys.map((key) => Array.from(reactiveIndex.getPksByKey(key))).flat();
|
|
10
16
|
onStoreChange();
|
|
11
|
-
|
|
12
|
-
|
|
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]);
|
|
13
36
|
const getSnapshot = useMemo(() => {
|
|
14
37
|
return () => {
|
|
15
38
|
return snapshotValueRef.current;
|
|
16
39
|
};
|
|
17
40
|
}, []);
|
|
18
|
-
const snapshot = useSyncExternalStore(
|
|
41
|
+
const snapshot = useSyncExternalStore(
|
|
42
|
+
listener.current,
|
|
43
|
+
getSnapshot,
|
|
44
|
+
getSnapshot
|
|
45
|
+
);
|
|
19
46
|
return snapshot;
|
|
20
47
|
};
|
|
21
48
|
var useSelectPksByIndexKey = (reactiveIndex, key) => {
|
|
22
|
-
const snapshotValueRef = useRef(
|
|
23
|
-
|
|
24
|
-
|
|
49
|
+
const snapshotValueRef = useRef(
|
|
50
|
+
Array.from(reactiveIndex.getPksByKey(key))
|
|
51
|
+
);
|
|
52
|
+
const listener = useRef(
|
|
53
|
+
() => () => {
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
const list = (onStoreChange) => {
|
|
25
58
|
snapshotValueRef.current = Array.from(
|
|
26
59
|
reactiveIndex.getPksByKey(key)
|
|
27
60
|
);
|
|
28
61
|
onStoreChange();
|
|
29
|
-
|
|
30
|
-
|
|
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]);
|
|
31
81
|
const getSnapshot = useMemo(() => {
|
|
32
82
|
return () => {
|
|
33
83
|
return snapshotValueRef.current;
|
|
34
84
|
};
|
|
35
85
|
}, []);
|
|
36
|
-
const snapshot = useSyncExternalStore(
|
|
86
|
+
const snapshot = useSyncExternalStore(
|
|
87
|
+
listener.current,
|
|
88
|
+
getSnapshot,
|
|
89
|
+
getSnapshot
|
|
90
|
+
);
|
|
37
91
|
return snapshot;
|
|
38
92
|
};
|
|
39
93
|
var selectEntityByPk = (reactiveCollection, pk) => {
|
|
40
|
-
const snapshotValueRef = useRef(
|
|
41
|
-
|
|
42
|
-
|
|
94
|
+
const snapshotValueRef = useRef(
|
|
95
|
+
reactiveCollection.getOneByPk(pk)
|
|
96
|
+
);
|
|
97
|
+
const listener = useRef(
|
|
98
|
+
() => () => {
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
const list = (onStoreChange) => {
|
|
43
103
|
snapshotValueRef.current = reactiveCollection.getOneByPk(pk);
|
|
44
104
|
onStoreChange();
|
|
45
|
-
|
|
46
|
-
|
|
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]);
|
|
47
124
|
const getSnapshot = useMemo(() => () => snapshotValueRef.current, []);
|
|
48
|
-
const snapshot = useSyncExternalStore(
|
|
125
|
+
const snapshot = useSyncExternalStore(
|
|
126
|
+
listener.current,
|
|
127
|
+
getSnapshot,
|
|
128
|
+
getSnapshot
|
|
129
|
+
);
|
|
49
130
|
return snapshot;
|
|
50
131
|
};
|
|
51
132
|
var useSelectEntitiesByPks = (reactiveCollection, pks) => {
|
|
52
|
-
const snapshotValueRef = useRef(
|
|
53
|
-
|
|
54
|
-
|
|
133
|
+
const snapshotValueRef = useRef(
|
|
134
|
+
pks.map((pk) => reactiveCollection.getOneByPk(pk))
|
|
135
|
+
);
|
|
136
|
+
const listener = useRef(
|
|
137
|
+
() => () => {
|
|
138
|
+
}
|
|
139
|
+
);
|
|
140
|
+
useEffect(() => {
|
|
141
|
+
const list = (onStoreChange) => {
|
|
55
142
|
snapshotValueRef.current = pks.map(
|
|
56
143
|
(pk) => reactiveCollection.getOneByPk(pk)
|
|
57
144
|
);
|
|
58
145
|
onStoreChange();
|
|
59
|
-
|
|
60
|
-
|
|
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]);
|
|
61
165
|
const getSnapshot = useMemo(() => {
|
|
62
166
|
return () => {
|
|
63
167
|
return snapshotValueRef.current;
|
|
64
168
|
};
|
|
65
169
|
}, []);
|
|
66
|
-
const snapshot = useSyncExternalStore(
|
|
170
|
+
const snapshot = useSyncExternalStore(
|
|
171
|
+
listener.current,
|
|
172
|
+
getSnapshot,
|
|
173
|
+
getSnapshot
|
|
174
|
+
);
|
|
67
175
|
return snapshot;
|
|
68
176
|
};
|
|
69
177
|
var selectEntitiesByIndexKey = (reactiveCollection, reactiveIndex, key) => {
|