@dr.pogodin/react-global-state 0.18.0 → 0.19.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.
Files changed (57) hide show
  1. package/LICENSE.md +1 -1
  2. package/build/{module → code}/GlobalState.js +15 -5
  3. package/build/code/GlobalState.js.map +1 -0
  4. package/build/{module → code}/GlobalStateProvider.js +18 -18
  5. package/build/code/GlobalStateProvider.js.map +1 -0
  6. package/build/code/SsrContext.js.map +1 -0
  7. package/build/{module → code}/index.js +9 -3
  8. package/build/code/index.js.map +1 -0
  9. package/build/{module → code}/useAsyncCollection.js +60 -27
  10. package/build/code/useAsyncCollection.js.map +1 -0
  11. package/build/{module → code}/useAsyncData.js +19 -17
  12. package/build/code/useAsyncData.js.map +1 -0
  13. package/build/{module → code}/useGlobalState.js +25 -8
  14. package/build/code/useGlobalState.js.map +1 -0
  15. package/build/{module → code}/utils.js +1 -1
  16. package/build/code/utils.js.map +1 -0
  17. package/build/types/GlobalState.d.ts +2 -2
  18. package/build/types/GlobalStateProvider.d.ts +3 -3
  19. package/build/types/SsrContext.d.ts +3 -3
  20. package/build/types/useAsyncCollection.d.ts +4 -6
  21. package/build/types/useAsyncData.d.ts +2 -2
  22. package/build/types/utils.d.ts +2 -3
  23. package/eslint.config.mjs +19 -0
  24. package/package.json +25 -41
  25. package/build/common/GlobalState.js +0 -279
  26. package/build/common/GlobalState.js.map +0 -1
  27. package/build/common/GlobalStateProvider.js +0 -97
  28. package/build/common/GlobalStateProvider.js.map +0 -1
  29. package/build/common/SsrContext.js +0 -15
  30. package/build/common/SsrContext.js.map +0 -1
  31. package/build/common/index.js +0 -84
  32. package/build/common/index.js.map +0 -1
  33. package/build/common/useAsyncCollection.js +0 -242
  34. package/build/common/useAsyncCollection.js.map +0 -1
  35. package/build/common/useAsyncData.js +0 -233
  36. package/build/common/useAsyncData.js.map +0 -1
  37. package/build/common/useGlobalState.js +0 -134
  38. package/build/common/useGlobalState.js.map +0 -1
  39. package/build/common/utils.js +0 -91
  40. package/build/common/utils.js.map +0 -1
  41. package/build/module/GlobalState.js.map +0 -1
  42. package/build/module/GlobalStateProvider.js.map +0 -1
  43. package/build/module/SsrContext.js.map +0 -1
  44. package/build/module/index.js.map +0 -1
  45. package/build/module/useAsyncCollection.js.map +0 -1
  46. package/build/module/useAsyncData.js.map +0 -1
  47. package/build/module/useGlobalState.js.map +0 -1
  48. package/build/module/utils.js.map +0 -1
  49. package/src/GlobalState.ts +0 -342
  50. package/src/GlobalStateProvider.tsx +0 -117
  51. package/src/SsrContext.ts +0 -11
  52. package/src/index.ts +0 -84
  53. package/src/useAsyncCollection.ts +0 -471
  54. package/src/useAsyncData.ts +0 -362
  55. package/src/useGlobalState.ts +0 -225
  56. package/src/utils.ts +0 -116
  57. /package/build/{module → code}/SsrContext.js +0 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAsyncData.js","names":["useEffect","useRef","v4","uuid","MIN_MS","getGlobalState","useGlobalState","cloneDeepForLog","isDebugMode","DEFAULT_MAXAGE","newAsyncDataEnvelope","initialData","arguments","length","undefined","numRefs","timestamp","data","operationId","load","path","loader","globalState","old","process","env","NODE_ENV","console","log","operationIdPath","prevOperationId","get","asyncDataLoadDone","set","definedOld","e","dataOrPromise","isAborted","opid","oldDataTimestamp","setAbortCallback","cb","Error","setAsyncDataAbortCallback","Promise","state","groupCollapsed","Date","now","groupEnd","useAsyncData","_options$maxage","_options$refreshAge","_options$garbageColle","_heap$reload","options","maxage","refreshAge","garbageCollectAge","initialValue","current","heap","reload","customLoader","localLoader","ssrContext","disabled","noSSR","pending","push","numRefsPath","state2","dropDependencies","deps","hasChangedDependencies","startsWith","localState","loading","Boolean"],"sources":["../../src/useAsyncData.ts"],"sourcesContent":["/**\n * Loads and uses async data into the GlobalState path.\n */\n\nimport { useEffect, useRef } from 'react';\nimport { v4 as uuid } from 'uuid';\n\nimport { MIN_MS } from '@dr.pogodin/js-utils';\n\nimport { getGlobalState } from './GlobalStateProvider';\nimport useGlobalState from './useGlobalState';\n\nimport {\n type ForceT,\n type LockT,\n type TypeLock,\n type ValueAtPathT,\n cloneDeepForLog,\n isDebugMode,\n} from './utils';\n\nimport type GlobalState from './GlobalState';\nimport type SsrContext from './SsrContext';\n\nexport const DEFAULT_MAXAGE = 5 * MIN_MS; // 5 minutes.\n\nexport type AsyncDataLoaderT<DataT>\n= (oldData: null | DataT, meta: {\n isAborted: () => boolean;\n oldDataTimestamp: number;\n setAbortCallback: (cb: () => void) => void;\n}) => DataT | Promise<DataT | null> | null;\n\nexport type AsyncDataReloaderT<DataT>\n= (loader?: AsyncDataLoaderT<DataT>) => Promise<void>;\n\nexport type AsyncDataEnvelopeT<DataT> = {\n data: null | DataT;\n numRefs: number;\n operationId: string;\n timestamp: number;\n};\n\nexport type OperationIdT = `${'C' | 'S'}${string}`;\n\nexport function newAsyncDataEnvelope<DataT>(\n initialData: DataT | null = null,\n { numRefs = 0, timestamp = 0 } = {},\n): AsyncDataEnvelopeT<DataT> {\n return {\n data: initialData,\n numRefs,\n operationId: '',\n timestamp,\n };\n}\n\nexport type UseAsyncDataOptionsT = {\n deps?: unknown[];\n disabled?: boolean;\n garbageCollectAge?: number;\n maxage?: number;\n noSSR?: boolean;\n refreshAge?: number;\n};\n\nexport type UseAsyncDataResT<DataT> = {\n data: DataT | null;\n loading: boolean;\n reload: AsyncDataReloaderT<DataT>;\n timestamp: number;\n};\n\n/**\n * Executes the data loading operation.\n * @param path Data segment path inside the global state.\n * @param loader Data loader.\n * @param globalState The global state instance.\n * @param oldData Optional. Previously fetched data, currently stored in\n * the state, if already fetched by the caller; otherwise, they will be fetched\n * by the load() function itself.\n * @param opIdPrefix operationId prefix to use, which should be\n * 'C' at the client-side (default), or 'S' at the server-side (within SSR\n * context).\n * @return Resolves once the operation is done.\n * @ignore\n */\nexport async function load<DataT>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<DataT>,\n globalState: GlobalState<unknown, SsrContext<unknown>>,\n old?: { data: DataT | null; timestamp: number },\n\n // TODO: Should this parameter be just a binary flag (client or server),\n // and UUID always generated inside this function? Or do we need it in\n // the caller methods as well, in some cases (see useAsyncCollection()\n // use case as well).\n operationId: OperationIdT = `C${uuid()}`,\n): Promise<void> {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState: async data (re-)loading. Path: \"${path ?? ''}\"`,\n );\n /* eslint-enable no-console */\n }\n\n const operationIdPath = path ? `${path}.operationId` : 'operationId';\n {\n const prevOperationId = globalState.get<ForceT, string>(operationIdPath);\n if (prevOperationId) globalState.asyncDataLoadDone(prevOperationId, true);\n }\n globalState.set<ForceT, string>(operationIdPath, operationId);\n\n let definedOld = old;\n if (!definedOld) {\n // TODO: Can we improve the typing, to avoid ForceT?\n const e = globalState.get<ForceT, AsyncDataEnvelopeT<DataT>>(path);\n definedOld = { data: e.data, timestamp: e.timestamp };\n }\n\n const dataOrPromise = loader(definedOld.data, {\n isAborted: () => {\n // TODO: Can we improve the typing, to avoid ForceT?\n const opid = globalState.get<\n ForceT, AsyncDataEnvelopeT<DataT>>(path).operationId;\n return opid !== operationId;\n },\n oldDataTimestamp: definedOld.timestamp,\n setAbortCallback(cb: () => void) {\n const opid = globalState.get<\n ForceT, AsyncDataEnvelopeT<DataT>>(path).operationId;\n if (opid !== operationId) {\n throw Error(`Operation #${operationId} has completed already`);\n }\n globalState.setAsyncDataAbortCallback(operationId, cb);\n },\n });\n\n let data: DataT | null;\n\n try {\n data = dataOrPromise instanceof Promise\n ? await dataOrPromise : dataOrPromise;\n } finally {\n // NOTE: We don't really mean that it hasn't been aborted,\n // the \"false\" flag rather says we don't need to trigger \"on aborted\"\n // callback for this operation, if any is registered - just drop it.\n globalState.asyncDataLoadDone(operationId, false);\n }\n\n type EnvT = AsyncDataEnvelopeT<DataT> | undefined;\n const state: EnvT = globalState.get<ForceT, EnvT>(path);\n\n if (operationId === state?.operationId) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState: async data (re-)loaded. Path: \"${\n path ?? ''\n }\"`,\n );\n console.log('Data:', cloneDeepForLog(data, path ?? ''));\n /* eslint-enable no-console */\n }\n globalState.set<ForceT, AsyncDataEnvelopeT<DataT>>(path, {\n ...state,\n data,\n operationId: '',\n timestamp: Date.now(),\n });\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupEnd();\n /* eslint-enable no-console */\n }\n }\n}\n\n/**\n * Resolves asynchronous data, and stores them at given `path` of global\n * state.\n */\n\nexport type DataInEnvelopeAtPathT<\n StateT,\n PathT extends null | string | undefined,\n> = Exclude<Extract<ValueAtPathT<StateT, PathT, void>, AsyncDataEnvelopeT<unknown>>['data'], null>;\n\ntype HeapT<DataT> = {\n // Note: these heap fields are necessary to make reload() a stable function.\n globalState?: GlobalState<unknown>;\n path?: null | string;\n loader?: AsyncDataLoaderT<DataT>;\n reload?: AsyncDataReloaderT<DataT>;\n};\n\nfunction useAsyncData<\n StateT,\n PathT extends null | string | undefined,\n\n DataT extends DataInEnvelopeAtPathT<\n StateT, PathT> = DataInEnvelopeAtPathT<StateT, PathT>,\n>(\n path: PathT,\n loader: AsyncDataLoaderT<DataT>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncDataResT<DataT>;\n\nfunction useAsyncData<\n Forced extends ForceT | LockT = LockT,\n DataT = void,\n>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;\n\nfunction useAsyncData<DataT>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<DataT>,\n options: UseAsyncDataOptionsT = {},\n): UseAsyncDataResT<DataT> {\n const maxage: number = options.maxage ?? DEFAULT_MAXAGE;\n const refreshAge: number = options.refreshAge ?? maxage;\n const garbageCollectAge: number = options.garbageCollectAge ?? maxage;\n\n // Note: here we can't depend on useGlobalState() to init the initial value,\n // because that way we'll have issues with SSR (see details below).\n const globalState = getGlobalState();\n const state = globalState.get<ForceT, AsyncDataEnvelopeT<DataT>>(path, {\n initialValue: newAsyncDataEnvelope<DataT>(),\n });\n\n const { current: heap } = useRef<HeapT<DataT>>({});\n heap.globalState = globalState;\n heap.path = path;\n heap.loader = loader;\n\n heap.reload ??= async (customLoader?: AsyncDataLoaderT<DataT>) => {\n const localLoader = customLoader ?? heap.loader;\n if (!localLoader || !heap.globalState) throw Error('Internal error');\n return load(heap.path, localLoader, heap.globalState);\n };\n\n if (globalState.ssrContext) {\n if (\n !options.disabled && !options.noSSR\n && !state.operationId && !state.timestamp\n ) {\n globalState.ssrContext.pending.push(\n load(path, loader, globalState, {\n data: state.data,\n timestamp: state.timestamp,\n }, `S${uuid()}`),\n );\n }\n } else {\n const { disabled } = options;\n\n // This takes care about the client-side reference counting, and garbage\n // collection.\n //\n // Note: the Rules of Hook below are violated by conditional call to a hook,\n // but as the condition is actually server-side or client-side environment,\n // it is effectively non-conditional at the runtime.\n //\n // TODO: Though, maybe there is a way to refactor it into a cleaner code.\n // The same applies to other useEffect() hooks below.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n const numRefsPath = path ? `${path}.numRefs` : 'numRefs';\n if (!disabled) {\n const numRefs = globalState.get<ForceT, number>(numRefsPath);\n globalState.set<ForceT, number>(numRefsPath, numRefs + 1);\n }\n return () => {\n if (!disabled) {\n const state2: AsyncDataEnvelopeT<DataT> = globalState.get<\n ForceT, AsyncDataEnvelopeT<DataT>>(\n path,\n );\n if (\n state2.numRefs === 1\n && garbageCollectAge < Date.now() - state2.timestamp\n ) {\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.log(\n `ReactGlobalState - useAsyncData garbage collected at path ${\n path ?? ''\n }`,\n );\n /* eslint-enable no-console */\n }\n globalState.dropDependencies(path ?? '');\n globalState.set<ForceT, AsyncDataEnvelopeT<DataT>>(path, {\n ...state2,\n data: null,\n numRefs: 0,\n timestamp: 0,\n });\n } else {\n globalState.set<ForceT, number>(numRefsPath, state2.numRefs - 1);\n }\n }\n };\n }, [disabled, garbageCollectAge, globalState, path]);\n\n // Note: a bunch of Rules of Hooks ignored belows because in our very\n // special case the otherwise wrong behavior is actually what we need.\n\n // Data loading and refreshing.\n useEffect(() => { // eslint-disable-line react-hooks/rules-of-hooks\n if (!disabled) {\n const state2: AsyncDataEnvelopeT<DataT> = globalState.get<\n ForceT, AsyncDataEnvelopeT<DataT>>(path);\n\n const { deps } = options;\n if (\n // The hook is called with a list of dependencies, that mismatch\n // dependencies last used to retrieve the data at given path.\n (deps && globalState.hasChangedDependencies(path ?? '', deps))\n\n // Data at the path are stale, and are not being loaded.\n || (\n refreshAge < Date.now() - state2.timestamp\n && (!state2.operationId || state2.operationId.startsWith('S'))\n )\n ) {\n if (!deps) globalState.dropDependencies(path ?? '');\n void load(path, loader, globalState, {\n data: state2.data,\n timestamp: state2.timestamp,\n });\n }\n }\n });\n }\n\n const [localState] = useGlobalState<ForceT, AsyncDataEnvelopeT<DataT>>(\n path,\n newAsyncDataEnvelope<DataT>(),\n );\n\n return {\n data: maxage < Date.now() - localState.timestamp ? null : localState.data,\n loading: Boolean(localState.operationId),\n reload: heap.reload,\n timestamp: localState.timestamp,\n };\n}\n\nexport { useAsyncData };\n\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface UseAsyncDataI<StateT> {\n <PathT extends null | string | undefined>(\n path: PathT,\n loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n <Forced extends ForceT | LockT = LockT, DataT = unknown>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;\n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CAAC3D,IAAI;IACzE4D,OAAO,EAAEC,OAAO,CAACF,UAAU,CAAC1D,WAAW,CAAC;IACxC4C,MAAM,EAAED,IAAI,CAACC,MAAM;IACnB9C,SAAS,EAAE4D,UAAU,CAAC5D;EACxB,CAAC;AACH;AAEA,SAASkC,YAAY;;AAErB","ignoreList":[]}
