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