@dr.pogodin/react-global-state 0.23.0 → 0.24.0

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.
@@ -3,27 +3,25 @@ import GlobalState from './GlobalState';
3
3
  import type SsrContext from './SsrContext';
4
4
  import type { ValueOrInitializerT } from './utils';
5
5
  /**
6
- * Gets {@link GlobalState} instance from the context. In most cases
7
- * you should use {@link useGlobalState}, and other hooks to interact with
8
- * the global state, instead of accessing it directly.
9
- * @return
6
+ * Returns the GlobalState object from the context. In most cases you should use
7
+ * other hooks, like useGlobalState(), etc. to interact with the global state,
8
+ * instead of accessing the GlobalState object directly.
10
9
  */
11
- export declare function getGlobalState<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>(): GlobalState<StateT, SsrContextT>;
10
+ export declare function useGlobalStateObject<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>(): GlobalState<StateT, SsrContextT>;
12
11
  /**
13
- * @category Hooks
14
- * @desc Gets SSR context.
15
- * @param throwWithoutSsrContext If `true` (default),
16
- * this hook will throw if no SSR context is attached to the global state;
17
- * set `false` to not throw in such case. In either case the hook will throw
18
- * if the {@link &lt;GlobalStateProvider&gt;} (hence the state) is missing.
12
+ * Returns SSR context.
13
+ * @param throwWithoutSsrContext - If _true_ (default), this hook will throw
14
+ * if no SSR context is attached to the global state; set _false_ to not throw
15
+ * in such case. In either case this hook will throw if the <GlobalStateProvider>
16
+ * (hence the global state) is missing.
19
17
  * @returns SSR context.
20
18
  * @throws
21
- * - If current component has no parent {@link &lt;GlobalStateProvider&gt;}
22
- * in the rendered React tree.
23
- * - If `throwWithoutSsrContext` is `true`, and there is no SSR context attached
24
- * to the global state provided by {@link &lt;GlobalStateProvider&gt;}.
19
+ * - If current component has no parent <GlobalStateProvider> in the rendered
20
+ * React tree.
21
+ * - If `throwWithoutSsrContext` is _true_ (default), and there is no SSR
22
+ * context attached to the global state provided by <GlobalStateProvider>.
25
23
  */
