@oimdb/react 1.2.0 → 1.2.2

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 CHANGED
@@ -33,7 +33,9 @@ __export(index_exports, {
33
33
  useSelectPksByIndexKeyArrayBased: () => useSelectPksByIndexKeyArrayBased,
34
34
  useSelectPksByIndexKeySetBased: () => useSelectPksByIndexKeySetBased,
35
35
  useSelectPksByIndexKeysArrayBased: () => useSelectPksByIndexKeysArrayBased,
36
- useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased
36
+ useSelectPksByIndexKeysSetBased: () => useSelectPksByIndexKeysSetBased,
37
+ useSelectValueByObjectKey: () => useSelectValueByObjectKey,
38
+ useSelectValuesByObjectKeys: () => useSelectValuesByObjectKeys
37
39
  });
38
40
  module.exports = __toCommonJS(index_exports);
39
41
 
@@ -200,6 +202,69 @@ var useSelectEntityByPk = (reactiveCollection, pk) => {
200
202
  const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
201
203
  return snapshot;
202
204
  };
205
+ var useSelectValueByObjectKey = (reactiveObject, key) => {
206
+ const getSnapshot = (0, import_react.useMemo)(
207
+ () => () => reactiveObject.get(key),
208
+ [key, reactiveObject]
209
+ );
210
+ const subscribe = (0, import_react.useMemo)(() => {
211
+ return (onStoreChange) => {
212
+ reactiveObject.updateEventEmitter.subscribeOnKey(
213
+ key,
214
+ onStoreChange
215
+ );
216
+ return () => {
217
+ reactiveObject.updateEventEmitter.unsubscribeFromKey(
218
+ key,
219
+ onStoreChange
220
+ );
221
+ };
222
+ };
223
+ }, [key, reactiveObject.updateEventEmitter]);
224
+ const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
225
+ return snapshot;
226
+ };
227
+ var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
228
+ const prevKeysRef = (0, import_react.useRef)();
229
+ const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
230
+ if (!keysAreEqual) {
231
+ prevKeysRef.current = keys;
232
+ }
233
+ const snapshotRef = (0, import_react.useRef)();
234
+ const subscribe = (0, import_react.useMemo)(() => {
235
+ snapshotRef.current = keys.map((key) => reactiveObject.get(key));
236
+ return (onStoreChange) => {
237
+ const prevKeys = prevKeysRef.current;
238
+ if (!prevKeys) {
239
+ return () => {
240
+ };
241
+ }
242
+ const updateSnapshot = () => {
243
+ snapshotRef.current = prevKeys.map(
244
+ (key) => reactiveObject.get(key)
245
+ );
246
+ onStoreChange();
247
+ };
248
+ reactiveObject.updateEventEmitter.subscribeOnKeys(
249
+ prevKeys,
250
+ updateSnapshot
251
+ );
252
+ return () => {
253
+ reactiveObject.updateEventEmitter.unsubscribeFromKeys(
254
+ prevKeys,
255
+ updateSnapshot
256
+ );
257
+ };
258
+ };
259
+ }, [prevKeysRef.current, reactiveObject.updateEventEmitter]);
260
+ const getSnapshot = (0, import_react.useMemo)(() => {
261
+ return () => {
262
+ return snapshotRef.current;
263
+ };
264
+ }, []);
265
+ const snapshot = (0, import_react2.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
266
+ return snapshot;
267
+ };
203
268
  function arraysEqual(a, b) {
204
269
  if (a === b) return true;
205
270
  if (a.length !== b.length) return false;
@@ -280,22 +345,20 @@ var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex,
280
345
  // src/context/index.tsx
281
346
  var import_react3 = require("react");
282
347
  var import_jsx_runtime = require("react/jsx-runtime");
283
- var OIMRICollectionsContext = (0, import_react3.createContext)(null);
348
+ var OIMRICollectionsContext = (0, import_react3.createContext)(
349
+ {}
350
+ );
284
351
  function createOIMCollectionsContext() {
285
- return (0, import_react3.createContext)(null);
352
+ return (0, import_react3.createContext)({});
286
353
  }
287
- function OIMRICollectionsProvider({
288
- collections,
289
- children,
290
- context = OIMRICollectionsContext
291
- }) {
292
- const Provider = context.Provider;
293
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Provider, { value: collections, children });
354
+ function OIMRICollectionsProvider({ collections, children, context }) {
355
+ const ContextToUse = context || OIMRICollectionsContext;
356
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextToUse.Provider, { value: collections, children });
294
357
  }
