@dr.pogodin/react-global-state 0.10.0-alpha.3 → 0.10.0-alpha.4
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/build/common/GlobalState.js.map +1 -1
- package/build/common/index.js +12 -7
- package/build/common/index.js.map +1 -1
- package/build/common/useAsyncCollection.js.map +1 -1
- package/build/common/useAsyncData.js.map +1 -1
- package/build/common/useGlobalState.js +3 -2
- package/build/common/useGlobalState.js.map +1 -1
- package/build/common/utils.js +2 -3
- package/build/common/utils.js.map +1 -1
- package/build/module/GlobalState.js.map +1 -1
- package/build/module/index.js +18 -7
- package/build/module/index.js.map +1 -1
- package/build/module/useAsyncCollection.js.map +1 -1
- package/build/module/useAsyncData.js.map +1 -1
- package/build/module/useGlobalState.js +3 -2
- package/build/module/useGlobalState.js.map +1 -1
- package/build/module/utils.js +2 -2
- package/build/module/utils.js.map +1 -1
- package/build/types/GlobalState.d.ts +3 -3
- package/build/types/index.d.ts +24 -8
- package/build/types/useAsyncCollection.d.ts +6 -2
- package/build/types/useAsyncData.d.ts +6 -2
- package/build/types/useGlobalState.d.ts +7 -2
- package/build/types/utils.d.ts +3 -1
- package/package.json +1 -1
- package/src/GlobalState.ts +3 -2
- package/src/index.ts +57 -19
- package/src/useAsyncCollection.ts +18 -2
- package/src/useAsyncData.ts +17 -2
- package/src/useGlobalState.ts +24 -3
- package/src/utils.ts +6 -3
- package/tsconfig.json +1 -1
- package/build/common/withGlobalStateType.js +0 -42
- package/build/common/withGlobalStateType.js.map +0 -1
- package/build/module/withGlobalStateType.js +0 -35
- package/build/module/withGlobalStateType.js.map +0 -1
- package/build/types/withGlobalStateType.d.ts +0 -29
- package/src/withGlobalStateType.ts +0 -170
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = withGlobalStateType;
|
|
8
|
-
var _GlobalStateProvider = _interopRequireWildcard(require("./GlobalStateProvider"));
|
|
9
|
-
var _useGlobalState = _interopRequireDefault(require("./useGlobalState"));
|
|
10
|
-
var _useAsyncCollection = _interopRequireDefault(require("./useAsyncCollection"));
|
|
11
|
-
var _useAsyncData = _interopRequireDefault(require("./useAsyncData"));
|
|
12
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
-
function withGlobalStateType() {
|
|
15
|
-
// These wrap useGlobalState() with locked-in StateT type.
|
|
16
|
-
|
|
17
|
-
function useGlobalStateWrap(path, initialValue) {
|
|
18
|
-
return (0, _useGlobalState.default)(path, initialValue);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// These overloads & implementation wrap useAsyncData() hook to lock-in its
|
|
22
|
-
// underlying StateT.
|
|
23
|
-
function useAsyncDataWrap(path, loader, options = {}) {
|
|
24
|
-
return (0, _useAsyncData.default)(path, loader, options);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
// These overloads & implementation wrap useAsyncCollection() hook to lock-in
|
|
28
|
-
// its underlying StateT.
|
|
29
|
-
function useAsyncCollectionWrap(id, path, loader, options = {}) {
|
|
30
|
-
return (0, _useAsyncCollection.default)(id, path, loader, options);
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
getGlobalState: _GlobalStateProvider.getGlobalState,
|
|
34
|
-
getSsrContext: _GlobalStateProvider.getSsrContext,
|
|
35
|
-
GlobalStateProvider: _GlobalStateProvider.default,
|
|
36
|
-
// SsrContext, /* CustomSsrContext || SsrContext, */
|
|
37
|
-
useAsyncCollection: useAsyncCollectionWrap,
|
|
38
|
-
useAsyncData: useAsyncDataWrap,
|
|
39
|
-
useGlobalState: useGlobalStateWrap
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=withGlobalStateType.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withGlobalStateType.js","names":["_GlobalStateProvider","_interopRequireWildcard","require","_useGlobalState","_interopRequireDefault","_useAsyncCollection","_useAsyncData","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","withGlobalStateType","useGlobalStateWrap","path","initialValue","useGlobalState","useAsyncDataWrap","loader","options","useAsyncData","useAsyncCollectionWrap","id","useAsyncCollection","getGlobalState","getSsrContext","GlobalStateProvider"],"sources":["../../src/withGlobalStateType.ts"],"sourcesContent":["import {\n type ForceT,\n type TypeLock,\n type ValueAtPathT,\n type ValueOrInitializerT,\n} from './utils';\n\nimport GlobalStateProvider, {\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nimport SsrContext from './SsrContext';\n\nimport useGlobalState, {\n type UseGlobalStateResT,\n} from './useGlobalState';\n\nimport useAsyncCollection, {\n type AsyncCollectionLoaderT,\n} from './useAsyncCollection';\n\nimport useAsyncData, {\n type AsyncDataLoaderT,\n type DataInEnvelopeAtPathT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n} from './useAsyncData';\n\ninterface NarrowedUseGlobalStateI<StateT> {\n (): UseGlobalStateResT<StateT>;\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 | false = false, ValueT = unknown>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n ): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n}\n\ninterface NarrowedUseAsyncDataI<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 | false = false, DataT = unknown>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;\n}\n\ninterface NarrowedUseAsyncCollectionI<StateT> {\n <PathT extends null | string | undefined>(\n id: string,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n <Forced extends ForceT | false = false, DataT = unknown>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataT>;\n}\n\ntype WithGlobalStateTypeResT<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n> = {\n getGlobalState: typeof getGlobalState<StateT, SsrContextT>,\n getSsrContext: typeof getSsrContext<SsrContextT>,\n GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>,\n // SsrContext: SsrContext<StateT>,\n useAsyncCollection: NarrowedUseAsyncCollectionI<StateT>,\n useAsyncData: NarrowedUseAsyncDataI<StateT>,\n useGlobalState: NarrowedUseGlobalStateI<StateT>,\n};\n\nexport default function withGlobalStateType<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n>(): WithGlobalStateTypeResT<StateT, SsrContextT> {\n // These wrap useGlobalState() with locked-in StateT type.\n\n function useGlobalStateWrap(): UseGlobalStateResT<StateT>;\n\n function useGlobalStateWrap<PathT extends null | string | undefined>(\n path: PathT,\n initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>,\n ): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;\n\n function useGlobalStateWrap<Forced extends ForceT | false = false, ValueT = unknown>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n ): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n\n function useGlobalStateWrap(\n path?: null | string,\n initialValue?: ValueOrInitializerT<unknown>,\n ): UseGlobalStateResT<any> {\n return useGlobalState<ForceT, unknown>(path, initialValue);\n }\n\n // These overloads & implementation wrap useAsyncData() hook to lock-in its\n // underlying StateT.\n\n function useAsyncDataWrap<PathT extends null | string | undefined>(\n path: PathT,\n loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n function useAsyncDataWrap<Forced extends ForceT | false = false, DataT = unknown>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;\n\n function useAsyncDataWrap<DataT>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<DataT>,\n options: UseAsyncDataOptionsT = {},\n ): UseAsyncDataResT<DataT> {\n return useAsyncData<ForceT, DataT>(path, loader, options);\n }\n\n // These overloads & implementation wrap useAsyncCollection() hook to lock-in\n // its underlying StateT.\n\n function useAsyncCollectionWrap<PathT extends null | string | undefined>(\n id: string,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n function useAsyncCollectionWrap<Forced extends ForceT | false = false, DataT = unknown>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataT>;\n\n function useAsyncCollectionWrap<DataT>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<DataT>,\n options: UseAsyncDataOptionsT = {},\n ): UseAsyncDataResT<DataT> {\n return useAsyncCollection<ForceT, DataT>(id, path, loader, options);\n }\n\n return {\n getGlobalState: getGlobalState<StateT, SsrContextT>,\n getSsrContext: getSsrContext<SsrContextT>,\n GlobalStateProvider: GlobalStateProvider<StateT, SsrContextT>,\n // SsrContext, /* CustomSsrContext || SsrContext, */\n useAsyncCollection: useAsyncCollectionWrap,\n useAsyncData: useAsyncDataWrap,\n useGlobalState: useGlobalStateWrap,\n };\n}\n"],"mappings":";;;;;;;AAOA,IAAAA,oBAAA,GAAAC,uBAAA,CAAAC,OAAA;AAOA,IAAAC,eAAA,GAAAC,sBAAA,CAAAF,OAAA;AAIA,IAAAG,mBAAA,GAAAD,sBAAA,CAAAF,OAAA;AAIA,IAAAI,aAAA,GAAAF,sBAAA,CAAAF,OAAA;AAKwB,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAP,wBAAAO,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,CAAA,CAAAI,GAAA,CAAAP,CAAA,OAAAQ,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAd,CAAA,oBAAAc,CAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAjB,CAAA,EAAAc,CAAA,SAAAI,CAAA,GAAAR,CAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAb,CAAA,EAAAc,CAAA,UAAAI,CAAA,KAAAA,CAAA,CAAAX,GAAA,IAAAW,CAAA,CAAAC,GAAA,IAAAR,MAAA,CAAAC,cAAA,CAAAJ,CAAA,EAAAM,CAAA,EAAAI,CAAA,IAAAV,CAAA,CAAAM,CAAA,IAAAd,CAAA,CAAAc,CAAA,YAAAN,CAAA,CAAAH,OAAA,GAAAL,CAAA,EAAAG,CAAA,IAAAA,CAAA,CAAAgB,GAAA,CAAAnB,CAAA,EAAAQ,CAAA,GAAAA,CAAA;AA2DT,SAASY,mBAAmBA,CAAA,EAGO;EAChD;;EAcA,SAASC,kBAAkBA,CACzBC,IAAoB,EACpBC,YAA2C,EAClB;IACzB,OAAO,IAAAC,uBAAc,EAAkBF,IAAI,EAAEC,YAAY,CAAC;EAC5D;;EAEA;EACA;EAcA,SAASE,gBAAgBA,CACvBH,IAA+B,EAC/BI,MAA+B,EAC/BC,OAA6B,GAAG,CAAC,CAAC,EACT;IACzB,OAAO,IAAAC,qBAAY,EAAgBN,IAAI,EAAEI,MAAM,EAAEC,OAAO,CAAC;EAC3D;;EAEA;EACA;EAgBA,SAASE,sBAAsBA,CAC7BC,EAAU,EACVR,IAA+B,EAC/BI,MAAqC,EACrCC,OAA6B,GAAG,CAAC,CAAC,EACT;IACzB,OAAO,IAAAI,2BAAkB,EAAgBD,EAAE,EAAER,IAAI,EAAEI,MAAM,EAAEC,OAAO,CAAC;EACrE;EAEA,OAAO;IACLK,cAAc,EAAEA,mCAAmC;IACnDC,aAAa,EAAEA,kCAA0B;IACzCC,mBAAmB,EAAEA,4BAAwC;IAC7D;IACAH,kBAAkB,EAAEF,sBAAsB;IAC1CD,YAAY,EAAEH,gBAAgB;IAC9BD,cAAc,EAAEH;EAClB,CAAC;AACH"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import GlobalStateProvider, { getGlobalState, getSsrContext } from "./GlobalStateProvider";
|
|
2
|
-
import useGlobalState from "./useGlobalState";
|
|
3
|
-
import useAsyncCollection from "./useAsyncCollection";
|
|
4
|
-
import useAsyncData from "./useAsyncData";
|
|
5
|
-
export default function withGlobalStateType() {
|
|
6
|
-
// These wrap useGlobalState() with locked-in StateT type.
|
|
7
|
-
|
|
8
|
-
function useGlobalStateWrap(path, initialValue) {
|
|
9
|
-
return useGlobalState(path, initialValue);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// These overloads & implementation wrap useAsyncData() hook to lock-in its
|
|
13
|
-
// underlying StateT.
|
|
14
|
-
function useAsyncDataWrap(path, loader) {
|
|
15
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
16
|
-
return useAsyncData(path, loader, options);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// These overloads & implementation wrap useAsyncCollection() hook to lock-in
|
|
20
|
-
// its underlying StateT.
|
|
21
|
-
function useAsyncCollectionWrap(id, path, loader) {
|
|
22
|
-
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
23
|
-
return useAsyncCollection(id, path, loader, options);
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
getGlobalState: getGlobalState,
|
|
27
|
-
getSsrContext: getSsrContext,
|
|
28
|
-
GlobalStateProvider: GlobalStateProvider,
|
|
29
|
-
// SsrContext, /* CustomSsrContext || SsrContext, */
|
|
30
|
-
useAsyncCollection: useAsyncCollectionWrap,
|
|
31
|
-
useAsyncData: useAsyncDataWrap,
|
|
32
|
-
useGlobalState: useGlobalStateWrap
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
//# sourceMappingURL=withGlobalStateType.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"withGlobalStateType.js","names":["GlobalStateProvider","getGlobalState","getSsrContext","useGlobalState","useAsyncCollection","useAsyncData","withGlobalStateType","useGlobalStateWrap","path","initialValue","useAsyncDataWrap","loader","options","arguments","length","undefined","useAsyncCollectionWrap","id"],"sources":["../../src/withGlobalStateType.ts"],"sourcesContent":["import {\n type ForceT,\n type TypeLock,\n type ValueAtPathT,\n type ValueOrInitializerT,\n} from './utils';\n\nimport GlobalStateProvider, {\n getGlobalState,\n getSsrContext,\n} from './GlobalStateProvider';\n\nimport SsrContext from './SsrContext';\n\nimport useGlobalState, {\n type UseGlobalStateResT,\n} from './useGlobalState';\n\nimport useAsyncCollection, {\n type AsyncCollectionLoaderT,\n} from './useAsyncCollection';\n\nimport useAsyncData, {\n type AsyncDataLoaderT,\n type DataInEnvelopeAtPathT,\n type UseAsyncDataOptionsT,\n type UseAsyncDataResT,\n} from './useAsyncData';\n\ninterface NarrowedUseGlobalStateI<StateT> {\n (): UseGlobalStateResT<StateT>;\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 | false = false, ValueT = unknown>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n ): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n}\n\ninterface NarrowedUseAsyncDataI<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 | false = false, DataT = unknown>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;\n}\n\ninterface NarrowedUseAsyncCollectionI<StateT> {\n <PathT extends null | string | undefined>(\n id: string,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n <Forced extends ForceT | false = false, DataT = unknown>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataT>;\n}\n\ntype WithGlobalStateTypeResT<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n> = {\n getGlobalState: typeof getGlobalState<StateT, SsrContextT>,\n getSsrContext: typeof getSsrContext<SsrContextT>,\n GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>,\n // SsrContext: SsrContext<StateT>,\n useAsyncCollection: NarrowedUseAsyncCollectionI<StateT>,\n useAsyncData: NarrowedUseAsyncDataI<StateT>,\n useGlobalState: NarrowedUseGlobalStateI<StateT>,\n};\n\nexport default function withGlobalStateType<\n StateT,\n SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,\n>(): WithGlobalStateTypeResT<StateT, SsrContextT> {\n // These wrap useGlobalState() with locked-in StateT type.\n\n function useGlobalStateWrap(): UseGlobalStateResT<StateT>;\n\n function useGlobalStateWrap<PathT extends null | string | undefined>(\n path: PathT,\n initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>,\n ): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;\n\n function useGlobalStateWrap<Forced extends ForceT | false = false, ValueT = unknown>(\n path: null | string | undefined,\n initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,\n ): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;\n\n function useGlobalStateWrap(\n path?: null | string,\n initialValue?: ValueOrInitializerT<unknown>,\n ): UseGlobalStateResT<any> {\n return useGlobalState<ForceT, unknown>(path, initialValue);\n }\n\n // These overloads & implementation wrap useAsyncData() hook to lock-in its\n // underlying StateT.\n\n function useAsyncDataWrap<PathT extends null | string | undefined>(\n path: PathT,\n loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n function useAsyncDataWrap<Forced extends ForceT | false = false, DataT = unknown>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;\n\n function useAsyncDataWrap<DataT>(\n path: null | string | undefined,\n loader: AsyncDataLoaderT<DataT>,\n options: UseAsyncDataOptionsT = {},\n ): UseAsyncDataResT<DataT> {\n return useAsyncData<ForceT, DataT>(path, loader, options);\n }\n\n // These overloads & implementation wrap useAsyncCollection() hook to lock-in\n // its underlying StateT.\n\n function useAsyncCollectionWrap<PathT extends null | string | undefined>(\n id: string,\n path: PathT,\n loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;\n\n function useAsyncCollectionWrap<Forced extends ForceT | false = false, DataT = unknown>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,\n options?: UseAsyncDataOptionsT,\n ): UseAsyncDataResT<DataT>;\n\n function useAsyncCollectionWrap<DataT>(\n id: string,\n path: null | string | undefined,\n loader: AsyncCollectionLoaderT<DataT>,\n options: UseAsyncDataOptionsT = {},\n ): UseAsyncDataResT<DataT> {\n return useAsyncCollection<ForceT, DataT>(id, path, loader, options);\n }\n\n return {\n getGlobalState: getGlobalState<StateT, SsrContextT>,\n getSsrContext: getSsrContext<SsrContextT>,\n GlobalStateProvider: GlobalStateProvider<StateT, SsrContextT>,\n // SsrContext, /* CustomSsrContext || SsrContext, */\n useAsyncCollection: useAsyncCollectionWrap,\n useAsyncData: useAsyncDataWrap,\n useGlobalState: useGlobalStateWrap,\n };\n}\n"],"mappings":"AAOA,OAAOA,mBAAmB,IACxBC,cAAc,EACdC,aAAa;AAKf,OAAOC,cAAc;AAIrB,OAAOC,kBAAkB;AAIzB,OAAOC,YAAY;AAgEnB,eAAe,SAASC,mBAAmBA,CAAA,EAGO;EAChD;;EAcA,SAASC,kBAAkBA,CACzBC,IAAoB,EACpBC,YAA2C,EAClB;IACzB,OAAON,cAAc,CAAkBK,IAAI,EAAEC,YAAY,CAAC;EAC5D;;EAEA;EACA;EAcA,SAASC,gBAAgBA,CACvBF,IAA+B,EAC/BG,MAA+B,EAEN;IAAA,IADzBC,OAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAElC,OAAOR,YAAY,CAAgBG,IAAI,EAAEG,MAAM,EAAEC,OAAO,CAAC;EAC3D;;EAEA;EACA;EAgBA,SAASI,sBAAsBA,CAC7BC,EAAU,EACVT,IAA+B,EAC/BG,MAAqC,EAEZ;IAAA,IADzBC,OAA6B,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAElC,OAAOT,kBAAkB,CAAgBa,EAAE,EAAET,IAAI,EAAEG,MAAM,EAAEC,OAAO,CAAC;EACrE;EAEA,OAAO;IACLX,cAAc,EAAEA,cAAmC;IACnDC,aAAa,EAAEA,aAA0B;IACzCF,mBAAmB,EAAEA,mBAAwC;IAC7D;IACAI,kBAAkB,EAAEY,sBAAsB;IAC1CX,YAAY,EAAEK,gBAAgB;IAC9BP,cAAc,EAAEI;EAClB,CAAC;AACH"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type ForceT, type TypeLock, type ValueAtPathT, type ValueOrInitializerT } from './utils';
|
|
2
|
-
import GlobalStateProvider, { getGlobalState, getSsrContext } from './GlobalStateProvider';
|
|
3
|
-
import SsrContext from './SsrContext';
|
|
4
|
-
import { type UseGlobalStateResT } from './useGlobalState';
|
|
5
|
-
import { type AsyncCollectionLoaderT } from './useAsyncCollection';
|
|
6
|
-
import { type AsyncDataLoaderT, type DataInEnvelopeAtPathT, type UseAsyncDataOptionsT, type UseAsyncDataResT } from './useAsyncData';
|
|
7
|
-
interface NarrowedUseGlobalStateI<StateT> {
|
|
8
|
-
(): UseGlobalStateResT<StateT>;
|
|
9
|
-
<PathT extends null | string | undefined>(path: PathT, initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;
|
|
10
|
-
<Forced extends ForceT | false = false, ValueT = unknown>(path: null | string | undefined, initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;
|
|
11
|
-
}
|
|
12
|
-
interface NarrowedUseAsyncDataI<StateT> {
|
|
13
|
-
<PathT extends null | string | undefined>(path: PathT, loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
14
|
-
<Forced extends ForceT | false = false, DataT = unknown>(path: null | string | undefined, loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;
|
|
15
|
-
}
|
|
16
|
-
interface NarrowedUseAsyncCollectionI<StateT> {
|
|
17
|
-
<PathT extends null | string | undefined>(id: string, path: PathT, loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
18
|
-
<Forced extends ForceT | false = false, DataT = unknown>(id: string, path: null | string | undefined, loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>, options?: UseAsyncDataOptionsT): UseAsyncDataResT<DataT>;
|
|
19
|
-
}
|
|
20
|
-
type WithGlobalStateTypeResT<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>> = {
|
|
21
|
-
getGlobalState: typeof getGlobalState<StateT, SsrContextT>;
|
|
22
|
-
getSsrContext: typeof getSsrContext<SsrContextT>;
|
|
23
|
-
GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>;
|
|
24
|
-
useAsyncCollection: NarrowedUseAsyncCollectionI<StateT>;
|
|
25
|
-
useAsyncData: NarrowedUseAsyncDataI<StateT>;
|
|
26
|
-
useGlobalState: NarrowedUseGlobalStateI<StateT>;
|
|
27
|
-
};
|
|
28
|
-
export default function withGlobalStateType<StateT, SsrContextT extends SsrContext<StateT> = SsrContext<StateT>>(): WithGlobalStateTypeResT<StateT, SsrContextT>;
|
|
29
|
-
export {};
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ForceT,
|
|
3
|
-
type TypeLock,
|
|
4
|
-
type ValueAtPathT,
|
|
5
|
-
type ValueOrInitializerT,
|
|
6
|
-
} from './utils';
|
|
7
|
-
|
|
8
|
-
import GlobalStateProvider, {
|
|
9
|
-
getGlobalState,
|
|
10
|
-
getSsrContext,
|
|
11
|
-
} from './GlobalStateProvider';
|
|
12
|
-
|
|
13
|
-
import SsrContext from './SsrContext';
|
|
14
|
-
|
|
15
|
-
import useGlobalState, {
|
|
16
|
-
type UseGlobalStateResT,
|
|
17
|
-
} from './useGlobalState';
|
|
18
|
-
|
|
19
|
-
import useAsyncCollection, {
|
|
20
|
-
type AsyncCollectionLoaderT,
|
|
21
|
-
} from './useAsyncCollection';
|
|
22
|
-
|
|
23
|
-
import useAsyncData, {
|
|
24
|
-
type AsyncDataLoaderT,
|
|
25
|
-
type DataInEnvelopeAtPathT,
|
|
26
|
-
type UseAsyncDataOptionsT,
|
|
27
|
-
type UseAsyncDataResT,
|
|
28
|
-
} from './useAsyncData';
|
|
29
|
-
|
|
30
|
-
interface NarrowedUseGlobalStateI<StateT> {
|
|
31
|
-
(): UseGlobalStateResT<StateT>;
|
|
32
|
-
|
|
33
|
-
<PathT extends null | string | undefined>(
|
|
34
|
-
path: PathT,
|
|
35
|
-
initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>,
|
|
36
|
-
): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;
|
|
37
|
-
|
|
38
|
-
<Forced extends ForceT | false = false, ValueT = unknown>(
|
|
39
|
-
path: null | string | undefined,
|
|
40
|
-
initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,
|
|
41
|
-
): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
interface NarrowedUseAsyncDataI<StateT> {
|
|
45
|
-
<PathT extends null | string | undefined>(
|
|
46
|
-
path: PathT,
|
|
47
|
-
loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
|
|
48
|
-
options?: UseAsyncDataOptionsT,
|
|
49
|
-
): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
50
|
-
|
|
51
|
-
<Forced extends ForceT | false = false, DataT = unknown>(
|
|
52
|
-
path: null | string | undefined,
|
|
53
|
-
loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,
|
|
54
|
-
options?: UseAsyncDataOptionsT,
|
|
55
|
-
): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
interface NarrowedUseAsyncCollectionI<StateT> {
|
|
59
|
-
<PathT extends null | string | undefined>(
|
|
60
|
-
id: string,
|
|
61
|
-
path: PathT,
|
|
62
|
-
loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
|
|
63
|
-
options?: UseAsyncDataOptionsT,
|
|
64
|
-
): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
65
|
-
|
|
66
|
-
<Forced extends ForceT | false = false, DataT = unknown>(
|
|
67
|
-
id: string,
|
|
68
|
-
path: null | string | undefined,
|
|
69
|
-
loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,
|
|
70
|
-
options?: UseAsyncDataOptionsT,
|
|
71
|
-
): UseAsyncDataResT<DataT>;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
type WithGlobalStateTypeResT<
|
|
75
|
-
StateT,
|
|
76
|
-
SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,
|
|
77
|
-
> = {
|
|
78
|
-
getGlobalState: typeof getGlobalState<StateT, SsrContextT>,
|
|
79
|
-
getSsrContext: typeof getSsrContext<SsrContextT>,
|
|
80
|
-
GlobalStateProvider: typeof GlobalStateProvider<StateT, SsrContextT>,
|
|
81
|
-
// SsrContext: SsrContext<StateT>,
|
|
82
|
-
useAsyncCollection: NarrowedUseAsyncCollectionI<StateT>,
|
|
83
|
-
useAsyncData: NarrowedUseAsyncDataI<StateT>,
|
|
84
|
-
useGlobalState: NarrowedUseGlobalStateI<StateT>,
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export default function withGlobalStateType<
|
|
88
|
-
StateT,
|
|
89
|
-
SsrContextT extends SsrContext<StateT> = SsrContext<StateT>,
|
|
90
|
-
>(): WithGlobalStateTypeResT<StateT, SsrContextT> {
|
|
91
|
-
// These wrap useGlobalState() with locked-in StateT type.
|
|
92
|
-
|
|
93
|
-
function useGlobalStateWrap(): UseGlobalStateResT<StateT>;
|
|
94
|
-
|
|
95
|
-
function useGlobalStateWrap<PathT extends null | string | undefined>(
|
|
96
|
-
path: PathT,
|
|
97
|
-
initialValue?: ValueOrInitializerT<ValueAtPathT<StateT, PathT, never>>,
|
|
98
|
-
): UseGlobalStateResT<ValueAtPathT<StateT, PathT, void>>;
|
|
99
|
-
|
|
100
|
-
function useGlobalStateWrap<Forced extends ForceT | false = false, ValueT = unknown>(
|
|
101
|
-
path: null | string | undefined,
|
|
102
|
-
initialValue?: ValueOrInitializerT<TypeLock<Forced, never, ValueT>>,
|
|
103
|
-
): UseGlobalStateResT<TypeLock<Forced, void, ValueT>>;
|
|
104
|
-
|
|
105
|
-
function useGlobalStateWrap(
|
|
106
|
-
path?: null | string,
|
|
107
|
-
initialValue?: ValueOrInitializerT<unknown>,
|
|
108
|
-
): UseGlobalStateResT<any> {
|
|
109
|
-
return useGlobalState<ForceT, unknown>(path, initialValue);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// These overloads & implementation wrap useAsyncData() hook to lock-in its
|
|
113
|
-
// underlying StateT.
|
|
114
|
-
|
|
115
|
-
function useAsyncDataWrap<PathT extends null | string | undefined>(
|
|
116
|
-
path: PathT,
|
|
117
|
-
loader: AsyncDataLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
|
|
118
|
-
options?: UseAsyncDataOptionsT,
|
|
119
|
-
): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
120
|
-
|
|
121
|
-
function useAsyncDataWrap<Forced extends ForceT | false = false, DataT = unknown>(
|
|
122
|
-
path: null | string | undefined,
|
|
123
|
-
loader: AsyncDataLoaderT<TypeLock<Forced, void, DataT>>,
|
|
124
|
-
options?: UseAsyncDataOptionsT,
|
|
125
|
-
): UseAsyncDataResT<TypeLock<Forced, never, DataT>>;
|
|
126
|
-
|
|
127
|
-
function useAsyncDataWrap<DataT>(
|
|
128
|
-
path: null | string | undefined,
|
|
129
|
-
loader: AsyncDataLoaderT<DataT>,
|
|
130
|
-
options: UseAsyncDataOptionsT = {},
|
|
131
|
-
): UseAsyncDataResT<DataT> {
|
|
132
|
-
return useAsyncData<ForceT, DataT>(path, loader, options);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// These overloads & implementation wrap useAsyncCollection() hook to lock-in
|
|
136
|
-
// its underlying StateT.
|
|
137
|
-
|
|
138
|
-
function useAsyncCollectionWrap<PathT extends null | string | undefined>(
|
|
139
|
-
id: string,
|
|
140
|
-
path: PathT,
|
|
141
|
-
loader: AsyncCollectionLoaderT<DataInEnvelopeAtPathT<StateT, PathT>>,
|
|
142
|
-
options?: UseAsyncDataOptionsT,
|
|
143
|
-
): UseAsyncDataResT<DataInEnvelopeAtPathT<StateT, PathT>>;
|
|
144
|
-
|
|
145
|
-
function useAsyncCollectionWrap<Forced extends ForceT | false = false, DataT = unknown>(
|
|
146
|
-
id: string,
|
|
147
|
-
path: null | string | undefined,
|
|
148
|
-
loader: AsyncCollectionLoaderT<TypeLock<Forced, void, DataT>>,
|
|
149
|
-
options?: UseAsyncDataOptionsT,
|
|
150
|
-
): UseAsyncDataResT<DataT>;
|
|
151
|
-
|
|
152
|
-
function useAsyncCollectionWrap<DataT>(
|
|
153
|
-
id: string,
|
|
154
|
-
path: null | string | undefined,
|
|
155
|
-
loader: AsyncCollectionLoaderT<DataT>,
|
|
156
|
-
options: UseAsyncDataOptionsT = {},
|
|
157
|
-
): UseAsyncDataResT<DataT> {
|
|
158
|
-
return useAsyncCollection<ForceT, DataT>(id, path, loader, options);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return {
|
|
162
|
-
getGlobalState: getGlobalState<StateT, SsrContextT>,
|
|
163
|
-
getSsrContext: getSsrContext<SsrContextT>,
|
|
164
|
-
GlobalStateProvider: GlobalStateProvider<StateT, SsrContextT>,
|
|
165
|
-
// SsrContext, /* CustomSsrContext || SsrContext, */
|
|
166
|
-
useAsyncCollection: useAsyncCollectionWrap,
|
|
167
|
-
useAsyncData: useAsyncDataWrap,
|
|
168
|
-
useGlobalState: useGlobalStateWrap,
|
|
169
|
-
};
|
|
170
|
-
}
|