@oimdb/react 1.2.0 → 1.2.1

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
@@ -280,22 +280,20 @@ var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex,
280
280
  // src/context/index.tsx
281
281
  var import_react3 = require("react");
282
282
  var import_jsx_runtime = require("react/jsx-runtime");
283
- var OIMRICollectionsContext = (0, import_react3.createContext)(null);
283
+ var OIMRICollectionsContext = (0, import_react3.createContext)(
284
+ {}
285
+ );
284
286
  function createOIMCollectionsContext() {
285
- return (0, import_react3.createContext)(null);
287
+ return (0, import_react3.createContext)({});
286
288
  }
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 });
289
+ function OIMRICollectionsProvider({ collections, children, context }) {
290
+ const ContextToUse = context || OIMRICollectionsContext;
291
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ContextToUse.Provider, { value: collections, children });
294
292
  }
295
293
  function useOIMCollectionsContext(context) {
296
294
  const contextToUse = context || OIMRICollectionsContext;
297
295
  const collections = (0, import_react3.useContext)(contextToUse);
298
- if (!collections) {
296
+ if (!collections || Object.keys(collections).length === 0) {
299
297
  throw new Error(
300
298
  "useOIMCollectionsContext must be used within an OIMRICollectionsProvider"
301
299
  );
package/dist/index.d.cts CHANGED
@@ -14,21 +14,16 @@ declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk
14
14
  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
15
  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
16
 
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> {
17
+ type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
18
+ type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
19
+ declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
20
+ declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
21
+ interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
27
22
  collections: T;
28
23
  children: ReactNode;
29
24
  context?: React.Context<OIMContextValue<T>>;
30
25
  }
31
- declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context, }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
26
+ declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
32
27
  declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
33
28
 
34
29
  export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
package/dist/index.d.ts CHANGED
@@ -14,21 +14,16 @@ declare const useSelectEntitiesByIndexKeysSetBased: <TEntity extends object, TPk
14
14
  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
15
  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
16
 
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> {
17
+ type CollectionsDictionary = Record<string, OIMRICollection<any, any, any, any>>;
18
+ type OIMContextValue<T extends CollectionsDictionary = CollectionsDictionary> = T;
19
+ declare const OIMRICollectionsContext: React.Context<CollectionsDictionary>;
20
+ declare function createOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(): React.Context<OIMContextValue<T>>;
21
+ interface OIMRICollectionsProviderProps<T extends CollectionsDictionary = CollectionsDictionary> {
27
22
  collections: T;
28
23
  children: ReactNode;
29
24
  context?: React.Context<OIMContextValue<T>>;
30
25
  }
31
- declare function OIMRICollectionsProvider<T extends CollectionsDictionary>({ collections, children, context, }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
26
+ declare function OIMRICollectionsProvider<T extends CollectionsDictionary = CollectionsDictionary>({ collections, children, context }: OIMRICollectionsProviderProps<T>): react_jsx_runtime.JSX.Element;
32
27
  declare function useOIMCollectionsContext<T extends CollectionsDictionary = CollectionsDictionary>(context?: React.Context<OIMContextValue<T>>): T;
33
28
 
34
29
  export { type CollectionsDictionary, type OIMContextValue, OIMRICollectionsContext, OIMRICollectionsProvider, type OIMRICollectionsProviderProps, createOIMCollectionsContext, useOIMCollectionsContext, useSelectEntitiesByIndexKeyArrayBased, useSelectEntitiesByIndexKeySetBased, useSelectEntitiesByIndexKeysArrayBased, useSelectEntitiesByIndexKeysSetBased, useSelectEntitiesByPks, useSelectEntityByPk, useSelectPksByIndexKeyArrayBased, useSelectPksByIndexKeySetBased, useSelectPksByIndexKeysArrayBased, useSelectPksByIndexKeysSetBased };
package/dist/index.js CHANGED
@@ -241,22 +241,20 @@ var useSelectEntitiesByIndexKeysArrayBased = (reactiveCollection, reactiveIndex,
241
241
  // src/context/index.tsx
242
242
  import { createContext, useContext } from "react";
243
243
  import { jsx } from "react/jsx-runtime";
244
- var OIMRICollectionsContext = createContext(null);
244
+ var OIMRICollectionsContext = createContext(
245
+ {}
246
+ );
245
247
  function createOIMCollectionsContext() {
246
- return createContext(null);
248
+ return createContext({});
247
249
  }
248
- function OIMRICollectionsProvider({
249
- collections,
250
- children,
251
- context = OIMRICollectionsContext
252
- }) {
253
- const Provider = context.Provider;
254
- return /* @__PURE__ */ jsx(Provider, { value: collections, children });
250
+ function OIMRICollectionsProvider({ collections, children, context }) {
251
+ const ContextToUse = context || OIMRICollectionsContext;
252
+ return /* @__PURE__ */ jsx(ContextToUse.Provider, { value: collections, children });
255
253
  }
256
254
  function useOIMCollectionsContext(context) {
257
255
  const contextToUse = context || OIMRICollectionsContext;
258
256
  const collections = useContext(contextToUse);
259
- if (!collections) {
257
+ if (!collections || Object.keys(collections).length === 0) {
260
258
  throw new Error(
261
259
  "useOIMCollectionsContext must be used within an OIMRICollectionsProvider"
262
260
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oimdb/react",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
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.3.1",
37
37
  "react": "^18.0.0"
38
38
  },
39
39
  "devDependencies": {