295
358
  function useOIMCollectionsContext(context) {
296
359
  const contextToUse = context || OIMRICollectionsContext;
297
360
  const collections = (0, import_react3.useContext)(contextToUse);
298
- if (!collections) {
361
+ if (!collections || Object.keys(collections).length === 0) {
299
362
  throw new Error(
300
363
  "useOIMCollectionsContext must be used within an OIMRICollectionsProvider"
301
364
  );
@@ -317,5 +380,7 @@ function useOIMCollectionsContext(context) {
317
380
  useSelectPksByIndexKeyArrayBased,
318
381
  useSelectPksByIndexKeySetBased,
319
382
  useSelectPksByIndexKeysArrayBased,
320
- useSelectPksByIndexKeysSetBased
383
+ useSelectPksByIndexKeysSetBased,
384
+ useSelectValueByObjectKey,
385
+ useSelectValuesByObjectKeys
321
386
  });
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMRICollection } from '@oimdb/core';
1
+ import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject, OIMRICollection } from '@oimdb/core';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
4
  import { ReactNode } from 'react';
@@ -8,27 +8,24 @@ declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends
8
8
  declare const useSelectPksByIndexKeysArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
9
9
  declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
10
10
  declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
11
+ declare const useSelectValueByObjectKey: <TKey extends string, TValue>(reactiveObject: OIMReactiveObject<TKey, TValue>, key: TKey) => TValue | undefined;
12
+ declare const useSelectValuesByObjectKeys: <TKey extends string, TValue>(reactiveObject: OIMReactiveObject<TKey, TValue>, keys: readonly TKey[]) => readonly (TValue | undefined)[] | undefined;
11
13
  declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly (TEntity | undefined)[] | undefined;
12
14
  declare const useSelectEntitiesByIndexKeySetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
13
15
  declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
14
16
  declare const useSelectEntitiesByIndexKeyArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
15
17
  declare const useSelectEntitiesByIndexKeysArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
16
18
 
17
- type TOIMAnyIndexSetBased = OIMIndexSetBased<TOIMPk, TOIMPk>;
18
- type TOIMAnyIndexArrayBased = OIMIndexArrayBased<TOIMPk, TOIMPk>;
19
- type TOIMAnyReactiveIndexSetBased = OIMReactiveIndexSetBased<TOIMPk, TOIMPk, TOIMAnyIndexSetBased>;
20
- type TOIMAnyReactiveIndexArrayBased = OIMReactiveIndexArrayBased<TOIMPk, TOIMPk, TOIMAnyIndexArrayBased>;
21
- type TOIMAnyReactiveIndex = TOIMAnyReactiveIndexSetBased | TOIMAnyReactiveIndexArrayBased;
22
- type CollectionsDictionary = Record<string, OIMRICollection<object, TOIMPk, string, TOIMPk, TOIMAnyReactiveIndex>>;
23
- type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T | null;
24
- declare const OIMRICollectionsContext: React.Context<OIMContextValue<CollectionsDictionary>>;
25
- declare function createOIMCollectionsContext<T extends CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
26
- interface OIMRICollectionsProviderProps<T extends CollectionsDictionary> {
19
+ type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
20
+ type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
21
+ declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
22
+ declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
23
+ interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
27
24
  collections: T;
28
25
  children: ReactNode;
29
26
  context?: React.Context<OIMContextValue<T>>;
30
27
  }
31
- declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context, }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
28
+ declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
32
29
  declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
33
30
 
34
- export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
31
+ export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased, useSelectValueByObjectKey, useSelectValuesByObjectKeys };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMRICollection } from '@oimdb/core';
1
+ import { TOIMPk, OIMIndexSetBased, OIMReactiveIndexSetBased, OIMIndexArrayBased, OIMReactiveIndexArrayBased, OIMReactiveCollection, OIMReactiveObject, OIMRICollection } from '@oimdb/core';
2
2
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
4
  import { ReactNode } from 'react';