@@ -63,10 +63,20 @@ import { cloneDeepForLog, isDebugMode } from "./utils";
63
63
 
64
64
  // "State evaluation overload"
65
65
 
66
- function useGlobalState(path, initialValue) {
66
+ function useGlobalState(path,
67
+ // TODO: Revise it later!
68
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
69
+ initialValue
70
+
71
+ // TODO: Revise it later!
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ ) {
67
74
  const globalState = getGlobalState();
68
75
  const ref = useRef(undefined);
69
- let rc;
76
+
77
+ // TODO: Revise how this `rc` variable is used, perhaps we can simplify stuff
78
+ // here.
79
+ let rc = ref.current;
70
80
  if (!ref.current) {
71
81
  const emitter = new Emitter();
72
82
  ref.current = {
@@ -76,10 +86,10 @@ function useGlobalState(path, initialValue) {
76
86
  setter: value => {
77
87
  const newState = isFunction(value) ? value(rc.globalState.get(rc.path)) : value;
78
88
  if (process.env.NODE_ENV !== 'production' && isDebugMode()) {
79
- var _rc$path;
89
+ var _path, _path2;
80
90
  /* eslint-disable no-console */
81
- console.groupCollapsed(`ReactGlobalState - useGlobalState setter triggered for path ${rc.path || ''}`);
82
- console.log('New value:', cloneDeepForLog(newState, (_rc$path = rc.path) !== null && _rc$path !== void 0 ? _rc$path : ''));
91
+ console.groupCollapsed(`ReactGlobalState - useGlobalState setter triggered for path ${(_path = rc.path) !== null && _path !== void 0 ? _path : ''}`);
92
+ console.log('New value:', cloneDeepForLog(newState, (_path2 = rc.path) !== null && _path2 !== void 0 ? _path2 : ''));
83
93
  console.groupEnd();
84
94
  /* eslint-enable no-console */
85
95
  }
@@ -99,6 +109,8 @@ function useGlobalState(path, initialValue) {
99
109
  state: isFunction(initialValue) ? initialValue() : initialValue,
100
110
  subscribe: emitter.addListener.bind(emitter),
101
111
  watcher: () => {
112
+ // TODO: Revise it later.
113
+ // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
102
114
  const state = rc.globalState.get(rc.path);
103
115
  if (state !== rc.state) rc.emitter.emit();
104
116
  }
@@ -110,8 +122,8 @@ function useGlobalState(path, initialValue) {
110
122
  rc.state = useSyncExternalStore(rc.subscribe, () => rc.globalState.get(rc.path, {
111
123
  initialValue
112
124
  }), () => rc.globalState.get(rc.path, {
113
- initialValue,
114
- initialState: true
125
+ initialState: true,
126
+ initialValue
115
127
  }));
116
128
  useEffect(() => {
117
129
  const {
@@ -119,7 +131,9 @@ function useGlobalState(path, initialValue) {
119
131
  } = ref.current;
120
132
  globalState.watch(watcher);
121
133
  watcher();
122
- return () => globalState.unWatch(watcher);
134
+ return () => {
135
+ globalState.unWatch(watcher);
136
+ };
123
137
  }, [globalState]);
124
138
  useEffect(() => {
125
139
  ref.current.watcher();
@@ -127,4 +141,7 @@ function useGlobalState(path, initialValue) {
127
141
  return [rc.state, rc.setter];
128
142
  }
129
143
  export default useGlobalState;
144
+
145
+ // TODO: Revise.
146
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
130
147
  //# sourceMappingURL=useGlobalState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useGlobalState.js","names":["isFunction","useEffect","useRef","useSyncExternalStore","Emitter","getGlobalState","cloneDeepForLog","isDebugMode","useGlobalState","path","initialValue","globalState","ref","undefined","rc","current","emitter","setter","value","newState","get","process","env","NODE_ENV","_path","_path2","console","groupCollapsed","log","groupEnd","set","state","emit","subscribe","addListener","bind","watcher","initialState","watch","unWatch"],"sources":["../../src/useGlobalState.ts"],"sourcesContent":["// Hook for updates of global state.\n\nimport { isFunction } from 'lodash';\n\nimport {\n type Dispatch,\n type SetStateAction,\n useEffect,\n useRef,\n useSyncExternalStore,\n} from 'react';\n\nimport { Emitter } from '@dr.pogodin/js-utils';\n\nimport type GlobalState from './GlobalState';\nimport { getGlobalState } from './GlobalStateProvider';\n\nimport {\n type CallbackT,\n type ForceT,\n type LockT,\n type TypeLock,\n type ValueAtPathT,\n type ValueOrInitializerT,\n cloneDeepForLog,\n isDebugMode,\n} from './utils';\n\nexport type SetterT<T> = Dispatch<SetStateAction<T>>;\n\ntype ListenerT = () => void;\n\ntype GlobalStateRef = {\n emitter: Emitter<[]>;\n globalState: GlobalState<unknown>;\n path: null | string | undefined;\n setter: SetterT<unknown>;\n subscribe: (listener: ListenerT) => () => void;\n state: unknown;\n watcher: CallbackT;\n};\n\nexport type UseGlobalStateResT<T> = [T, SetterT<T>];\n\n/**\n * The primary hook for interacting with the global state, modeled after\n * the standard React's\n * [useState](https://reactjs.org/docs/hooks-reference.html#usestate).\n * It subscribes a component to a given `path` of global state, and provides\n * a function to update it. Each time the value at `path` changes, the hook\n * triggers re-render of its host component.\n *\n * **Note:**\n * - For performance, the library does not copy objects written to / read from\n * global state paths. You MUST NOT manually mutate returned state values,\n * or change objects already written into the global state, without explicitly\n * clonning them first yourself.\n * - State update notifications are asynchronous. When your code does multiple\n * global state updates in the same React rendering cycle, all state update\n * notifications are queued and dispatched together, after the current\n * rendering cycle. In other words, in any given rendering cycle the global\n * state values are \"fixed\", and all changes becomes visible at once in the\n * next triggered rendering pass.\n *\n * @param path Dot-delimitered state path. It can be undefined to\n * subscribe for entire state.\n *\n * Under-the-hood state values are read and written using `lodash`\n * [_.get()](https://lodash.com/docs/4.17.15#get) and\n * [_.set()](https://lodash.com/docs/4.17.15#set) methods, thus it is safe\n * to access state paths which have not been created before.\n * @param initialValue Initial value to set at the `path`, or its\n * factory:\n * - If a function is given, it will act similar to\n * [the lazy initial state of the standard React's useState()](https://reactjs.org/docs/hooks-reference.html#lazy-initial-state):\n * only if the value at `path` is `undefined`, the function will be executed,\n * and the value it returns will be written to the `path`.\n * - Otherwise, the given value itself will be written to the `path`,\n * if the current value at `path` is `undefined`.\n * @return It returs an array with two elements: `[value, setValue]`:\n *\n * - The `value` is the current value at given `path`.\n *\n * - The `setValue()` is setter function to write a new value to the `path`.\n *\n * Similar to the standard React's `useState()`, it supports\n * [functional value updates](https://reactjs.org/docs/hooks-reference.html#functional-updates):\n * if `setValue()` is called with a function as argument, that function will\n * be called and its return value will be written to `path`. Otherwise,\n * the argument of `setValue()` itself is written to `path`.\n *\n * Also, similar to the standard React's state setters, `setValue()` is\n * stable function: it does not change between component re-renders.\n */\n\n// \"Enforced type overload\"\nfunction useGlobalState<\n Forced extends ForceT | LockT = LockT,\n ValueT = void,\n>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n\n// \"Entire state overload\"\nfunction useGlobalState<StateT>(): UseGlobalStateResT<StateT>;\n\n// \"State evaluation overload\"\nfunction useGlobalState<\n StateT,\n PathT extends null | string | undefined,\n>(\n path: PathT,\n initialValue: ValueOrInitializerT<\n Exclude<ValueAtPathT<StateT, PathT, never>, undefined>>\n): UseGlobalStateResT<Exclude<ValueAtPathT<StateT, PathT, void>, undefined>>;\n\nfunction useGlobalState<\n StateT,\n PathT extends null | string | undefined,\n>(\n path: PathT,\n initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>\n): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;\n\nfunction useGlobalState(\n path?: null | string,\n // TODO: Revise it later!\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n initialValue?: ValueOrInitializerT<any>,\n\n // TODO: Revise it later!\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n): UseGlobalStateResT<any> {\n const globalState = getGlobalState();\n\n const ref = useRef<GlobalStateRef>(undefined);\n\n // TODO: Revise how this `rc` variable is used, perhaps we can simplify stuff\n // here.\n let rc: GlobalStateRef | undefined = ref.current;\n if (!ref.current) {\n const emitter = new Emitter();\n ref.current = {\n emitter,\n globalState,\n path,\n setter: (value) => {\n const newState = isFunction(value)\n ? value(rc!.globalState.get(rc!.path)) as unknown\n : value;\n\n if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n /* eslint-disable no-console */\n console.groupCollapsed(\n `ReactGlobalState - useGlobalState setter triggered for path ${\n rc!.path ?? ''\n }`,\n );\n console.log('New value:', cloneDeepForLog(newState, rc!.path ?? ''));\n console.groupEnd();\n /* eslint-enable no-console */\n }\n rc!.globalState.set<ForceT, unknown>(rc!.path, newState);\n\n // NOTE: The regular global state's update notifications, automatically\n // triggered by the rc.globalState.set() call above, are batched, and\n // scheduled to fire asynchronosuly at a later time, which is problematic\n // for managed text inputs - if they have their value update delayed to\n // future render cycles, it will result in reset of their cursor position\n // to the value end. Calling the rc.emitter.emit() below causes a sooner\n // state update for the current component, thus working around the issue.\n // For additional details see the original issue:\n // https://github.com/birdofpreyru/react-global-state/issues/22\n if (newState !== rc!.state) rc!.emitter.emit();\n },\n state: isFunction(initialValue) ? initialValue() : initialValue,\n subscribe: emitter.addListener.bind(emitter),\n watcher: () => {\n // TODO: Revise it later.\n // eslint-disable-next-line @typescript-eslint/no-confusing-void-expression\n const state = rc!.globalState.get(rc!.path) as unknown;\n if (state !== rc!.state) rc!.emitter.emit();\n },\n };\n }\n rc = ref.current!;\n\n rc.globalState = globalState;\n rc.path = path;\n\n rc.state = useSyncExternalStore(\n rc.subscribe,\n () => rc.globalState.get<ForceT, unknown>(rc.path, { initialValue }),\n\n () => rc.globalState.get<ForceT, unknown>(\n rc.path,\n { initialState: true, initialValue },\n ),\n );\n\n useEffect(() => {\n const { watcher } = ref.current!;\n globalState.watch(watcher);\n watcher();\n return () => {\n globalState.unWatch(watcher);\n };\n }, [globalState]);\n\n useEffect(() => {\n ref.current!.watcher();\n }, [path]);\n\n return [rc.state, rc.setter];\n}\n\nexport default useGlobalState;\n\n// TODO: Revise.\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions\nexport interface UseGlobalStateI<StateT> {\n (): UseGlobalStateResT<StateT>;\n\n <PathT extends null | string | undefined>(\n path: PathT,\n initialValue: ValueOrInitializerT<\n Exclude<ValueAtPathT<StateT, PathT, never>, undefined>>\n ): UseGlobalStateResT<Exclude<ValueAtPathT<StateT, PathT, void>, undefined>>;\n\n <PathT extends null | string | undefined>(\n path: PathT,\n initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>\n ): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;\n\n <Forced extends ForceT | LockT = LockT, ValueT = unknown>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n ): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n}\n"],"mappings":"AAAA;;AAEA,SAASA,UAAU,QAAQ,QAAQ;AAEnC,SAGEC,SAAS,EACTC,MAAM,EACNC,oBAAoB,QACf,OAAO;AAEd,SAASC,OAAO,QAAQ,sBAAsB;AAG9C,SAASC,cAAc;AAEvB,SAOEC,eAAe,EACfC,WAAW;;AAmBb;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AASA;;AAGA;;AAkBA,SAASC,cAAcA,CACrBC,IAAoB;AACpB;AACA;AACAC;;AAEA;AACA;AAAA,EACyB;EACzB,MAAMC,WAAW,GAAGN,cAAc,CAAC,CAAC;EAEpC,MAAMO,GAAG,GAAGV,MAAM,CAAiBW,SAAS,CAAC;;EAE7C;EACA;EACA,IAAIC,EAA8B,GAAGF,GAAG,CAACG,OAAO;EAChD,IAAI,CAACH,GAAG,CAACG,OAAO,EAAE;IAChB,MAAMC,OAAO,GAAG,IAAIZ,OAAO,CAAC,CAAC;IAC7BQ,GAAG,CAACG,OAAO,GAAG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AAK,KAAKjB,EAAE,CAAEiB,KAAK,EAAEjB,EAAE,CAAEE,OAAO,CAACgB,IAAI,CAAC,CAAC;MAC7C;IACF,CAAC;EACH;EACAlB,EAAE,GAAGF,GAAG,CAACG,OAAQ;EAEjBD,EAAE,CAACH,WAAW,GAAGA,WAAW;EAC5BG,EAAE,CAACL,IAAI,GAAGA,IAAI;EAEdK,EAAE,CAACiB,KAAK,GAAG5B,oBAAoB,CAC7BW,EAAE,CAACmB,SAAS,EACZ,MAAMnB,EAAE,CAACH,WAAW,CAACS,GAAG,CAAkBN,EAAE,CAACL,IAAI,EAAE;IAAEC;EAAa,CAAC,CAAC,EAEpE,MAAMI,EAAE,CAACH,WAAW,CAACS,GAAG,CACtBN,EAAE,CAACL,IAAI,EACP;IAAE4B,YAAY,EAAE,IAAI;IAAE3B;EAAa,CACrC,CACF,CAAC;EAEDT,SAAS,CAAC,MAAM;IACd,MAAM;MAAEmC;IAAQ,CAAC,GAAGxB,GAAG,CAACG,OAAQ;IAChCJ,WAAW,CAAC2B,KAAK,CAACF,OAAO,CAAC;IAC1BA,OAAO,CAAC,CAAC;IACT,OAAO,MAAM;MACXzB,WAAW,CAAC4B,OAAO,CAACH,OAAO,CAAC;IAC9B,CAAC;EACH,CAAC,EAAE,CAACzB,WAAW,CAAC,CAAC;EAEjBV,SAAS,CAAC,MAAM;IACdW,GAAG,CAACG,OAAO,CAAEqB,OAAO,CAAC,CAAC;EACxB,CAAC,EAAE,CAAC3B,IAAI,CAAC,CAAC;EAEV,OAAO,CAACK,EAAE,CAACiB,KAAK,EAAEjB,EAAE,CAACG,MAAM,CAAC;AAC9B;AAEA,eAAeT,cAAc;;AAE7B;AACA","ignoreList":[]}
@@ -32,7 +32,7 @@ import { cloneDeep } from 'lodash';
32
32
  export function isDebugMode() {
33
33
  try {
34
34
  return process.env.NODE_ENV !== 'production' && !!process.env.REACT_GLOBAL_STATE_DEBUG;
35
- } catch (error) {
35
+ } catch {
36
36
  return false;
37
37
  }
38
38
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","names":["cloneDeep","isDebugMode","process","env","NODE_ENV","REACT_GLOBAL_STATE_DEBUG","cloneDeepBailKeys","Set","cloneDeepForLog","value","key","arguments","length","undefined","has","console","warn","start","Date","now","res","time","add","escape","x","replace","toString","hash","items","map","join"],"sources":["../../src/utils.ts"],"sourcesContent":["import { type GetFieldType, cloneDeep } from 'lodash';\n\nexport type CallbackT = () => void;\n\n// TODO: This (ForceT, LockT, and TypeLock) probably should be moved to JS Utils\n// lib.\n\nexport declare const force: unique symbol;\nexport declare const lock: unique symbol;\n\nexport type ForceT = typeof force;\nexport type LockT = typeof lock;\n\nexport type TypeLock<\n Unlocked extends ForceT | LockT,\n\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n LockedT extends never | void,\n UnlockedT,\n> = Unlocked extends ForceT ? UnlockedT : LockedT;\n\n/**\n * Given the type of state, `StateT`, and the type of state path, `PathT`,\n * it evaluates the type of value at that path of the state, if it can be\n * evaluated from the path type (it is possible when `PathT` is a string\n * literal type, and `StateT` elements along this path have appropriate\n * types); otherwise it falls back to the specified `UnknownT` type,\n * which should be set either `never` (for input arguments), or `void`\n * (for return types) - `never` and `void` in those places forbid assignments,\n * and are not auto-inferred to more permissible types.\n *\n * BEWARE: When StateT is any the construct resolves to any for any string\n * paths.\n */\nexport type ValueAtPathT<\n StateT,\n PathT extends null | string | undefined,\n\n // TODO: Revise later.\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents, @typescript-eslint/no-invalid-void-type\n UnknownT extends never | undefined | void,\n> = unknown extends StateT\n ? UnknownT\n : string extends PathT\n ? UnknownT\n : PathT extends null | undefined\n ? StateT\n : GetFieldType<StateT, PathT> extends undefined\n ? UnknownT : GetFieldType<StateT, PathT>;\n\nexport type ValueOrInitializerT<ValueT> = ValueT | (() => ValueT);\n\n/**\n * Returns 'true' if debug logging should be performed; 'false' otherwise.\n *\n * BEWARE: The actual safeguards for the debug logging still should read\n * if (process.env.NODE_ENV !== 'production' && isDebugMode()) {\n * // Some debug logging\n * }\n * to ensure that debug code is stripped out by Webpack in production mode.\n *\n * @returns\n * @ignore\n */\nexport function isDebugMode(): boolean {\n try {\n return process.env.NODE_ENV !== 'production'\n && !!process.env.REACT_GLOBAL_STATE_DEBUG;\n } catch {\n return false;\n }\n}\n\nconst cloneDeepBailKeys = new Set<string>();\n\n/**\n * Deep-clones given value for logging purposes, or returns the value itself\n * if the previous clone attempt, with the same key, took more than 300ms\n * (to avoid situations when large payload in the global state slows down\n * development versions of the app due to the logging overhead).\n */\nexport function cloneDeepForLog<T>(value: T, key: string = ''): T {\n if (cloneDeepBailKeys.has(key)) {\n // eslint-disable-next-line no-console\n console.warn(`The logged value won't be clonned (key \"${key}\").`);\n return value;\n }\n\n const start = Date.now();\n const res = cloneDeep(value);\n const time = Date.now() - start;\n if (time > 300) {\n // eslint-disable-next-line no-console\n console.warn(`${time}ms spent to clone the logged value (key \"${key}\").`);\n cloneDeepBailKeys.add(key);\n }\n\n return res;\n}\n\n/**\n * Converts given value to an escaped string. For now, we are good with the most\n * trivial escape logic:\n * - '%' characters are replaced by '%0' code pair;\n * - '/' characters are replaced by '%1' code pair.\n */\nexport function escape(x: number | string): string {\n return typeof x === 'string'\n ? x.replace(/%/g, '%0').replace(/\\//g, '%1')\n : x.toString();\n}\n\n/**\n * Hashes given string array. For our current needs we are fine to go with\n * the most trivial implementation, which probably should not be called \"hash\"\n * in the strict sense: we just escape each given string to not include '/'\n * characters, and then we join all those strings using '/' as the separator.\n */\nexport function hash(items: Array<number | string>): string {\n return items.map(escape).join('/');\n}\n"],"mappings":"AAAA,SAA4BA,SAAS,QAAQ,QAAQ;;AAIrD;AACA;;AAiBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,WAAWA,CAA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AASC,IAAIA,CAACC,KAA6B,EAAU;EAC1D,OAAOA,KAAK,CAACC,GAAG,CAACN,MAAM,CAAC,CAACO,IAAI,CAAC,GAAG,CAAC;AACpC","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import SsrContext from './SsrContext';
1
+ import type SsrContext from './SsrContext';
2
2
  import { type CallbackT, type ForceT, type LockT, type TypeLock, type ValueAtPathT, type ValueOrInitializerT } from './utils';
3
3
  type GetOptsT<T> = {
4
4
  initialState?: boolean;
@@ -39,7 +39,7 @@ export default class GlobalState<StateT, SsrContextT extends SsrContext<StateT>
39
39
  * are used. We should normalize given path here, I guess, or on a higher
40
40
  * level in the logic?
41
41
  */
42
- hasChangedDependencies(path: string, deps: any[]): boolean;
42
+ hasChangedDependencies(path: string, deps: unknown[]): boolean;
43
43
  /**
44
44
  * Gets entire state, the same way as .get(null, opts) would do.
45
45
  * @param opts.initialState
@@ -1,7 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import GlobalState from './GlobalState';
3
- import SsrContext from './SsrContext';
4
- import { type ValueOrInitializerT } from './utils';
3
+ import type SsrContext from './SsrContext';
4
+ import type { ValueOrInitializerT } from './utils';
5
5
  /**
6
6
  * Gets {@link GlobalState} instance from the context. In most cases
7
7
  * you should use {@link useGlobalState}, and other hooks to interact with
@@ -46,5 +46,5 @@ type GlobalStateProviderProps<StateT, SsrContextT extends SsrContext<StateT>> =
46
46
  * - If `GlobalState` instance, it will be used by this provider.
47
47
  * - If not given, a new `GlobalState` instance will be created and used.
48
48
  */
49
- declare const GlobalStateProvider: <StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>({ children, ...rest }: GlobalStateProviderProps<StateT, SsrContextT>) => import("react/jsx-runtime").JSX.Element;
49
+ declare const GlobalStateProvider: <StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>({ children, ...rest }: GlobalStateProviderProps<StateT, SsrContextT>) => ReactNode;
50
50
  export default GlobalStateProvider;
@@ -1,6 +1,6 @@
1
1
  export default class SsrContext<StateT> {
2
+ state?: StateT | undefined;
2
3
  dirty: boolean;
3
- pending: Promise<void>[];
4
- state?: StateT;
5
- constructor(state?: StateT);
4
+ pending: Array<Promise<void>>;
5
+ constructor(state?: StateT | undefined);
6
6
  }
@@ -3,9 +3,7 @@
3
3
  */
4
4
  import { type AsyncDataEnvelopeT, type DataInEnvelopeAtPathT, type UseAsyncDataOptionsT, type UseAsyncDataResT } from './useAsyncData';
5
5
  import { type ForceT, type LockT, type TypeLock } from './utils';
6
- export type AsyncCollectionT<DataT = unknown, IdT extends number | string = number | string> = {
7
- [id in IdT]?: AsyncDataEnvelopeT<DataT>;
8
- };
6
+ export type AsyncCollectionT<DataT = unknown, IdT extends number | string = number | string> = Record<IdT, AsyncDataEnvelopeT<DataT>>;
9
7
  export type AsyncCollectionLoaderT<DataT, IdT extends number | string = number | string> = (id: IdT, oldData: null | DataT, meta: {
10
8
  isAborted: () => boolean;
11
9
  oldDataTimestamp: number;
@@ -18,9 +16,7 @@ type CollectionItemT<DataT> = {
18
16
  timestamp: number;
19
17
  };
20
18
  export type UseAsyncCollectionResT<DataT, IdT extends number | string = number | string> = {
21
- items: {
22
- [id in IdT]: CollectionItemT<DataT>;
23
- };
19
+ items: Record<IdT, CollectionItemT<DataT>>;
24
20
  loading: boolean;
25
21
  reload: AsyncCollectionReloaderT<DataT, IdT>;
26
22
  timestamp: number;
@@ -33,10 +29,12 @@ declare function useAsyncCollection<StateT, PathT extends null | string | undefi
33
29
  declare function useAsyncCollection<Forced extends ForceT | LockT = LockT, DataT = unknown, IdT extends number | string = number | string>(id: IdT, path: null | string | undefined, loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;
34
30
  declare function useAsyncCollection<StateT, PathT extends null | string | undefined, IdT extends number | string, DataT extends DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`> = DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>>(id: IdT[], path: PathT, loader: AsyncCollectionLoaderT<DataT, IdT>, options?: UseAsyncDataOptionsT): UseAsyncCollectionResT<DataT, IdT>;
35
31
  declare function useAsyncCollection<Forced extends ForceT | LockT = LockT, DataT = unknown, IdT extends number | string = number | string>(id: IdT[], path: null | string | undefined, loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncCollectionResT<DataT, IdT>;
32
+ declare function useAsyncCollection<StateT, PathT extends null | string | undefined, IdT extends number | string, DataT extends DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`> = DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>>(id: IdT | IdT[], path: PathT, loader: AsyncCollectionLoaderT<DataT, IdT>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataT> | UseAsyncCollectionResT<DataT, IdT>;
36
33
  export default useAsyncCollection;
37
34
  export interface UseAsyncCollectionI<StateT> {
38
35
  <PathT extends null | string | undefined, IdT extends number | string>(id: IdT, path: PathT, loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>>;
39
36
  <Forced extends ForceT | LockT = LockT, DataT = unknown, IdT extends number | string = number | string>(id: IdT, path: null | string | undefined, loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<TypeLock<Forced, void, DataT>>;
40
37
  <PathT extends null | string | undefined, IdT extends number | string>(id: IdT[], path: PathT, loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncCollectionResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>;
41
38
  <Forced extends ForceT | LockT = LockT, DataT = unknown, IdT extends number | string = number | string>(id: IdT[], path: null | string | undefined, loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncCollectionResT<DataT, IdT>;
39
+ <PathT extends null | string | undefined, IdT extends number | string>(id: IdT | IdT[], path: PathT, loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>> | UseAsyncCollectionResT<DataInEnvelopeAtPathT<StateT, `${PathT}.${IdT}`>, IdT>;
42
40
  }
@@ -2,8 +2,8 @@
2
2
  * Loads and uses async data into the GlobalState path.
3
3
  */
4
4
  import { type ForceT, type LockT, type TypeLock, type ValueAtPathT } from './utils';
5
- import GlobalState from './GlobalState';
6
- import SsrContext from './SsrContext';
5
+ import type GlobalState from './GlobalState';
6
+ import type SsrContext from './SsrContext';
7
7
  export declare const DEFAULT_MAXAGE: number;
8
8
  export type AsyncDataLoaderT<DataT> = (oldData: null | DataT, meta: {
9
9
  isAborted: () => boolean;
@@ -1,7 +1,7 @@
1
1
  import { type GetFieldType } from 'lodash';
2
2
  export type CallbackT = () => void;
3
- declare const force: unique symbol;
4
- declare const lock: unique symbol;
3
+ export declare const force: unique symbol;
4
+ export declare const lock: unique symbol;
5
5
  export type ForceT = typeof force;
6
6
  export type LockT = typeof lock;
7
7
  export type TypeLock<Unlocked extends ForceT | LockT, LockedT extends never | void, UnlockedT> = Unlocked extends ForceT ? UnlockedT : LockedT;
@@ -54,4 +54,3 @@ export declare function escape(x: number | string): string;
54
54
  * characters, and then we join all those strings using '/' as the separator.
55
55
  */
56
56
  export declare function hash(items: Array<number | string>): string;
57
- export {};
@@ -0,0 +1,19 @@
1
+ /* eslint-disable import/no-extraneous-dependencies */
2
+
3
+ import { defineConfig } from 'eslint/config';
4
+ import eslintConfigs from '@dr.pogodin/eslint-configs';
5
+
6
+ export default defineConfig([
7
+ { ignores: [
8
+ 'build/',
9
+ 'docs/build/',
10
+ 'docs/.docusaurus/',
11
+ ] },
12
+ eslintConfigs.configs.javascript,
13
+ eslintConfigs.configs.typescript,
14
+ eslintConfigs.configs.react,
15
+ {
16
+ extends: [eslintConfigs.configs.jest],
17
+ files: ['__tests__/**'],
18
+ },
19
+ ]);
package/package.json CHANGED
@@ -1,25 +1,20 @@
1
1
  {
2
2
  "name": "@dr.pogodin/react-global-state",
3
- "version": "0.18.0",
3
+ "version": "0.19.0",
4
4
  "description": "Hook-based global state for React",
5
- "main": "./build/common/index.js",
6
- "react-native": "src/index.ts",
7
- "source": "src/index.ts",
5
+ "main": "./build/code/index.js",
8
6
  "types": "./build/types/index.d.ts",
9
7
  "exports": {
10
- "module": "./build/module/index.js",
11
- "node": "./build/common/index.js",
12
- "default": "./build/common/index.js"
8
+ "default": "./build/code/index.js"
13
9
  },
14
10
  "scripts": {
15
- "build": "rimraf build && npm run build:types && npm run build:common && npm run build:module",
16
- "build:common": "rimraf build/common && babel src -x .ts,.tsx --out-dir build/common --source-maps",
17
- "build:module": "rimraf build/module && babel src -x .ts,.tsx --out-dir build/module --source-maps --config-file ./babel.module.config.js",
11
+ "build": "rimraf build && npm run build:types && npm run build:code",
12
+ "build:code": "rimraf build/code && babel src -x .ts,.tsx --out-dir build/code --source-maps --config-file ./babel.module.config.js",
18
13
  "build:types": "rimraf build/types && tsc --project tsconfig.types.json",
19
14
  "jest": "npm run jest:types && npm run jest:logic",
20
15
  "jest:logic": "jest --config jest/config.json -w 1",
21
16
  "jest:types": "tstyche",
22
- "lint": "eslint --ext .js,.jsx,.ts,.tsx .",
17
+ "lint": "eslint",
23
18
  "test": "npm run lint && npm run typecheck && npm run jest",
24
19
  "typecheck": "tsc --project __tests__/tsconfig.json"
25
20
  },
@@ -43,50 +38,39 @@
43
38
  "node": ">=18"
44
39
  },
45
40
  "dependencies": {
46
- "@babel/runtime": "^7.26.0",
47
- "@dr.pogodin/js-utils": "^0.0.13",
48
- "@types/lodash": "^4.17.13",
41
+ "@babel/runtime": "^7.27.1",
42
+ "@dr.pogodin/js-utils": "^0.0.18",
43
+ "@types/lodash": "^4.17.16",
49
44
  "lodash": "^4.17.21",
50
- "uuid": "^11.0.3"
45
+ "uuid": "^11.1.0"
51
46
  },
52
47
  "devDependencies": {
53
- "@babel/cli": "^7.26.4",
54
- "@babel/core": "^7.26.0",
55
- "@babel/eslint-parser": "^7.25.9",
56
- "@babel/eslint-plugin": "^7.25.9",
57
- "@babel/node": "^7.26.0",
58
- "@babel/plugin-transform-runtime": "^7.25.9",
59
- "@babel/preset-env": "^7.26.0",
60
- "@babel/preset-react": "^7.26.3",
61
- "@babel/preset-typescript": "^7.26.0",
48
+ "@babel/cli": "^7.27.2",
49
+ "@babel/core": "^7.27.1",
50
+ "@babel/node": "^7.27.1",
51
+ "@babel/plugin-transform-runtime": "^7.27.1",
52
+ "@babel/preset-env": "^7.27.2",
53
+ "@babel/preset-react": "^7.27.1",
54
+ "@babel/preset-typescript": "^7.27.1",
55
+ "@dr.pogodin/eslint-configs": "^0.0.6",
62
56
  "@testing-library/dom": "^10.4.0",
63
- "@testing-library/react": "^16.1.0",
57
+ "@testing-library/react": "^16.3.0",
64
58
  "@tsconfig/recommended": "^1.0.8",
65
59
  "@types/jest": "^29.5.14",
66
60
  "@types/pretty": "^2.0.3",
67
- "@types/react": "^19.0.2",
68
- "@types/react-dom": "^19.0.2",
61
+ "@types/react": "^19.1.3",
62
+ "@types/react-dom": "^19.1.3",
69
63
  "babel-jest": "^29.7.0",
70
64
  "babel-plugin-module-resolver": "^5.0.2",
71
- "eslint": "^8.57.1",
72
- "eslint-config-airbnb": "^19.0.4",
73
- "eslint-config-airbnb-typescript": "^18.0.0",
74
- "eslint-import-resolver-babel-module": "^5.3.2",
75
- "eslint-plugin-import": "^2.31.0",
76
- "eslint-plugin-jest": "^28.10.0",
77
- "eslint-plugin-jsx-a11y": "^6.10.2",
78
- "eslint-plugin-react": "^7.37.3",
79
- "eslint-plugin-react-hooks": "^4.6.2",
80
65
  "jest": "^29.7.0",
81
66
  "jest-environment-jsdom": "^29.7.0",
82
67
  "mockdate": "^3.0.5",
83
68
  "rimraf": "^6.0.1",
84
- "tstyche": "^3.2.0",
85
- "typescript": "^5.7.2",
86
- "typescript-eslint": "^8.18.2"
69
+ "tstyche": "^3.5.0",
70
+ "typescript": "^5.8.3"
87
71
  },
88
72
  "peerDependencies": {
89
- "react": "^19.0.0",
90
- "react-dom": "^19.0.0"
73
+ "react": "^19.1.0",
74
+ "react-dom": "^19.1.0"
91
75
  }
92
76
  }