26
- export declare function getSsrContext<SsrContextT extends SsrContext<unknown>>(throwWithoutSsrContext?: boolean): SsrContextT | undefined;
24
+ export declare function useSsrContext<SsrContextT extends SsrContext<unknown>>(throwWithoutSsrContext?: boolean): SsrContextT | undefined;
27
25
  type NewStateProps<StateT, SsrContextT extends SsrContext<StateT>> = {
28
26
  initialState: ValueOrInitializerT<StateT>;
29
27
  ssrContext?: SsrContextT;
@@ -1,5 +1,5 @@
1
1
  import GlobalState from './GlobalState';
2
- import GlobalStateProvider, { getGlobalState, getSsrContext } from './GlobalStateProvider';
2
+ import GlobalStateProvider, { useGlobalStateObject, useSsrContext } from './GlobalStateProvider';
3
3
  import SsrContext from './SsrContext';
4
4
  import useAsyncCollection, { type UseAsyncCollectionI, type UseAsyncCollectionResT } from './useAsyncCollection';
5
5
  import { type AsyncDataEnvelopeT, type AsyncDataLoaderT, type AsyncDataReloaderT, type LoadAsyncDataI, type UseAsyncDataI, type UseAsyncDataOptionsT, type UseAsyncDataResT, loadAsyncData, newAsyncDataEnvelope, useAsyncData } from './useAsyncData';
@@ -7,17 +7,17 @@ import useGlobalState, { type UseGlobalStateI } from './useGlobalState';
7
7
  export type { AsyncCollectionLoaderT, AsyncCollectionReloaderT, AsyncCollectionT, } from './useAsyncCollection';
8
8
  export type { SetterT, UseGlobalStateResT } from './useGlobalState';
9
9
  export type { ForceT, ValueOrInitializerT } from './utils';
10
- export { type AsyncDataEnvelopeT, type AsyncDataLoaderT, type AsyncDataReloaderT, GlobalState, GlobalStateProvider, SsrContext, type UseAsyncCollectionI, type UseAsyncCollectionResT, type UseAsyncDataI, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateI, getGlobalState, getSsrContext, loadAsyncData, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, };
10
+ export { type AsyncDataEnvelopeT, type AsyncDataLoaderT, type AsyncDataReloaderT, GlobalState, GlobalStateProvider, SsrContext, type UseAsyncCollectionI, type UseAsyncCollectionResT, type UseAsyncDataI, type UseAsyncDataOptionsT, type UseAsyncDataResT, type UseGlobalStateI, loadAsyncData, newAsyncDataEnvelope, useAsyncCollection, useAsyncData, useGlobalState, useGlobalStateObject, useSsrContext, };
11
11
  interface API<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>> {
12
12
  GlobalState: typeof GlobalState<StateT, SsrContextT>;
13
13
  GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>;
14
14
  SsrContext: typeof SsrContext<StateT>;
15
- getGlobalState: typeof getGlobalState<StateT, SsrContextT>;
16
- getSsrContext: typeof getSsrContext<SsrContextT>;
17
15
  loadAsyncData: LoadAsyncDataI<StateT>;
18
16
  newAsyncDataEnvelope: typeof newAsyncDataEnvelope;
19
17
  useAsyncCollection: UseAsyncCollectionI<StateT>;
20
18
  useAsyncData: UseAsyncDataI<StateT>;
21
19
  useGlobalState: UseGlobalStateI<StateT>;
20
+ useGlobalStateObject: typeof useGlobalStateObject<StateT, SsrContextT>;
21
+ useSsrContext: typeof useSsrContext<SsrContextT>;
22
22
  }
23
23
  export declare function withGlobalStateType<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>(): API<StateT, SsrContextT>;
@@ -1,4 +1,5 @@
1
1
  import type { GetFieldType } from 'lodash';
2
+ import type { ObjectKey } from '@dr.pogodin/js-utils';
2
3
  export type CallbackT = () => void;
3
4
  export declare const force: unique symbol;
4
5
  export declare const lock: unique symbol;
@@ -40,17 +41,4 @@ export declare function isDebugMode(): boolean;
40
41
  * development versions of the app due to the logging overhead).
41
42
  */
42
43
  export declare function cloneDeepForLog<T>(value: T, key?: string): T;
43
- /**
44
- * Converts given value to an escaped string. For now, we are good with the most
45
- * trivial escape logic:
46
- * - '%' characters are replaced by '%0' code pair;
47
- * - '/' characters are replaced by '%1' code pair.
48
- */
49
- export declare function escape(x: number | string): string;
50
- /**
51
- * Hashes given string array. For our current needs we are fine to go with
52
- * the most trivial implementation, which probably should not be called "hash"
53
- * in the strict sense: we just escape each given string to not include '/'
54
- * characters, and then we join all those strings using '/' as the separator.
55
- */
56
- export declare function hash(items: Array<number | string>): string;
44
+ export declare function areEqual<K extends ObjectKey>(a: Record<K, boolean>, b: Record<K, boolean>): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dr.pogodin/react-global-state",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Hook-based global state for React",
5
5
  "main": "./build/code/index.js",
6
6
  "types": "./build/types/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "jest": "npm run jest:types && npm run jest:logic",
16
16
  "jest:logic": "jest --config jest/config.json -w 1 --no-cache",
17
17
  "jest:types": "tstyche",
18
- "lint": "eslint --cache",
18
+ "lint": "eslint --cache --cache-strategy content",
19
19
  "test": "npm run lint && npm run typecheck && npm run jest",