@@ -8,27 +8,24 @@ declare const useSelectPksByIndexKeySetBased: <TPk extends TOIMPk, TKey extends
8
8
  declare const useSelectPksByIndexKeysArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => TPk[] | undefined;
9
9
  declare const useSelectPksByIndexKeyArrayBased: <TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => TPk[] | undefined;
10
10
  declare const useSelectEntityByPk: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pk: TPk) => TEntity | undefined;
11
+ declare const useSelectValueByObjectKey: <TKey extends string, TValue>(reactiveObject: OIMReactiveObject<TKey, TValue>, key: TKey) => TValue | undefined;
12
+ declare const useSelectValuesByObjectKeys: <TKey extends string, TValue>(reactiveObject: OIMReactiveObject<TKey, TValue>, keys: readonly TKey[]) => readonly (TValue | undefined)[] | undefined;
11
13
  declare const useSelectEntitiesByPks: <TEntity extends object, TPk extends TOIMPk>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, pks: readonly TPk[]) => readonly (TEntity | undefined)[] | undefined;
12
14
  declare const useSelectEntitiesByIndexKeySetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
13
15
  declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexSetBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexSetBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
14
16
  declare const useSelectEntitiesByIndexKeyArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, key: TKey) => readonly (TEntity | undefined)[] | undefined;
15
17
  declare const useSelectEntitiesByIndexKeysArrayBased: <TEntity extends object, TPk extends TOIMPk, TKey extends TOIMPk, TIndex extends OIMIndexArrayBased<TKey, TPk>>(reactiveCollection: OIMReactiveCollection<TEntity, TPk>, reactiveIndex: OIMReactiveIndexArrayBased<TKey, TPk, TIndex>, keys: readonly TKey[]) => readonly (TEntity | undefined)[] | undefined;
16
18
 
17
- type TOIMAnyIndexSetBased = OIMIndexSetBased<TOIMPk, TOIMPk>;
18
- type TOIMAnyIndexArrayBased = OIMIndexArrayBased<TOIMPk, TOIMPk>;
19
- type TOIMAnyReactiveIndexSetBased = OIMReactiveIndexSetBased<TOIMPk, TOIMPk, TOIMAnyIndexSetBased>;
20
- type TOIMAnyReactiveIndexArrayBased = OIMReactiveIndexArrayBased<TOIMPk, TOIMPk, TOIMAnyIndexArrayBased>;
21
- type TOIMAnyReactiveIndex = TOIMAnyReactiveIndexSetBased | TOIMAnyReactiveIndexArrayBased;
22
- type CollectionsDictionary = Record<string, OIMRICollection<object, TOIMPk, string, TOIMPk, TOIMAnyReactiveIndex>>;
23
- type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T | null;
24
- declare const OIMRICollectionsContext: React.Context<OIMContextValue<CollectionsDictionary>>;
25
- declare function createOIMCollectionsContext<T extends CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
26
- interface OIMRICollectionsProviderProps<T extends CollectionsDictionary> {
19
+ type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
20
+ type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
21
+ declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
22
+ declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
23
+ interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
27
24
  collections: T;
28
25
  children: ReactNode;
29
26
  context?: React.Context<OIMContextValue<T>>;
30
27
  }
31
- declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context, }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
28
+ declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
32
29
  declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
33
30
 
34
- export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
31
+ export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased, useSelectValueByObjectKey, useSelectValuesByObjectKeys };
package/dist/index.js CHANGED
@@ -161,6 +161,69 @@ var useSelectEntityByPk = (reactiveCollection, pk) => {
161
161
  const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
162
162
  return snapshot;
163
163
  };
