Server: Phase 2 (REVIEW not respected yet)
This commit is contained in:
1 parent
5d16ded553
commit
142b47674d
4271 files changed
+1203269
No files matched your search
+28
@@ -0,0 +1,28 @@
|
||||
const require_useSelector = require('./useSelector.cjs');
|
||||
let react = require("react");
|
||||
|
||||
//#region src/_useStore.ts
|
||||
/**
|
||||
* Experimental combined read+write hook for stores, mirroring useAtom's tuple
|
||||
* pattern.
|
||||
*
|
||||
* Returns `[selected, actions]` when the store has an actions factory, or
|
||||
* `[selected, setState]` for plain stores.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* // Store with actions
|
||||
* const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)
|
||||
*
|
||||
* // Store without actions
|
||||
* const [count, setState] = _useStore(plainStore, (s) => s)
|
||||
* setState((prev) => prev + 1)
|
||||
* ```
|
||||
*/
|
||||
function _useStore(store, selector, options) {
|
||||
return [require_useSelector.useSelector(store, selector, options), (0, react.useMemo)(() => store.actions ?? store.setState, [store])];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports._useStore = _useStore;
|
||||
//# sourceMappingURL=_useStore.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"_useStore.cjs","names":["useSelector"],"sources":["../src/_useStore.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { useSelector } from './useSelector'\nimport type { Store, StoreActionMap } from '@tanstack/store'\nimport type { UseSelectorOptions } from './useSelector'\n\n/**\n * Experimental combined read+write hook for stores, mirroring useAtom's tuple\n * pattern.\n *\n * Returns `[selected, actions]` when the store has an actions factory, or\n * `[selected, setState]` for plain stores.\n *\n * @example\n * ```tsx\n * // Store with actions\n * const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)\n *\n * // Store without actions\n * const [count, setState] = _useStore(plainStore, (s) => s)\n * setState((prev) => prev + 1)\n * ```\n */\n/* eslint-disable react-hooks/rules-of-hooks, @eslint-react/rules-of-hooks -- experimental API with underscore prefix */\nexport function _useStore<\n TState,\n TActions extends StoreActionMap,\n TSelected = NoInfer<TState>,\n>(\n store: Store<TState, TActions>,\n selector: (state: NoInfer<TState>) => TSelected,\n options?: UseSelectorOptions<TSelected>,\n): [\n TSelected,\n [TActions] extends [never] ? Store<TState>['setState'] : TActions,\n] {\n const selected = useSelector(store, selector, options)\n const actionsOrSetState = useMemo(\n () => (store.actions as StoreActionMap | undefined) ?? store.setState,\n [store],\n ) as [TActions] extends [never] ? Store<TState>['setState'] : TActions\n\n return [selected, actionsOrSetState]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,UAKd,OACA,UACA,SAIA;AAOA,QAAO,CANUA,gCAAY,OAAO,UAAU,QAAQ,2BAE7C,MAAM,WAA0C,MAAM,UAC7D,CAAC,MAAM,CACR,CAEmC"}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { UseSelectorOptions } from "./useSelector.cjs";
|
||||
import { Store, StoreActionMap } from "@tanstack/store";
|
||||
|
||||
//#region src/_useStore.d.ts
|
||||
/**
|
||||
* Experimental combined read+write hook for stores, mirroring useAtom's tuple
|
||||
* pattern.
|
||||
*
|
||||
* Returns `[selected, actions]` when the store has an actions factory, or
|
||||
* `[selected, setState]` for plain stores.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* // Store with actions
|
||||
* const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)
|
||||
*
|
||||
* // Store without actions
|
||||
* const [count, setState] = _useStore(plainStore, (s) => s)
|
||||
* setState((prev) => prev + 1)
|
||||
* ```
|
||||
*/
|
||||
declare function _useStore<TState, TActions extends StoreActionMap, TSelected = NoInfer<TState>>(store: Store<TState, TActions>, selector: (state: NoInfer<TState>) => TSelected, options?: UseSelectorOptions<TSelected>): [TSelected, [TActions] extends [never] ? Store<TState>['setState'] : TActions];
|
||||
//#endregion
|
||||
export { _useStore };
|
||||
//# sourceMappingURL=_useStore.d.cts.map
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
import { UseSelectorOptions } from "./useSelector.js";
|
||||
import { Store, StoreActionMap } from "@tanstack/store";
|
||||
|
||||
//#region src/_useStore.d.ts
|
||||
/**
|
||||
* Experimental combined read+write hook for stores, mirroring useAtom's tuple
|
||||
* pattern.
|
||||
*
|
||||
* Returns `[selected, actions]` when the store has an actions factory, or
|
||||
* `[selected, setState]` for plain stores.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* // Store with actions
|
||||
* const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)
|
||||
*
|
||||
* // Store without actions
|
||||
* const [count, setState] = _useStore(plainStore, (s) => s)
|
||||
* setState((prev) => prev + 1)
|
||||
* ```
|
||||
*/
|
||||
declare function _useStore<TState, TActions extends StoreActionMap, TSelected = NoInfer<TState>>(store: Store<TState, TActions>, selector: (state: NoInfer<TState>) => TSelected, options?: UseSelectorOptions<TSelected>): [TSelected, [TActions] extends [never] ? Store<TState>['setState'] : TActions];
|
||||
//#endregion
|
||||
export { _useStore };
|
||||
//# sourceMappingURL=_useStore.d.ts.map
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
import { useSelector } from "./useSelector.js";
|
||||
import { useMemo } from "react";
|
||||
|
||||
//#region src/_useStore.ts
|
||||
/**
|
||||
* Experimental combined read+write hook for stores, mirroring useAtom's tuple
|
||||
* pattern.
|
||||
*
|
||||
* Returns `[selected, actions]` when the store has an actions factory, or
|
||||
* `[selected, setState]` for plain stores.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* // Store with actions
|
||||
* const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)
|
||||
*
|
||||
* // Store without actions
|
||||
* const [count, setState] = _useStore(plainStore, (s) => s)
|
||||
* setState((prev) => prev + 1)
|
||||
* ```
|
||||
*/
|
||||
function _useStore(store, selector, options) {
|
||||
return [useSelector(store, selector, options), useMemo(() => store.actions ?? store.setState, [store])];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { _useStore };
|
||||
//# sourceMappingURL=_useStore.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"_useStore.js","names":[],"sources":["../src/_useStore.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { useSelector } from './useSelector'\nimport type { Store, StoreActionMap } from '@tanstack/store'\nimport type { UseSelectorOptions } from './useSelector'\n\n/**\n * Experimental combined read+write hook for stores, mirroring useAtom's tuple\n * pattern.\n *\n * Returns `[selected, actions]` when the store has an actions factory, or\n * `[selected, setState]` for plain stores.\n *\n * @example\n * ```tsx\n * // Store with actions\n * const [cats, { addCat }] = _useStore(petStore, (s) => s.cats)\n *\n * // Store without actions\n * const [count, setState] = _useStore(plainStore, (s) => s)\n * setState((prev) => prev + 1)\n * ```\n */\n/* eslint-disable react-hooks/rules-of-hooks, @eslint-react/rules-of-hooks -- experimental API with underscore prefix */\nexport function _useStore<\n TState,\n TActions extends StoreActionMap,\n TSelected = NoInfer<TState>,\n>(\n store: Store<TState, TActions>,\n selector: (state: NoInfer<TState>) => TSelected,\n options?: UseSelectorOptions<TSelected>,\n): [\n TSelected,\n [TActions] extends [never] ? Store<TState>['setState'] : TActions,\n] {\n const selected = useSelector(store, selector, options)\n const actionsOrSetState = useMemo(\n () => (store.actions as StoreActionMap | undefined) ?? store.setState,\n [store],\n ) as [TActions] extends [never] ? Store<TState>['setState'] : TActions\n\n return [selected, actionsOrSetState]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAuBA,SAAgB,UAKd,OACA,UACA,SAIA;AAOA,QAAO,CANU,YAAY,OAAO,UAAU,QAAQ,EAC5B,cACjB,MAAM,WAA0C,MAAM,UAC7D,CAAC,MAAM,CACR,CAEmC"}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
let react = require("react");
|
||||
let react_jsx_runtime = require("react/jsx-runtime");
|
||||
|
||||
//#region src/createStoreContext.tsx
|
||||
/**
|
||||
* Creates a typed React context for sharing a bundle of atoms and stores with a subtree.
|
||||
*
|
||||
* The returned `StoreProvider` only transports the provided object through
|
||||
* React context. Consumers destructure the contextual atoms and stores, then
|
||||
* compose them with the existing hooks like {@link useSelector},
|
||||
* {@link useSelector} and {@link useAtom}.
|
||||
*
|
||||
* The object shape is preserved exactly, so keyed atoms and stores remain fully
|
||||
* typed when read back with `useStoreContext()`.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { StoreProvider, useStoreContext } = createStoreContext<{
|
||||
* countAtom: Atom<number>
|
||||
* totalsStore: Store<{ count: number }>
|
||||
* }>()
|
||||
*
|
||||
* function CountButton() {
|
||||
* const { countAtom, totalsStore } = useStoreContext()
|
||||
* const count = useSelector(countAtom)
|
||||
* const total = useSelector(totalsStore, (state) => state.count)
|
||||
*
|
||||
* return (
|
||||
* <button
|
||||
* type="button"
|
||||
* onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}
|
||||
* >
|
||||
* {count} / {total}
|
||||
* </button>
|
||||
* )
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @throws When `useStoreContext()` is called outside the matching `StoreProvider`.
|
||||
*/
|
||||
function createStoreContext() {
|
||||
const Context = (0, react.createContext)(null);
|
||||
Context.displayName = "StoreContext";
|
||||
function StoreProvider({ children, value }) {
|
||||
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Context.Provider, {
|
||||
value,
|
||||
children
|
||||
});
|
||||
}
|
||||
function useStoreContext() {
|
||||
const value = (0, react.useContext)(Context);
|
||||
if (value === null) throw new Error("Missing StoreProvider for StoreContext");
|
||||
return value;
|
||||
}
|
||||
return {
|
||||
StoreProvider,
|
||||
useStoreContext
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.createStoreContext = createStoreContext;
|
||||
//# sourceMappingURL=createStoreContext.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"createStoreContext.cjs","names":[],"sources":["../src/createStoreContext.tsx"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport type { PropsWithChildren, ReactElement } from 'react'\n\n/**\n * Creates a typed React context for sharing a bundle of atoms and stores with a subtree.\n *\n * The returned `StoreProvider` only transports the provided object through\n * React context. Consumers destructure the contextual atoms and stores, then\n * compose them with the existing hooks like {@link useSelector},\n * {@link useSelector} and {@link useAtom}.\n *\n * The object shape is preserved exactly, so keyed atoms and stores remain fully\n * typed when read back with `useStoreContext()`.\n *\n * @example\n * ```tsx\n * const { StoreProvider, useStoreContext } = createStoreContext<{\n * countAtom: Atom<number>\n * totalsStore: Store<{ count: number }>\n * }>()\n *\n * function CountButton() {\n * const { countAtom, totalsStore } = useStoreContext()\n * const count = useSelector(countAtom)\n * const total = useSelector(totalsStore, (state) => state.count)\n *\n * return (\n * <button\n * type=\"button\"\n * onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}\n * >\n * {count} / {total}\n * </button>\n * )\n * }\n * ```\n *\n * @throws When `useStoreContext()` is called outside the matching `StoreProvider`.\n */\nexport function createStoreContext<TValue extends object>(): {\n StoreProvider: (\n props: {\n value: TValue\n } & PropsWithChildren,\n ) => ReactElement\n useStoreContext: () => TValue\n} {\n const Context = createContext<TValue | null>(null)\n Context.displayName = 'StoreContext'\n\n // eslint-disable-next-line @eslint-react/component-hook-factories\n function StoreProvider({\n children,\n value,\n }: PropsWithChildren<{\n value: TValue\n }>) {\n // eslint-disable-next-line @eslint-react/no-context-provider\n return <Context.Provider value={value}>{children}</Context.Provider>\n }\n\n // eslint-disable-next-line @eslint-react/component-hook-factories\n function useStoreContext() {\n // eslint-disable-next-line @eslint-react/no-use-context\n const value = useContext(Context)\n\n if (value === null) {\n throw new Error('Missing StoreProvider for StoreContext')\n }\n\n return value\n }\n\n return {\n StoreProvider,\n useStoreContext,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,qBAOd;CACA,MAAM,mCAAuC,KAAK;AAClD,SAAQ,cAAc;CAGtB,SAAS,cAAc,EACrB,UACA,SAGE;AAEF,SAAO,2CAAC,QAAQ,UAAT;GAAyB;GAAQ;GAA4B;;CAItE,SAAS,kBAAkB;EAEzB,MAAM,8BAAmB,QAAQ;AAEjC,MAAI,UAAU,KACZ,OAAM,IAAI,MAAM,yCAAyC;AAG3D,SAAO;;AAGT,QAAO;EACL;EACA;EACD"}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import { PropsWithChildren, ReactElement } from "react";
|
||||
|
||||
//#region src/createStoreContext.d.ts
|
||||
/**
|
||||
* Creates a typed React context for sharing a bundle of atoms and stores with a subtree.
|
||||
*
|
||||
* The returned `StoreProvider` only transports the provided object through
|
||||
* React context. Consumers destructure the contextual atoms and stores, then
|
||||
* compose them with the existing hooks like {@link useSelector},
|
||||
* {@link useSelector} and {@link useAtom}.
|
||||
*
|
||||
* The object shape is preserved exactly, so keyed atoms and stores remain fully
|
||||
* typed when read back with `useStoreContext()`.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { StoreProvider, useStoreContext } = createStoreContext<{
|
||||
* countAtom: Atom<number>
|
||||
* totalsStore: Store<{ count: number }>
|
||||
* }>()
|
||||
*
|
||||
* function CountButton() {
|
||||
* const { countAtom, totalsStore } = useStoreContext()
|
||||
* const count = useSelector(countAtom)
|
||||
* const total = useSelector(totalsStore, (state) => state.count)
|
||||
*
|
||||
* return (
|
||||
* <button
|
||||
* type="button"
|
||||
* onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}
|
||||
* >
|
||||
* {count} / {total}
|
||||
* </button>
|
||||
* )
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @throws When `useStoreContext()` is called outside the matching `StoreProvider`.
|
||||
*/
|
||||
declare function createStoreContext<TValue extends object>(): {
|
||||
StoreProvider: (props: {
|
||||
value: TValue;
|
||||
} & PropsWithChildren) => ReactElement;
|
||||
useStoreContext: () => TValue;
|
||||
};
|
||||
//#endregion
|
||||
export { createStoreContext };
|
||||
//# sourceMappingURL=createStoreContext.d.cts.map
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
import { PropsWithChildren, ReactElement } from "react";
|
||||
|
||||
//#region src/createStoreContext.d.ts
|
||||
/**
|
||||
* Creates a typed React context for sharing a bundle of atoms and stores with a subtree.
|
||||
*
|
||||
* The returned `StoreProvider` only transports the provided object through
|
||||
* React context. Consumers destructure the contextual atoms and stores, then
|
||||
* compose them with the existing hooks like {@link useSelector},
|
||||
* {@link useSelector} and {@link useAtom}.
|
||||
*
|
||||
* The object shape is preserved exactly, so keyed atoms and stores remain fully
|
||||
* typed when read back with `useStoreContext()`.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { StoreProvider, useStoreContext } = createStoreContext<{
|
||||
* countAtom: Atom<number>
|
||||
* totalsStore: Store<{ count: number }>
|
||||
* }>()
|
||||
*
|
||||
* function CountButton() {
|
||||
* const { countAtom, totalsStore } = useStoreContext()
|
||||
* const count = useSelector(countAtom)
|
||||
* const total = useSelector(totalsStore, (state) => state.count)
|
||||
*
|
||||
* return (
|
||||
* <button
|
||||
* type="button"
|
||||
* onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}
|
||||
* >
|
||||
* {count} / {total}
|
||||
* </button>
|
||||
* )
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @throws When `useStoreContext()` is called outside the matching `StoreProvider`.
|
||||
*/
|
||||
declare function createStoreContext<TValue extends object>(): {
|
||||
StoreProvider: (props: {
|
||||
value: TValue;
|
||||
} & PropsWithChildren) => ReactElement;
|
||||
useStoreContext: () => TValue;
|
||||
};
|
||||
//#endregion
|
||||
export { createStoreContext };
|
||||
//# sourceMappingURL=createStoreContext.d.ts.map
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
import { createContext, useContext } from "react";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
|
||||
//#region src/createStoreContext.tsx
|
||||
/**
|
||||
* Creates a typed React context for sharing a bundle of atoms and stores with a subtree.
|
||||
*
|
||||
* The returned `StoreProvider` only transports the provided object through
|
||||
* React context. Consumers destructure the contextual atoms and stores, then
|
||||
* compose them with the existing hooks like {@link useSelector},
|
||||
* {@link useSelector} and {@link useAtom}.
|
||||
*
|
||||
* The object shape is preserved exactly, so keyed atoms and stores remain fully
|
||||
* typed when read back with `useStoreContext()`.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const { StoreProvider, useStoreContext } = createStoreContext<{
|
||||
* countAtom: Atom<number>
|
||||
* totalsStore: Store<{ count: number }>
|
||||
* }>()
|
||||
*
|
||||
* function CountButton() {
|
||||
* const { countAtom, totalsStore } = useStoreContext()
|
||||
* const count = useSelector(countAtom)
|
||||
* const total = useSelector(totalsStore, (state) => state.count)
|
||||
*
|
||||
* return (
|
||||
* <button
|
||||
* type="button"
|
||||
* onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}
|
||||
* >
|
||||
* {count} / {total}
|
||||
* </button>
|
||||
* )
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* @throws When `useStoreContext()` is called outside the matching `StoreProvider`.
|
||||
*/
|
||||
function createStoreContext() {
|
||||
const Context = createContext(null);
|
||||
Context.displayName = "StoreContext";
|
||||
function StoreProvider({ children, value }) {
|
||||
return /* @__PURE__ */ jsx(Context.Provider, {
|
||||
value,
|
||||
children
|
||||
});
|
||||
}
|
||||
function useStoreContext() {
|
||||
const value = useContext(Context);
|
||||
if (value === null) throw new Error("Missing StoreProvider for StoreContext");
|
||||
return value;
|
||||
}
|
||||
return {
|
||||
StoreProvider,
|
||||
useStoreContext
|
||||
};
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { createStoreContext };
|
||||
//# sourceMappingURL=createStoreContext.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"createStoreContext.js","names":[],"sources":["../src/createStoreContext.tsx"],"sourcesContent":["import { createContext, useContext } from 'react'\nimport type { PropsWithChildren, ReactElement } from 'react'\n\n/**\n * Creates a typed React context for sharing a bundle of atoms and stores with a subtree.\n *\n * The returned `StoreProvider` only transports the provided object through\n * React context. Consumers destructure the contextual atoms and stores, then\n * compose them with the existing hooks like {@link useSelector},\n * {@link useSelector} and {@link useAtom}.\n *\n * The object shape is preserved exactly, so keyed atoms and stores remain fully\n * typed when read back with `useStoreContext()`.\n *\n * @example\n * ```tsx\n * const { StoreProvider, useStoreContext } = createStoreContext<{\n * countAtom: Atom<number>\n * totalsStore: Store<{ count: number }>\n * }>()\n *\n * function CountButton() {\n * const { countAtom, totalsStore } = useStoreContext()\n * const count = useSelector(countAtom)\n * const total = useSelector(totalsStore, (state) => state.count)\n *\n * return (\n * <button\n * type=\"button\"\n * onClick={() => totalsStore.setState((state) => ({ ...state, count: state.count + 1 }))}\n * >\n * {count} / {total}\n * </button>\n * )\n * }\n * ```\n *\n * @throws When `useStoreContext()` is called outside the matching `StoreProvider`.\n */\nexport function createStoreContext<TValue extends object>(): {\n StoreProvider: (\n props: {\n value: TValue\n } & PropsWithChildren,\n ) => ReactElement\n useStoreContext: () => TValue\n} {\n const Context = createContext<TValue | null>(null)\n Context.displayName = 'StoreContext'\n\n // eslint-disable-next-line @eslint-react/component-hook-factories\n function StoreProvider({\n children,\n value,\n }: PropsWithChildren<{\n value: TValue\n }>) {\n // eslint-disable-next-line @eslint-react/no-context-provider\n return <Context.Provider value={value}>{children}</Context.Provider>\n }\n\n // eslint-disable-next-line @eslint-react/component-hook-factories\n function useStoreContext() {\n // eslint-disable-next-line @eslint-react/no-use-context\n const value = useContext(Context)\n\n if (value === null) {\n throw new Error('Missing StoreProvider for StoreContext')\n }\n\n return value\n }\n\n return {\n StoreProvider,\n useStoreContext,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,SAAgB,qBAOd;CACA,MAAM,UAAU,cAA6B,KAAK;AAClD,SAAQ,cAAc;CAGtB,SAAS,cAAc,EACrB,UACA,SAGE;AAEF,SAAO,oBAAC,QAAQ,UAAT;GAAyB;GAAQ;GAA4B;;CAItE,SAAS,kBAAkB;EAEzB,MAAM,QAAQ,WAAW,QAAQ;AAEjC,MAAI,UAAU,KACZ,OAAM,IAAI,MAAM,yCAAyC;AAG3D,SAAO;;AAGT,QAAO;EACL;EACA;EACD"}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
||||
const require_createStoreContext = require('./createStoreContext.cjs');
|
||||
const require_useCreateAtom = require('./useCreateAtom.cjs');
|
||||
const require_useCreateStore = require('./useCreateStore.cjs');
|
||||
const require_useSelector = require('./useSelector.cjs');
|
||||
const require_useAtom = require('./useAtom.cjs');
|
||||
const require__useStore = require('./_useStore.cjs');
|
||||
const require_useStore = require('./useStore.cjs');
|
||||
|
||||
exports._useStore = require__useStore._useStore;
|
||||
exports.createStoreContext = require_createStoreContext.createStoreContext;
|
||||
exports.useAtom = require_useAtom.useAtom;
|
||||
exports.useCreateAtom = require_useCreateAtom.useCreateAtom;
|
||||
exports.useCreateStore = require_useCreateStore.useCreateStore;
|
||||
exports.useSelector = require_useSelector.useSelector;
|
||||
exports.useStore = require_useStore.useStore;
|
||||
var _tanstack_store = require("@tanstack/store");
|
||||
Object.keys(_tanstack_store).forEach(function (k) {
|
||||
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
||||
enumerable: true,
|
||||
get: function () { return _tanstack_store[k]; }
|
||||
});
|
||||
});
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { createStoreContext } from "./createStoreContext.cjs";
|
||||
import { useCreateAtom } from "./useCreateAtom.cjs";
|
||||
import { useCreateStore } from "./useCreateStore.cjs";
|
||||
import { UseSelectorOptions, useSelector } from "./useSelector.cjs";
|
||||
import { useAtom } from "./useAtom.cjs";
|
||||
import { _useStore } from "./_useStore.cjs";
|
||||
import { useStore } from "./useStore.cjs";
|
||||
export * from "@tanstack/store";
|
||||
export { UseSelectorOptions, _useStore, createStoreContext, useAtom, useCreateAtom, useCreateStore, useSelector, useStore };
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
import { createStoreContext } from "./createStoreContext.js";
|
||||
import { useCreateAtom } from "./useCreateAtom.js";
|
||||
import { useCreateStore } from "./useCreateStore.js";
|
||||
import { UseSelectorOptions, useSelector } from "./useSelector.js";
|
||||
import { useAtom } from "./useAtom.js";
|
||||
import { _useStore } from "./_useStore.js";
|
||||
import { useStore } from "./useStore.js";
|
||||
export * from "@tanstack/store";
|
||||
export { UseSelectorOptions, _useStore, createStoreContext, useAtom, useCreateAtom, useCreateStore, useSelector, useStore };
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { createStoreContext } from "./createStoreContext.js";
|
||||
import { useCreateAtom } from "./useCreateAtom.js";
|
||||
import { useCreateStore } from "./useCreateStore.js";
|
||||
import { useSelector } from "./useSelector.js";
|
||||
import { useAtom } from "./useAtom.js";
|
||||
import { _useStore } from "./_useStore.js";
|
||||
import { useStore } from "./useStore.js";
|
||||
|
||||
export * from "@tanstack/store"
|
||||
|
||||
export { _useStore, createStoreContext, useAtom, useCreateAtom, useCreateStore, useSelector, useStore };
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
const require_useSelector = require('./useSelector.cjs');
|
||||
|
||||
//#region src/useAtom.ts
|
||||
/**
|
||||
* Returns the current atom value together with a stable setter.
|
||||
*
|
||||
* This is the writable-atom convenience hook for components that need to both
|
||||
* read and update the same atom.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const [count, setCount] = useAtom(countAtom)
|
||||
* ```
|
||||
*/
|
||||
function useAtom(atom, options) {
|
||||
return [require_useSelector.useSelector(atom, void 0, options), atom.set];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.useAtom = useAtom;
|
||||
//# sourceMappingURL=useAtom.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useAtom.cjs","names":["useSelector"],"sources":["../src/useAtom.ts"],"sourcesContent":["import { useSelector } from './useSelector'\nimport type { Atom } from '@tanstack/store'\nimport type { UseSelectorOptions } from './useSelector'\n\n/**\n * Returns the current atom value together with a stable setter.\n *\n * This is the writable-atom convenience hook for components that need to both\n * read and update the same atom.\n *\n * @example\n * ```tsx\n * const [count, setCount] = useAtom(countAtom)\n * ```\n */\nexport function useAtom<TValue>(\n atom: Atom<TValue>,\n options?: UseSelectorOptions<TValue>,\n): [TValue, Atom<TValue>['set']] {\n const value = useSelector(atom, undefined, options)\n\n return [value, atom.set]\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,QACd,MACA,SAC+B;AAG/B,QAAO,CAFOA,gCAAY,MAAM,QAAW,QAAQ,EAEpC,KAAK,IAAI"}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { UseSelectorOptions } from "./useSelector.cjs";
|
||||
import { Atom } from "@tanstack/store";
|
||||
|
||||
//#region src/useAtom.d.ts
|
||||
/**
|
||||
* Returns the current atom value together with a stable setter.
|
||||
*
|
||||
* This is the writable-atom convenience hook for components that need to both
|
||||
* read and update the same atom.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const [count, setCount] = useAtom(countAtom)
|
||||
* ```
|
||||
*/
|
||||
declare function useAtom<TValue>(atom: Atom<TValue>, options?: UseSelectorOptions<TValue>): [TValue, Atom<TValue>['set']];
|
||||
//#endregion
|
||||
export { useAtom };
|
||||
//# sourceMappingURL=useAtom.d.cts.map
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
import { UseSelectorOptions } from "./useSelector.js";
|
||||
import { Atom } from "@tanstack/store";
|
||||
|
||||
//#region src/useAtom.d.ts
|
||||
/**
|
||||
* Returns the current atom value together with a stable setter.
|
||||
*
|
||||
* This is the writable-atom convenience hook for components that need to both
|
||||
* read and update the same atom.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const [count, setCount] = useAtom(countAtom)
|
||||
* ```
|
||||
*/
|
||||
declare function useAtom<TValue>(atom: Atom<TValue>, options?: UseSelectorOptions<TValue>): [TValue, Atom<TValue>['set']];
|
||||
//#endregion
|
||||
export { useAtom };
|
||||
//# sourceMappingURL=useAtom.d.ts.map
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
import { useSelector } from "./useSelector.js";
|
||||
|
||||
//#region src/useAtom.ts
|
||||
/**
|
||||
* Returns the current atom value together with a stable setter.
|
||||
*
|
||||
* This is the writable-atom convenience hook for components that need to both
|
||||
* read and update the same atom.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const [count, setCount] = useAtom(countAtom)
|
||||
* ```
|
||||
*/
|
||||
function useAtom(atom, options) {
|
||||
return [useSelector(atom, void 0, options), atom.set];
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { useAtom };
|
||||
//# sourceMappingURL=useAtom.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useAtom.js","names":[],"sources":["../src/useAtom.ts"],"sourcesContent":["import { useSelector } from './useSelector'\nimport type { Atom } from '@tanstack/store'\nimport type { UseSelectorOptions } from './useSelector'\n\n/**\n * Returns the current atom value together with a stable setter.\n *\n * This is the writable-atom convenience hook for components that need to both\n * read and update the same atom.\n *\n * @example\n * ```tsx\n * const [count, setCount] = useAtom(countAtom)\n * ```\n */\nexport function useAtom<TValue>(\n atom: Atom<TValue>,\n options?: UseSelectorOptions<TValue>,\n): [TValue, Atom<TValue>['set']] {\n const value = useSelector(atom, undefined, options)\n\n return [value, atom.set]\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,SAAgB,QACd,MACA,SAC+B;AAG/B,QAAO,CAFO,YAAY,MAAM,QAAW,QAAQ,EAEpC,KAAK,IAAI"}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
let _tanstack_store = require("@tanstack/store");
|
||||
let react = require("react");
|
||||
|
||||
//#region src/useCreateAtom.ts
|
||||
function useCreateAtom(valueOrFn, options) {
|
||||
const [atom] = (0, react.useState)(() => {
|
||||
if (typeof valueOrFn === "function") return (0, _tanstack_store.createAtom)(valueOrFn, options);
|
||||
return (0, _tanstack_store.createAtom)(valueOrFn, options);
|
||||
});
|
||||
return atom;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.useCreateAtom = useCreateAtom;
|
||||
//# sourceMappingURL=useCreateAtom.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useCreateAtom.cjs","names":[],"sources":["../src/useCreateAtom.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createAtom } from '@tanstack/store'\nimport type { Atom, AtomOptions, ReadonlyAtom } from '@tanstack/store'\n\n/**\n * Creates a stable atom instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable atom, or a getter function to\n * create a readonly derived atom. This hook mirrors the overloads from\n * {@link createAtom}, but ensures the atom is only created once per mount.\n *\n * @example\n * ```tsx\n * const countAtom = useCreateAtom(0)\n * ```\n */\nexport function useCreateAtom<T>(\n getValue: (prev?: NoInfer<T>) => T,\n options?: AtomOptions<T>,\n): ReadonlyAtom<T>\nexport function useCreateAtom<T>(\n initialValue: T,\n options?: AtomOptions<T>,\n): Atom<T>\nexport function useCreateAtom<T>(\n valueOrFn: T | ((prev?: T) => T),\n options?: AtomOptions<T>,\n): Atom<T> | ReadonlyAtom<T> {\n const [atom] = useState<Atom<T> | ReadonlyAtom<T>>(() => {\n if (typeof valueOrFn === 'function') {\n return createAtom(valueOrFn as (prev?: NoInfer<T>) => T, options)\n }\n\n return createAtom(valueOrFn, options)\n })\n\n return atom\n}\n"],"mappings":";;;;AAwBA,SAAgB,cACd,WACA,SAC2B;CAC3B,MAAM,CAAC,kCAAkD;AACvD,MAAI,OAAO,cAAc,WACvB,wCAAkB,WAAuC,QAAQ;AAGnE,yCAAkB,WAAW,QAAQ;GACrC;AAEF,QAAO"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Atom, AtomOptions, ReadonlyAtom } from "@tanstack/store";
|
||||
|
||||
//#region src/useCreateAtom.d.ts
|
||||
/**
|
||||
* Creates a stable atom instance for the lifetime of the component.
|
||||
*
|
||||
* Pass an initial value to create a writable atom, or a getter function to
|
||||
* create a readonly derived atom. This hook mirrors the overloads from
|
||||
* {@link createAtom}, but ensures the atom is only created once per mount.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const countAtom = useCreateAtom(0)
|
||||
* ```
|
||||
*/
|
||||
declare function useCreateAtom<T>(getValue: (prev?: NoInfer<T>) => T, options?: AtomOptions<T>): ReadonlyAtom<T>;
|
||||
declare function useCreateAtom<T>(initialValue: T, options?: AtomOptions<T>): Atom<T>;
|
||||
//#endregion
|
||||
export { useCreateAtom };
|
||||
//# sourceMappingURL=useCreateAtom.d.cts.map
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
import { Atom, AtomOptions, ReadonlyAtom } from "@tanstack/store";
|
||||
|
||||
//#region src/useCreateAtom.d.ts
|
||||
/**
|
||||
* Creates a stable atom instance for the lifetime of the component.
|
||||
*
|
||||
* Pass an initial value to create a writable atom, or a getter function to
|
||||
* create a readonly derived atom. This hook mirrors the overloads from
|
||||
* {@link createAtom}, but ensures the atom is only created once per mount.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const countAtom = useCreateAtom(0)
|
||||
* ```
|
||||
*/
|
||||
declare function useCreateAtom<T>(getValue: (prev?: NoInfer<T>) => T, options?: AtomOptions<T>): ReadonlyAtom<T>;
|
||||
declare function useCreateAtom<T>(initialValue: T, options?: AtomOptions<T>): Atom<T>;
|
||||
//#endregion
|
||||
export { useCreateAtom };
|
||||
//# sourceMappingURL=useCreateAtom.d.ts.map
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import { createAtom } from "@tanstack/store";
|
||||
import { useState } from "react";
|
||||
|
||||
//#region src/useCreateAtom.ts
|
||||
function useCreateAtom(valueOrFn, options) {
|
||||
const [atom] = useState(() => {
|
||||
if (typeof valueOrFn === "function") return createAtom(valueOrFn, options);
|
||||
return createAtom(valueOrFn, options);
|
||||
});
|
||||
return atom;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { useCreateAtom };
|
||||
//# sourceMappingURL=useCreateAtom.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useCreateAtom.js","names":[],"sources":["../src/useCreateAtom.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createAtom } from '@tanstack/store'\nimport type { Atom, AtomOptions, ReadonlyAtom } from '@tanstack/store'\n\n/**\n * Creates a stable atom instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable atom, or a getter function to\n * create a readonly derived atom. This hook mirrors the overloads from\n * {@link createAtom}, but ensures the atom is only created once per mount.\n *\n * @example\n * ```tsx\n * const countAtom = useCreateAtom(0)\n * ```\n */\nexport function useCreateAtom<T>(\n getValue: (prev?: NoInfer<T>) => T,\n options?: AtomOptions<T>,\n): ReadonlyAtom<T>\nexport function useCreateAtom<T>(\n initialValue: T,\n options?: AtomOptions<T>,\n): Atom<T>\nexport function useCreateAtom<T>(\n valueOrFn: T | ((prev?: T) => T),\n options?: AtomOptions<T>,\n): Atom<T> | ReadonlyAtom<T> {\n const [atom] = useState<Atom<T> | ReadonlyAtom<T>>(() => {\n if (typeof valueOrFn === 'function') {\n return createAtom(valueOrFn as (prev?: NoInfer<T>) => T, options)\n }\n\n return createAtom(valueOrFn, options)\n })\n\n return atom\n}\n"],"mappings":";;;;AAwBA,SAAgB,cACd,WACA,SAC2B;CAC3B,MAAM,CAAC,QAAQ,eAA0C;AACvD,MAAI,OAAO,cAAc,WACvB,QAAO,WAAW,WAAuC,QAAQ;AAGnE,SAAO,WAAW,WAAW,QAAQ;GACrC;AAEF,QAAO"}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
let _tanstack_store = require("@tanstack/store");
|
||||
let react = require("react");
|
||||
|
||||
//#region src/useCreateStore.ts
|
||||
function useCreateStore(valueOrFn, actions) {
|
||||
const [store] = (0, react.useState)(() => {
|
||||
if (typeof valueOrFn === "function") return (0, _tanstack_store.createStore)(valueOrFn);
|
||||
if (actions) return (0, _tanstack_store.createStore)(valueOrFn, actions);
|
||||
return (0, _tanstack_store.createStore)(valueOrFn);
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.useCreateStore = useCreateStore;
|
||||
//# sourceMappingURL=useCreateStore.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useCreateStore.cjs","names":[],"sources":["../src/useCreateStore.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createStore } from '@tanstack/store'\nimport type {\n ReadonlyStore,\n Store,\n StoreActionMap,\n StoreActionsFactory,\n} from '@tanstack/store'\n\ntype NonFunction<T> = T extends (...args: Array<any>) => any ? never : T\n\n/**\n * Creates a stable store instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable store, or a getter function to\n * create a readonly derived store. This hook mirrors the overloads from\n * {@link createStore}, but ensures the store is only created once per mount.\n *\n * @example\n * ```tsx\n * const counterStore = useCreateStore({ count: 0 })\n * ```\n */\nexport function useCreateStore<T>(\n getValue: (prev?: NoInfer<T>) => T,\n): ReadonlyStore<T>\nexport function useCreateStore<T>(initialValue: T): Store<T>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n initialValue: NonFunction<T>,\n actions: StoreActionsFactory<T, TActions>,\n): Store<T, TActions>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n valueOrFn: T | ((prev?: T) => T),\n actions?: StoreActionsFactory<T, TActions>,\n): Store<T, TActions> | Store<T> | ReadonlyStore<T> {\n const [store] = useState<Store<T, TActions> | Store<T> | ReadonlyStore<T>>(\n () => {\n if (typeof valueOrFn === 'function') {\n return createStore(valueOrFn as (prev?: NoInfer<T>) => T)\n }\n\n if (actions) {\n return createStore(valueOrFn as NonFunction<T>, actions)\n }\n\n return createStore(valueOrFn)\n },\n )\n\n return store\n}\n"],"mappings":";;;;AA+BA,SAAgB,eACd,WACA,SACkD;CAClD,MAAM,CAAC,mCACC;AACJ,MAAI,OAAO,cAAc,WACvB,yCAAmB,UAAsC;AAG3D,MAAI,QACF,yCAAmB,WAA6B,QAAQ;AAG1D,0CAAmB,UAAU;GAEhC;AAED,QAAO"}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { ReadonlyStore, Store, StoreActionMap, StoreActionsFactory } from "@tanstack/store";
|
||||
|
||||
//#region src/useCreateStore.d.ts
|
||||
type NonFunction<T> = T extends ((...args: Array<any>) => any) ? never : T;
|
||||
/**
|
||||
* Creates a stable store instance for the lifetime of the component.
|
||||
*
|
||||
* Pass an initial value to create a writable store, or a getter function to
|
||||
* create a readonly derived store. This hook mirrors the overloads from
|
||||
* {@link createStore}, but ensures the store is only created once per mount.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const counterStore = useCreateStore({ count: 0 })
|
||||
* ```
|
||||
*/
|
||||
declare function useCreateStore<T>(getValue: (prev?: NoInfer<T>) => T): ReadonlyStore<T>;
|
||||
declare function useCreateStore<T>(initialValue: T): Store<T>;
|
||||
declare function useCreateStore<T, TActions extends StoreActionMap>(initialValue: NonFunction<T>, actions: StoreActionsFactory<T, TActions>): Store<T, TActions>;
|
||||
//#endregion
|
||||
export { useCreateStore };
|
||||
//# sourceMappingURL=useCreateStore.d.cts.map
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
import { ReadonlyStore, Store, StoreActionMap, StoreActionsFactory } from "@tanstack/store";
|
||||
|
||||
//#region src/useCreateStore.d.ts
|
||||
type NonFunction<T> = T extends ((...args: Array<any>) => any) ? never : T;
|
||||
/**
|
||||
* Creates a stable store instance for the lifetime of the component.
|
||||
*
|
||||
* Pass an initial value to create a writable store, or a getter function to
|
||||
* create a readonly derived store. This hook mirrors the overloads from
|
||||
* {@link createStore}, but ensures the store is only created once per mount.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const counterStore = useCreateStore({ count: 0 })
|
||||
* ```
|
||||
*/
|
||||
declare function useCreateStore<T>(getValue: (prev?: NoInfer<T>) => T): ReadonlyStore<T>;
|
||||
declare function useCreateStore<T>(initialValue: T): Store<T>;
|
||||
declare function useCreateStore<T, TActions extends StoreActionMap>(initialValue: NonFunction<T>, actions: StoreActionsFactory<T, TActions>): Store<T, TActions>;
|
||||
//#endregion
|
||||
export { useCreateStore };
|
||||
//# sourceMappingURL=useCreateStore.d.ts.map
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { createStore } from "@tanstack/store";
|
||||
import { useState } from "react";
|
||||
|
||||
//#region src/useCreateStore.ts
|
||||
function useCreateStore(valueOrFn, actions) {
|
||||
const [store] = useState(() => {
|
||||
if (typeof valueOrFn === "function") return createStore(valueOrFn);
|
||||
if (actions) return createStore(valueOrFn, actions);
|
||||
return createStore(valueOrFn);
|
||||
});
|
||||
return store;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { useCreateStore };
|
||||
//# sourceMappingURL=useCreateStore.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useCreateStore.js","names":[],"sources":["../src/useCreateStore.ts"],"sourcesContent":["import { useState } from 'react'\nimport { createStore } from '@tanstack/store'\nimport type {\n ReadonlyStore,\n Store,\n StoreActionMap,\n StoreActionsFactory,\n} from '@tanstack/store'\n\ntype NonFunction<T> = T extends (...args: Array<any>) => any ? never : T\n\n/**\n * Creates a stable store instance for the lifetime of the component.\n *\n * Pass an initial value to create a writable store, or a getter function to\n * create a readonly derived store. This hook mirrors the overloads from\n * {@link createStore}, but ensures the store is only created once per mount.\n *\n * @example\n * ```tsx\n * const counterStore = useCreateStore({ count: 0 })\n * ```\n */\nexport function useCreateStore<T>(\n getValue: (prev?: NoInfer<T>) => T,\n): ReadonlyStore<T>\nexport function useCreateStore<T>(initialValue: T): Store<T>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n initialValue: NonFunction<T>,\n actions: StoreActionsFactory<T, TActions>,\n): Store<T, TActions>\nexport function useCreateStore<T, TActions extends StoreActionMap>(\n valueOrFn: T | ((prev?: T) => T),\n actions?: StoreActionsFactory<T, TActions>,\n): Store<T, TActions> | Store<T> | ReadonlyStore<T> {\n const [store] = useState<Store<T, TActions> | Store<T> | ReadonlyStore<T>>(\n () => {\n if (typeof valueOrFn === 'function') {\n return createStore(valueOrFn as (prev?: NoInfer<T>) => T)\n }\n\n if (actions) {\n return createStore(valueOrFn as NonFunction<T>, actions)\n }\n\n return createStore(valueOrFn)\n },\n )\n\n return store\n}\n"],"mappings":";;;;AA+BA,SAAgB,eACd,WACA,SACkD;CAClD,MAAM,CAAC,SAAS,eACR;AACJ,MAAI,OAAO,cAAc,WACvB,QAAO,YAAY,UAAsC;AAG3D,MAAI,QACF,QAAO,YAAY,WAA6B,QAAQ;AAG1D,SAAO,YAAY,UAAU;GAEhC;AAED,QAAO"}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
let react = require("react");
|
||||
let use_sync_external_store_shim_with_selector = require("use-sync-external-store/shim/with-selector");
|
||||
|
||||
//#region src/useSelector.ts
|
||||
function defaultCompare(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
/**
|
||||
* Selects a slice of state from an atom or store and subscribes the component
|
||||
* to that selection.
|
||||
*
|
||||
* This is the primary React read hook for TanStack Store. It works with any
|
||||
* source that exposes `get()` and `subscribe()`, including atoms, readonly
|
||||
* atoms, stores, and readonly stores.
|
||||
*
|
||||
* Omit the selector to subscribe to the whole value.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useSelector(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const value = useSelector(countAtom)
|
||||
* ```
|
||||
*/
|
||||
function useSelector(source, selector = (s) => s, options) {
|
||||
const compare = options?.compare ?? defaultCompare;
|
||||
const subscribe = (0, react.useCallback)((handleStoreChange) => {
|
||||
const { unsubscribe } = source.subscribe(handleStoreChange);
|
||||
return unsubscribe;
|
||||
}, [source]);
|
||||
const getSnapshot = (0, react.useCallback)(() => source.get(), [source]);
|
||||
return (0, use_sync_external_store_shim_with_selector.useSyncExternalStoreWithSelector)(subscribe, getSnapshot, getSnapshot, selector, compare);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
exports.useSelector = useSelector;
|
||||
//# sourceMappingURL=useSelector.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useSelector.cjs","names":[],"sources":["../src/useSelector.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport interface UseSelectorOptions<TSelected> {\n compare?: (a: TSelected, b: TSelected) => boolean\n}\n\ntype SyncExternalStoreSubscribe = Parameters<\n typeof useSyncExternalStoreWithSelector\n>[0]\n\ntype SelectionSource<T> = {\n get: () => T\n subscribe: (listener: (value: T) => void) => {\n unsubscribe: () => void\n }\n}\n\nfunction defaultCompare<T>(a: T, b: T) {\n return a === b\n}\n\n/**\n * Selects a slice of state from an atom or store and subscribes the component\n * to that selection.\n *\n * This is the primary React read hook for TanStack Store. It works with any\n * source that exposes `get()` and `subscribe()`, including atoms, readonly\n * atoms, stores, and readonly stores.\n *\n * Omit the selector to subscribe to the whole value.\n *\n * @example\n * ```tsx\n * const count = useSelector(counterStore, (state) => state.count)\n * ```\n *\n * @example\n * ```tsx\n * const value = useSelector(countAtom)\n * ```\n */\nexport function useSelector<TSource, TSelected = NoInfer<TSource>>(\n source: SelectionSource<TSource>,\n selector: (snapshot: TSource) => TSelected = (s) => s as unknown as TSelected,\n options?: UseSelectorOptions<TSelected>,\n): TSelected {\n const compare = options?.compare ?? defaultCompare\n\n const subscribe: SyncExternalStoreSubscribe = useCallback(\n (handleStoreChange) => {\n const { unsubscribe } = source.subscribe(handleStoreChange)\n return unsubscribe\n },\n [source],\n )\n\n const getSnapshot = useCallback(() => source.get(), [source])\n\n return useSyncExternalStoreWithSelector(\n subscribe,\n getSnapshot,\n getSnapshot,\n selector,\n compare,\n )\n}\n"],"mappings":";;;;AAkBA,SAAS,eAAkB,GAAM,GAAM;AACrC,QAAO,MAAM;;;;;;;;;;;;;;;;;;;;;;AAuBf,SAAgB,YACd,QACA,YAA8C,MAAM,GACpD,SACW;CACX,MAAM,UAAU,SAAS,WAAW;CAEpC,MAAM,oCACH,sBAAsB;EACrB,MAAM,EAAE,gBAAgB,OAAO,UAAU,kBAAkB;AAC3D,SAAO;IAET,CAAC,OAAO,CACT;CAED,MAAM,2CAAgC,OAAO,KAAK,EAAE,CAAC,OAAO,CAAC;AAE7D,yFACE,WACA,aACA,aACA,UACA,QACD"}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//#region src/useSelector.d.ts
|
||||
interface UseSelectorOptions<TSelected> {
|
||||
compare?: (a: TSelected, b: TSelected) => boolean;
|
||||
}
|
||||
type SelectionSource<T> = {
|
||||
get: () => T;
|
||||
subscribe: (listener: (value: T) => void) => {
|
||||
unsubscribe: () => void;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Selects a slice of state from an atom or store and subscribes the component
|
||||
* to that selection.
|
||||
*
|
||||
* This is the primary React read hook for TanStack Store. It works with any
|
||||
* source that exposes `get()` and `subscribe()`, including atoms, readonly
|
||||
* atoms, stores, and readonly stores.
|
||||
*
|
||||
* Omit the selector to subscribe to the whole value.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useSelector(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const value = useSelector(countAtom)
|
||||
* ```
|
||||
*/
|
||||
declare function useSelector<TSource, TSelected = NoInfer<TSource>>(source: SelectionSource<TSource>, selector?: (snapshot: TSource) => TSelected, options?: UseSelectorOptions<TSelected>): TSelected;
|
||||
//#endregion
|
||||
export { UseSelectorOptions, useSelector };
|
||||
//# sourceMappingURL=useSelector.d.cts.map
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
//#region src/useSelector.d.ts
|
||||
interface UseSelectorOptions<TSelected> {
|
||||
compare?: (a: TSelected, b: TSelected) => boolean;
|
||||
}
|
||||
type SelectionSource<T> = {
|
||||
get: () => T;
|
||||
subscribe: (listener: (value: T) => void) => {
|
||||
unsubscribe: () => void;
|
||||
};
|
||||
};
|
||||
/**
|
||||
* Selects a slice of state from an atom or store and subscribes the component
|
||||
* to that selection.
|
||||
*
|
||||
* This is the primary React read hook for TanStack Store. It works with any
|
||||
* source that exposes `get()` and `subscribe()`, including atoms, readonly
|
||||
* atoms, stores, and readonly stores.
|
||||
*
|
||||
* Omit the selector to subscribe to the whole value.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useSelector(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const value = useSelector(countAtom)
|
||||
* ```
|
||||
*/
|
||||
declare function useSelector<TSource, TSelected = NoInfer<TSource>>(source: SelectionSource<TSource>, selector?: (snapshot: TSource) => TSelected, options?: UseSelectorOptions<TSelected>): TSelected;
|
||||
//#endregion
|
||||
export { UseSelectorOptions, useSelector };
|
||||
//# sourceMappingURL=useSelector.d.ts.map
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
import { useCallback } from "react";
|
||||
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
||||
|
||||
//#region src/useSelector.ts
|
||||
function defaultCompare(a, b) {
|
||||
return a === b;
|
||||
}
|
||||
/**
|
||||
* Selects a slice of state from an atom or store and subscribes the component
|
||||
* to that selection.
|
||||
*
|
||||
* This is the primary React read hook for TanStack Store. It works with any
|
||||
* source that exposes `get()` and `subscribe()`, including atoms, readonly
|
||||
* atoms, stores, and readonly stores.
|
||||
*
|
||||
* Omit the selector to subscribe to the whole value.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useSelector(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const value = useSelector(countAtom)
|
||||
* ```
|
||||
*/
|
||||
function useSelector(source, selector = (s) => s, options) {
|
||||
const compare = options?.compare ?? defaultCompare;
|
||||
const subscribe = useCallback((handleStoreChange) => {
|
||||
const { unsubscribe } = source.subscribe(handleStoreChange);
|
||||
return unsubscribe;
|
||||
}, [source]);
|
||||
const getSnapshot = useCallback(() => source.get(), [source]);
|
||||
return useSyncExternalStoreWithSelector(subscribe, getSnapshot, getSnapshot, selector, compare);
|
||||
}
|
||||
|
||||
//#endregion
|
||||
export { useSelector };
|
||||
//# sourceMappingURL=useSelector.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useSelector.js","names":[],"sources":["../src/useSelector.ts"],"sourcesContent":["import { useCallback } from 'react'\nimport { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'\n\nexport interface UseSelectorOptions<TSelected> {\n compare?: (a: TSelected, b: TSelected) => boolean\n}\n\ntype SyncExternalStoreSubscribe = Parameters<\n typeof useSyncExternalStoreWithSelector\n>[0]\n\ntype SelectionSource<T> = {\n get: () => T\n subscribe: (listener: (value: T) => void) => {\n unsubscribe: () => void\n }\n}\n\nfunction defaultCompare<T>(a: T, b: T) {\n return a === b\n}\n\n/**\n * Selects a slice of state from an atom or store and subscribes the component\n * to that selection.\n *\n * This is the primary React read hook for TanStack Store. It works with any\n * source that exposes `get()` and `subscribe()`, including atoms, readonly\n * atoms, stores, and readonly stores.\n *\n * Omit the selector to subscribe to the whole value.\n *\n * @example\n * ```tsx\n * const count = useSelector(counterStore, (state) => state.count)\n * ```\n *\n * @example\n * ```tsx\n * const value = useSelector(countAtom)\n * ```\n */\nexport function useSelector<TSource, TSelected = NoInfer<TSource>>(\n source: SelectionSource<TSource>,\n selector: (snapshot: TSource) => TSelected = (s) => s as unknown as TSelected,\n options?: UseSelectorOptions<TSelected>,\n): TSelected {\n const compare = options?.compare ?? defaultCompare\n\n const subscribe: SyncExternalStoreSubscribe = useCallback(\n (handleStoreChange) => {\n const { unsubscribe } = source.subscribe(handleStoreChange)\n return unsubscribe\n },\n [source],\n )\n\n const getSnapshot = useCallback(() => source.get(), [source])\n\n return useSyncExternalStoreWithSelector(\n subscribe,\n getSnapshot,\n getSnapshot,\n selector,\n compare,\n )\n}\n"],"mappings":";;;;AAkBA,SAAS,eAAkB,GAAM,GAAM;AACrC,QAAO,MAAM;;;;;;;;;;;;;;;;;;;;;;AAuBf,SAAgB,YACd,QACA,YAA8C,MAAM,GACpD,SACW;CACX,MAAM,UAAU,SAAS,WAAW;CAEpC,MAAM,YAAwC,aAC3C,sBAAsB;EACrB,MAAM,EAAE,gBAAgB,OAAO,UAAU,kBAAkB;AAC3D,SAAO;IAET,CAAC,OAAO,CACT;CAED,MAAM,cAAc,kBAAkB,OAAO,KAAK,EAAE,CAAC,OAAO,CAAC;AAE7D,QAAO,iCACL,WACA,aACA,aACA,UACA,QACD"}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
const require_useSelector = require('./useSelector.cjs');
|
||||
|
||||
//#region src/useStore.ts
|
||||
/**
|
||||
* Deprecated alias for {@link useSelector}.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useStore(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `useSelector` instead.
|
||||
*/
|
||||
const useStore = (source, selector = (s) => s, compare) => require_useSelector.useSelector(source, selector, { compare });
|
||||
|
||||
//#endregion
|
||||
exports.useStore = useStore;
|
||||
//# sourceMappingURL=useStore.cjs.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useStore.cjs","names":["useSelector"],"sources":["../src/useStore.ts"],"sourcesContent":["import { useSelector } from './useSelector'\n\n/**\n * Deprecated alias for {@link useSelector}.\n *\n * @example\n * ```tsx\n * const count = useStore(counterStore, (state) => state.count)\n * ```\n *\n * @deprecated Use `useSelector` instead.\n */\nexport const useStore = <TSource, TSelected = NoInfer<TSource>>(\n source: {\n get: () => TSource\n subscribe: (listener: (value: TSource) => void) => {\n unsubscribe: () => void\n }\n },\n selector: (snapshot: TSource) => TSelected = (s) => s as unknown as TSelected,\n compare?: (a: TSelected, b: TSelected) => boolean,\n) => useSelector(source, selector, { compare })\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,YACX,QAMA,YAA8C,MAAM,GACpD,YACGA,gCAAY,QAAQ,UAAU,EAAE,SAAS,CAAC"}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//#region src/useStore.d.ts
|
||||
/**
|
||||
* Deprecated alias for {@link useSelector}.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useStore(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `useSelector` instead.
|
||||
*/
|
||||
declare const useStore: <TSource, TSelected = NoInfer<TSource>>(source: {
|
||||
get: () => TSource;
|
||||
subscribe: (listener: (value: TSource) => void) => {
|
||||
unsubscribe: () => void;
|
||||
};
|
||||
}, selector?: (snapshot: TSource) => TSelected, compare?: (a: TSelected, b: TSelected) => boolean) => TSelected;
|
||||
//#endregion
|
||||
export { useStore };
|
||||
//# sourceMappingURL=useStore.d.cts.map
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
//#region src/useStore.d.ts
|
||||
/**
|
||||
* Deprecated alias for {@link useSelector}.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useStore(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `useSelector` instead.
|
||||
*/
|
||||
declare const useStore: <TSource, TSelected = NoInfer<TSource>>(source: {
|
||||
get: () => TSource;
|
||||
subscribe: (listener: (value: TSource) => void) => {
|
||||
unsubscribe: () => void;
|
||||
};
|
||||
}, selector?: (snapshot: TSource) => TSelected, compare?: (a: TSelected, b: TSelected) => boolean) => TSelected;
|
||||
//#endregion
|
||||
export { useStore };
|
||||
//# sourceMappingURL=useStore.d.ts.map
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
import { useSelector } from "./useSelector.js";
|
||||
|
||||
//#region src/useStore.ts
|
||||
/**
|
||||
* Deprecated alias for {@link useSelector}.
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* const count = useStore(counterStore, (state) => state.count)
|
||||
* ```
|
||||
*
|
||||
* @deprecated Use `useSelector` instead.
|
||||
*/
|
||||
const useStore = (source, selector = (s) => s, compare) => useSelector(source, selector, { compare });
|
||||
|
||||
//#endregion
|
||||
export { useStore };
|
||||
//# sourceMappingURL=useStore.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"useStore.js","names":[],"sources":["../src/useStore.ts"],"sourcesContent":["import { useSelector } from './useSelector'\n\n/**\n * Deprecated alias for {@link useSelector}.\n *\n * @example\n * ```tsx\n * const count = useStore(counterStore, (state) => state.count)\n * ```\n *\n * @deprecated Use `useSelector` instead.\n */\nexport const useStore = <TSource, TSelected = NoInfer<TSource>>(\n source: {\n get: () => TSource\n subscribe: (listener: (value: TSource) => void) => {\n unsubscribe: () => void\n }\n },\n selector: (snapshot: TSource) => TSelected = (s) => s as unknown as TSelected,\n compare?: (a: TSelected, b: TSelected) => boolean,\n) => useSelector(source, selector, { compare })\n"],"mappings":";;;;;;;;;;;;;AAYA,MAAa,YACX,QAMA,YAA8C,MAAM,GACpD,YACG,YAAY,QAAQ,UAAU,EAAE,SAAS,CAAC"}
|
||||
Reference in new issue
Block a user