mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
build(store): build26 from 45504a2b
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
import { Comparator, Selector } from "../../core/shallow-equal.js";
|
||||
//#region src/react/hooks/use-selector.d.ts
|
||||
/**
|
||||
* Subscribe to derived state with customizable equality check.
|
||||
*
|
||||
* Low-level hook used internally by `useStore` and `useSnapshot`.
|
||||
*
|
||||
* @param subscribe - Subscribe function that returns an unsubscribe callback.
|
||||
* @param getSnapshot - Returns the current snapshot value.
|
||||
* @param selector - Derives a value from the snapshot.
|
||||
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
||||
*/
|
||||
declare function useSelector<S, R>(subscribe: (cb: () => void) => () => void, getSnapshot: () => S, selector: Selector<S, R>, isEqual?: Comparator<R>): R;
|
||||
//#endregion
|
||||
export { type Comparator, type Selector, useSelector };
|
||||
//# sourceMappingURL=use-selector.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-selector.d.ts","names":[],"sources":["../../../../src/react/hooks/use-selector.ts"],"mappings":";;;;;;;;;;;;iBAegB,YAAY,GAAG,GAC7B,YAAY,+BACZ,mBAAmB,GACnB,UAAU,SAAS,GAAG,IACtB,UAAS,WAAW,KACnB"}
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
import { shallowEqual } from "../../core/shallow-equal.js";
|
||||
import { useRef, useSyncExternalStore } from "react";
|
||||
//#region src/react/hooks/use-selector.ts
|
||||
/**
|
||||
* Subscribe to derived state with customizable equality check.
|
||||
*
|
||||
* Low-level hook used internally by `useStore` and `useSnapshot`.
|
||||
*
|
||||
* @param subscribe - Subscribe function that returns an unsubscribe callback.
|
||||
* @param getSnapshot - Returns the current snapshot value.
|
||||
* @param selector - Derives a value from the snapshot.
|
||||
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
||||
*/
|
||||
function useSelector(subscribe, getSnapshot, selector, isEqual = shallowEqual) {
|
||||
const cache = useRef(void 0);
|
||||
const getSelectedSnapshot = () => {
|
||||
const next = selector(getSnapshot());
|
||||
if (cache.current !== void 0 && isEqual(cache.current, next)) return cache.current;
|
||||
cache.current = next;
|
||||
return next;
|
||||
};
|
||||
return useSyncExternalStore(subscribe, getSelectedSnapshot, getSelectedSnapshot);
|
||||
}
|
||||
//#endregion
|
||||
export { useSelector };
|
||||
|
||||
//# sourceMappingURL=use-selector.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-selector.js","names":[],"sources":["../../../../src/react/hooks/use-selector.ts"],"sourcesContent":["import { useRef, useSyncExternalStore } from 'react';\nimport { type Comparator, type Selector, shallowEqual } from '../../core/shallow-equal';\n\nexport type { Comparator, Selector };\n\n/**\n * Subscribe to derived state with customizable equality check.\n *\n * Low-level hook used internally by `useStore` and `useSnapshot`.\n *\n * @param subscribe - Subscribe function that returns an unsubscribe callback.\n * @param getSnapshot - Returns the current snapshot value.\n * @param selector - Derives a value from the snapshot.\n * @param isEqual - Custom equality function. Defaults to `shallowEqual`.\n */\nexport function useSelector<S, R>(\n subscribe: (cb: () => void) => () => void,\n getSnapshot: () => S,\n selector: Selector<S, R>,\n isEqual: Comparator<R> = shallowEqual\n): R {\n const cache = useRef<R | undefined>(undefined);\n\n const getSelectedSnapshot = () => {\n const next = selector(getSnapshot());\n\n if (cache.current !== undefined && isEqual(cache.current, next)) {\n return cache.current;\n }\n\n cache.current = next;\n\n return next;\n };\n\n return useSyncExternalStore(subscribe, getSelectedSnapshot, getSelectedSnapshot);\n}\n"],"mappings":";;;;;;;;;;;;;AAeA,SAAgB,YACd,WACA,aACA,UACA,UAAyB,cACtB;CACH,MAAM,QAAQ,OAAsB,KAAA,CAAS;CAE7C,MAAM,4BAA4B;EAChC,MAAM,OAAO,SAAS,YAAY,CAAC;EAEnC,IAAI,MAAM,YAAY,KAAA,KAAa,QAAQ,MAAM,SAAS,IAAI,GAC5D,OAAO,MAAM;EAGf,MAAM,UAAU;EAEhB,OAAO;CACT;CAEA,OAAO,qBAAqB,WAAW,qBAAqB,mBAAmB;AACjF"}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
import { State } from "../../core/state.js";
|
||||
import { Comparator, Selector } from "../../core/shallow-equal.js";
|
||||
import "./use-selector.js";
|
||||
//#region src/react/hooks/use-snapshot.d.ts
|
||||
/**
|
||||
* Subscribe to a State container's current value.
|
||||
*
|
||||
* @param state - The State container to subscribe to.
|
||||
* @param selector - Derives a value from state.
|
||||
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
||||
*/
|
||||
/** @label Without Selector */
|
||||
declare function useSnapshot<T extends object>(state: State<T>): T;
|
||||
/**
|
||||
* Select a value from state. Re-renders when the selected value changes.
|
||||
*
|
||||
* @label With Selector
|
||||
* @param selector - Derives a value from state.
|
||||
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
||||
*/
|
||||
declare function useSnapshot<T extends object, R>(state: State<T>, selector: Selector<T, R>, isEqual?: Comparator<R>): R;
|
||||
//#endregion
|
||||
export { useSnapshot };
|
||||
//# sourceMappingURL=use-snapshot.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-snapshot.d.ts","names":[],"sources":["../../../../src/react/hooks/use-snapshot.ts"],"mappings":";;;;;;;;;;;;iBAYgB,YAAY,kBAAkB,OAAO,MAAM,KAAK;;;;;;;;iBAShD,YAAY,kBAAkB,GAAG,OAAO,MAAM,IAAI,UAAU,SAAS,GAAG,IAAI,UAAU,WAAW,KAAK"}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
import { useSelector } from "./use-selector.js";
|
||||
import { identity } from "@videojs/utils/function";
|
||||
//#region src/react/hooks/use-snapshot.ts
|
||||
function useSnapshot(state, selector, isEqual) {
|
||||
return useSelector((cb) => state.subscribe(cb), () => state.current, selector ?? identity, isEqual);
|
||||
}
|
||||
//#endregion
|
||||
export { useSnapshot };
|
||||
|
||||
//# sourceMappingURL=use-snapshot.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-snapshot.js","names":[],"sources":["../../../../src/react/hooks/use-snapshot.ts"],"sourcesContent":["import { identity } from '@videojs/utils/function';\nimport type { State } from '../../core/state';\nimport { type Comparator, type Selector, useSelector } from './use-selector';\n\n/**\n * Subscribe to a State container's current value.\n *\n * @param state - The State container to subscribe to.\n * @param selector - Derives a value from state.\n * @param isEqual - Custom equality function. Defaults to `shallowEqual`.\n */\n/** @label Without Selector */\nexport function useSnapshot<T extends object>(state: State<T>): T;\n\n/**\n * Select a value from state. Re-renders when the selected value changes.\n *\n * @label With Selector\n * @param selector - Derives a value from state.\n * @param isEqual - Custom equality function. Defaults to `shallowEqual`.\n */\nexport function useSnapshot<T extends object, R>(state: State<T>, selector: Selector<T, R>, isEqual?: Comparator<R>): R;\n\nexport function useSnapshot(state: State<object>, selector?: Selector<any, any>, isEqual?: Comparator<any>) {\n return useSelector(\n (cb) => state.subscribe(cb),\n () => state.current,\n selector ?? identity,\n isEqual\n );\n}\n"],"mappings":";;;AAuBA,SAAgB,YAAY,OAAsB,UAA+B,SAA2B;CAC1G,OAAO,aACJ,OAAO,MAAM,UAAU,EAAE,SACpB,MAAM,SACZ,YAAY,UACZ,OACF;AACF"}
|
||||
Vendored
+40
@@ -0,0 +1,40 @@
|
||||
import { AnyStore, InferStoreState } from "../../core/store.js";
|
||||
import { Comparator, Selector } from "../../core/shallow-equal.js";
|
||||
import "./use-selector.js";
|
||||
//#region src/react/hooks/use-store.d.ts
|
||||
/**
|
||||
* Access store state and actions.
|
||||
*
|
||||
* Without selector: Returns the store, does NOT subscribe to changes.
|
||||
* With selector: Returns selected state, re-renders when selected state changes (shallowEqual).
|
||||
*
|
||||
* @example
|
||||
* ```tsx
|
||||
* // Store access (no subscription) - access actions, subscribe without re-render
|
||||
* function Controls() {
|
||||
* const { setVolume } = useStore(store);
|
||||
* }
|
||||
*
|
||||
* // Selector-based subscription - re-renders when paused changes
|
||||
* function PlayButton() {
|
||||
* const paused = useStore(store, (s) => s.paused);
|
||||
* return <button>{paused ? 'Play' : 'Pause'}</button>;
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
/** @label Without Selector */
|
||||
declare function useStore<S extends AnyStore>(store: S): S;
|
||||
/**
|
||||
* Select a value from the store. Re-renders when the selected value changes (shallowEqual).
|
||||
*
|
||||
* @label With Selector
|
||||
* @param selector - Derives a value from the store state.
|
||||
* @param isEqual - Custom equality function. Defaults to `shallowEqual`.
|
||||
*/
|
||||
declare function useStore<S extends AnyStore, R>(store: S, selector: Selector<InferStoreState<S>, R>, isEqual?: Comparator<R>): R;
|
||||
declare namespace useStore {
|
||||
type Result<S extends AnyStore> = S;
|
||||
}
|
||||
//#endregion
|
||||
export { useStore };
|
||||
//# sourceMappingURL=use-store.d.ts.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-store.d.ts","names":[],"sources":["../../../../src/react/hooks/use-store.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;iBA2BgB,SAAS,UAAU,UAAU,OAAO,IAAI;;;;;;;;iBASxC,SAAS,UAAU,UAAU,GAC3C,OAAO,GACP,UAAU,SAAS,gBAAgB,IAAI,IACvC,UAAU,WAAW,KACpB;kBASc;OACH,OAAO,UAAU,YAAY"}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
import { useSelector } from "./use-selector.js";
|
||||
import { identity, noop } from "@videojs/utils/function";
|
||||
//#region src/react/hooks/use-store.ts
|
||||
const noopSubscribe = () => noop;
|
||||
function useStore(store, selector, isEqual) {
|
||||
return useSelector(selector ? (cb) => store.subscribe(cb) : noopSubscribe, selector ? () => store.state : () => store, selector ?? identity, isEqual);
|
||||
}
|
||||
//#endregion
|
||||
export { useStore };
|
||||
|
||||
//# sourceMappingURL=use-store.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"use-store.js","names":[],"sources":["../../../../src/react/hooks/use-store.ts"],"sourcesContent":["import { identity, noop } from '@videojs/utils/function';\nimport type { AnyStore, InferStoreState } from '../../core/store';\nimport { type Comparator, type Selector, useSelector } from './use-selector';\n\nconst noopSubscribe = () => noop;\n\n/**\n * Access store state and actions.\n *\n * Without selector: Returns the store, does NOT subscribe to changes.\n * With selector: Returns selected state, re-renders when selected state changes (shallowEqual).\n *\n * @example\n * ```tsx\n * // Store access (no subscription) - access actions, subscribe without re-render\n * function Controls() {\n * const { setVolume } = useStore(store);\n * }\n *\n * // Selector-based subscription - re-renders when paused changes\n * function PlayButton() {\n * const paused = useStore(store, (s) => s.paused);\n * return <button>{paused ? 'Play' : 'Pause'}</button>;\n * }\n * ```\n */\n/** @label Without Selector */\nexport function useStore<S extends AnyStore>(store: S): S;\n\n/**\n * Select a value from the store. Re-renders when the selected value changes (shallowEqual).\n *\n * @label With Selector\n * @param selector - Derives a value from the store state.\n * @param isEqual - Custom equality function. Defaults to `shallowEqual`.\n */\nexport function useStore<S extends AnyStore, R>(\n store: S,\n selector: Selector<InferStoreState<S>, R>,\n isEqual?: Comparator<R>\n): R;\n\nexport function useStore(store: AnyStore, selector?: Selector<any, any>, isEqual?: Comparator<any>) {\n const subscribe = selector ? (cb: () => void) => store.subscribe(cb) : noopSubscribe,\n getSnapshot = selector ? () => store.state : () => store;\n\n return useSelector(subscribe, getSnapshot, selector ?? identity, isEqual);\n}\n\nexport namespace useStore {\n export type Result<S extends AnyStore> = S;\n}\n"],"mappings":";;;AAIA,MAAM,sBAAsB;AAsC5B,SAAgB,SAAS,OAAiB,UAA+B,SAA2B;CAIlG,OAAO,YAHW,YAAY,OAAmB,MAAM,UAAU,EAAE,IAAI,eACvD,iBAAiB,MAAM,cAAc,OAEV,YAAY,UAAU,OAAO;AAC1E"}
|
||||
Reference in New Issue
Block a user