164
+ var useSelectValueByObjectKey = (reactiveObject, key) => {
165
+ const getSnapshot = useMemo(
166
+ () => () => reactiveObject.get(key),
167
+ [key, reactiveObject]
168
+ );
169
+ const subscribe = useMemo(() => {
170
+ return (onStoreChange) => {
171
+ reactiveObject.updateEventEmitter.subscribeOnKey(
172
+ key,
173
+ onStoreChange
174
+ );
175
+ return () => {
176
+ reactiveObject.updateEventEmitter.unsubscribeFromKey(
177
+ key,
178
+ onStoreChange
179
+ );
180
+ };
181
+ };
182
+ }, [key, reactiveObject.updateEventEmitter]);
183
+ const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
184
+ return snapshot;
185
+ };
186
+ var useSelectValuesByObjectKeys = (reactiveObject, keys) => {
187
+ const prevKeysRef = useRef();
188
+ const keysAreEqual = arraysEqual(prevKeysRef.current || EMPTY_ARRAY, keys);
189
+ if (!keysAreEqual) {
190
+ prevKeysRef.current = keys;
191
+ }
192
+ const snapshotRef = useRef();
193
+ const subscribe = useMemo(() => {
194
+ snapshotRef.current = keys.map((key) => reactiveObject.get(key));
195
+ return (onStoreChange) => {
196
+ const prevKeys = prevKeysRef.current;
197
+ if (!prevKeys) {
198
+ return () => {
199
+ };
200
+ }
201
+ const updateSnapshot = () => {
202
+ snapshotRef.current = prevKeys.map(
203
+ (key) => reactiveObject.get(key)
204
+ );
205
+ onStoreChange();
206
+ };
207
+ reactiveObject.updateEventEmitter.subscribeOnKeys(
208
+ prevKeys,
209
+ updateSnapshot
210
+ );
211
+ return () => {
212
+ reactiveObject.updateEventEmitter.unsubscribeFromKeys(
213
+ prevKeys,
214
+ updateSnapshot
215
+ );
216
+ };
217
+ };
218
+ }, [prevKeysRef.current, reactiveObject.updateEventEmitter]);
219
+ const getSnapshot = useMemo(() => {
220
+ return () => {
221
+ return snapshotRef.current;
222
+ };
223
+ }, []);
224
+ const snapshot = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
225
+ return snapshot;
226
+ };
164
227
  function arraysEqual(a, b) {
165
228
  if (a === b) return true;
166
229
  if (a.length !== b.length) return false;
@@ -241,22 +304,20 @@ var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex,
241
304
  // src/context/index.tsx
242
305
  import { createContext, useContext } from "react";
243
306
  import { jsx } from "react/jsx-runtime";
244
- var OIMRICollectionsContext = createContext(null);
307
+ var OIMRICollectionsContext = createContext(
308
+ {}
309
+ );
245
310
  function createOIMCollectionsContext() {
246
- return createContext(null);
311
+ return createContext({});
247
312
  }
248
- function OIMRICollectionsProvider({
249
- collections,
250
- children,
251
- context = OIMRICollectionsContext
252
- }) {
253
- const Provider = context.Provider;
254
- return /* @__PURE__ */ jsx(Provider, { value: collections, children });
313
+ function OIMRICollectionsProvider({ collections, children, context }) {
314
+ const ContextToUse = context || OIMRICollectionsContext;
315
+ return /* @__PURE__ */ jsx(ContextToUse.Provider, { value: collections, children });
255
316
  }
256
317
  function useOIMCollectionsContext(context) {
257
318
  const contextToUse = context || OIMRICollectionsContext;
258
319
  const collections = useContext(contextToUse);
259
- if (!collections) {
320
+ if (!collections || Object.keys(collections).length === 0) {
260
321
  throw new Error(
261
322
  "useOIMCollectionsContext must be used within an OIMRICollectionsProvider"
262
323
  );
@@ -277,5 +338,7 @@ export {
277
338
  useSelectPksByIndexKeyArrayBased,
278
339
  useSelectPksByIndexKeySetBased,
279
340
  useSelectPksByIndexKeysArrayBased,
280
- useSelectPksByIndexKeysSetBased
341
+ useSelectPksByIndexKeysSetBased,
342
+ useSelectValueByObjectKey,
343
+ useSelectValuesByObjectKeys
281
344
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oimdb/react",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "React integration for OIMDB - Hooks for selection and subscription with external storage",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,7 +33,7 @@
33
33
  "dist"
34
34
  ],
35
35
  "peerDependencies": {
36
- "@oimdb/core": "^1.3.0",
36
+ "@oimdb/core": "^1.4.0",
37
37
  "react": "^18.0.0"
38
38
  },
39
39
  "devDependencies": {