20
20
  "typecheck": "tsc --noEmit"
21
21
  },
@@ -36,43 +36,45 @@
36
36
  },
37
37
  "homepage": "https://dr.pogodin.studio/docs/react-global-state/index.html",
38
38
  "engines": {
39
- "node": ">=20"
39
+ "node": ">=22"
40
40
  },
41
41
  "dependencies": {
42
- "@babel/runtime": "^7.29.2",
43
- "@dr.pogodin/js-utils": "^0.1.6",
42
+ "@babel/runtime": "^7.29.7",
43
+ "@dr.pogodin/js-utils": "^0.1.8",
44
44
  "@types/lodash": "^4.17.24",
45
45
  "lodash-es": "^4.18.1"
46
46
  },
47
47
  "devDependencies": {
48
- "@babel/cli": "^7.28.6",
49
- "@babel/core": "^7.29.0",
50
- "@babel/node": "^7.29.0",
51
- "@babel/plugin-transform-runtime": "^7.29.0",
52
- "@babel/preset-env": "^7.29.2",
53
- "@babel/preset-react": "^7.28.5",
54
- "@babel/preset-typescript": "^7.28.5",
55
- "@dr.pogodin/eslint-configs": "^0.2.10",
48
+ "@babel/cli": "^7.29.7",
49
+ "@babel/core": "^7.29.7",
50
+ "@babel/node": "^7.29.7",
51
+ "@babel/plugin-transform-runtime": "^7.29.7",
52
+ "@babel/preset-env": "^7.29.7",
53
+ "@babel/preset-react": "^7.29.7",
54
+ "@babel/preset-typescript": "^7.29.7",
55
+ "@dr.pogodin/eslint-configs": "^0.2.14",
56
+ "@jest/globals": "^30.4.1",
56
57
  "@testing-library/dom": "^10.4.1",
57
58
  "@testing-library/react": "^16.3.2",
58
59
  "@tsconfig/recommended": "^1.0.13",
59
60
  "@types/jest": "^30.0.0",
60
61
  "@types/lodash-es": "^4.17.12",
61
62
  "@types/pretty": "^2.0.3",
62
- "@types/react": "^19.2.14",
63
+ "@types/react": "^19.2.17",
63
64
  "@types/react-dom": "^19.2.3",
64
- "babel-jest": "^30.3.0",
65
+ "babel-jest": "^30.4.1",
65
66
  "babel-plugin-add-import-extension": "^1.6.0",
66
67
  "babel-plugin-module-resolver": "^5.0.3",
67
- "jest": "^30.3.0",
68
- "jest-environment-jsdom": "^30.3.0",
68
+ "babel-plugin-react-compiler": "^1.0.0",
69
+ "jest": "^30.4.2",
70
+ "jest-environment-jsdom": "^30.4.1",
69
71
  "mockdate": "^3.0.5",
70
72
  "rimraf": "^6.1.3",
71
- "tstyche": "^7.0.0",
73
+ "tstyche": "^7.2.1",
72
74
  "typescript": "^5.9.3"
73
75
  },
74
76
  "peerDependencies": {
75
- "react": "^19.2.5",
76
- "react-dom": "^19.2.5"
77
+ "react": "^19.2.7",
78
+ "react-dom": "^19.2.7"
77
79
  }
78
80
  }
package/tsconfig.json CHANGED
@@ -10,12 +10,13 @@
10
10
  "declaration": true,
11
11
  "jsx": "react-jsx",
12
12
  "module": "ESNext",
13
- "moduleResolution": "Node",
13
+ "moduleResolution": "bundler",
14
14
  "noUncheckedIndexedAccess": true,
15
15
  "outDir": "build",
16
16
  "paths": {
17
17
  "*": ["./*"]
18
18
  },
19
+ "types": ["node"],
19
20
  "verbatimModuleSyntax": true
20
21
  }
21
- }
22
+ }