@necto-react/state 0.0.1 → 0.0.3
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/dist/index.cjs +1 -1
- package/dist/index.d.cts +31 -2
- package/dist/index.d.ts +31 -2
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var b=Object.prototype.hasOwnProperty;var v=(t,o)=>{for(var e in o)d(t,e,{get:o[e],enumerable:!0})},k=(t,o,e,u)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of L(o))!b.call(t,r)&&r!==e&&d(t,r,{get:()=>o[r],enumerable:!(u=w(o,r))||u.enumerable});return t};var E=t=>k(d({},"__esModule",{value:!0}),t);var P={};v(P,{Provider:()=>y,useLocalState:()=>A,useSetState:()=>c,useState:()=>f,useStateValue:()=>p,useStore:()=>l});module.exports=E(P);var i=require("react");var n=require("react"),x=require("@necto/state"),R=(0,n.createContext)(void 0);function l(t){let o=(0,n.useContext)(R);return t?.store||o||(0,x.getDefaultStore)()}function y({children:t,store:o}){let e=(0,n.useRef)(null);return o?(0,n.createElement)(R.Provider,{value:o},t):(e.current===null&&(e.current=(0,x.createStore)()),(0,n.createElement)(R.Provider,{value:e.current},t))}function p(t,o){let e=l(o),[[u,r,S],V]=(0,i.useReducer)(s=>{let O=e.get(t);return Object.is(s[0],O)&&s[1]===e&&s[2]===t?s:[O,e,t]},void 0,()=>[e.get(t),e,t]),a=u;return(r!==e||S!==t)&&(V(),a=e.get(t)),(0,i.useEffect)(()=>{let s=e.sub(t,()=>{V()});return V(),s},[e,t]),(0,i.useDebugValue)(a),a}var g=require("react");function c(t,o){let e=l(o);return(0,g.useCallback)((...r)=>{if(!("write"in t))throw new Error("state is not writable");return e.set(t,...r)},[e,t])}function f(t,o){return[p(t,o),c(t,o)]}var m=require("react"),U=require("@necto/state");function A(t,o){let e=(0,m.useRef)(null),u=(0,m.useRef)(null);if(u.current===null){let a=typeof t=="function"?t():t;e.current=a,u.current=(0,U.state)(a)}let[r,S]=f(u.current,o);return(0,m.useMemo)(()=>{let a=[r,S];return Object.defineProperty(a,"value",{get:()=>a[0],enumerable:!0,configurable:!0}),a.set=s=>S(s),a.update=s=>S(s),a.reset=()=>S(e.current),a},[r,S])}0&&(module.exports={Provider,useLocalState,useSetState,useState,useStateValue,useStore});
|
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,35 @@ type SetState<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
|
77
77
|
declare function useSetState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseSetStateOptions): SetState<Args, Result>;
|
|
78
78
|
declare function useSetState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseSetStateOptions): SetState<ExtractStateArgs<S>, ExtractStateResult<S>>;
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
|
+
*
|
|
83
|
+
* This source code is licensed under the MIT license found in the
|
|
84
|
+
* LICENSE file in the root directory of this source tree.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
type UseLocalStateOptions = {
|
|
88
|
+
store?: Store;
|
|
89
|
+
};
|
|
90
|
+
type LocalStateResult<Value> = [Value, (value: SetStateAction<Value>) => void] & {
|
|
91
|
+
value: Value;
|
|
92
|
+
set: (value: Value) => void;
|
|
93
|
+
update: (fn: (prev: Value) => Value) => void;
|
|
94
|
+
reset: () => void;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
99
|
+
*
|
|
100
|
+
* This source code is licensed under the MIT license found in the
|
|
101
|
+
* LICENSE file in the root directory of this source tree.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/** useLocalState(initialValue) — component-scoped state, drop-in for React's useState with signal-style API */
|
|
105
|
+
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
106
|
+
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
107
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
108
|
+
|
|
80
109
|
/**
|
|
81
110
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
111
|
*
|
|
@@ -88,9 +117,9 @@ type UseStoreOptions = {
|
|
|
88
117
|
store?: Store;
|
|
89
118
|
};
|
|
90
119
|
declare function useStore(options?: UseStoreOptions): Store;
|
|
91
|
-
declare function Provider({ children, store
|
|
120
|
+
declare function Provider({ children, store }: {
|
|
92
121
|
children?: ReactNode;
|
|
93
122
|
store?: Store;
|
|
94
123
|
}): ReactElement;
|
|
95
124
|
|
|
96
|
-
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
|
125
|
+
export { type LocalStateResult, Provider, type UseLocalStateOptions, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useLocalState, useSetState, useState, useStateValue, useStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,35 @@ type SetState<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
|
77
77
|
declare function useSetState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseSetStateOptions): SetState<Args, Result>;
|
|
78
78
|
declare function useSetState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseSetStateOptions): SetState<ExtractStateArgs<S>, ExtractStateResult<S>>;
|
|
79
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
|
+
*
|
|
83
|
+
* This source code is licensed under the MIT license found in the
|
|
84
|
+
* LICENSE file in the root directory of this source tree.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
type UseLocalStateOptions = {
|
|
88
|
+
store?: Store;
|
|
89
|
+
};
|
|
90
|
+
type LocalStateResult<Value> = [Value, (value: SetStateAction<Value>) => void] & {
|
|
91
|
+
value: Value;
|
|
92
|
+
set: (value: Value) => void;
|
|
93
|
+
update: (fn: (prev: Value) => Value) => void;
|
|
94
|
+
reset: () => void;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
99
|
+
*
|
|
100
|
+
* This source code is licensed under the MIT license found in the
|
|
101
|
+
* LICENSE file in the root directory of this source tree.
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/** useLocalState(initialValue) — component-scoped state, drop-in for React's useState with signal-style API */
|
|
105
|
+
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
106
|
+
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
107
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
108
|
+
|
|
80
109
|
/**
|
|
81
110
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
111
|
*
|
|
@@ -88,9 +117,9 @@ type UseStoreOptions = {
|
|
|
88
117
|
store?: Store;
|
|
89
118
|
};
|
|
90
119
|
declare function useStore(options?: UseStoreOptions): Store;
|
|
91
|
-
declare function Provider({ children, store
|
|
120
|
+
declare function Provider({ children, store }: {
|
|
92
121
|
children?: ReactNode;
|
|
93
122
|
store?: Store;
|
|
94
123
|
}): ReactElement;
|
|
95
124
|
|
|
96
|
-
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
|
125
|
+
export { type LocalStateResult, Provider, type UseLocalStateOptions, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useLocalState, useSetState, useState, useStateValue, useStore };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useDebugValue as
|
|
1
|
+
import{useDebugValue as w,useEffect as L,useReducer as b}from"react";import{createContext as y,createElement as V,useContext as A,useRef as O}from"react";import{createStore as g,getDefaultStore as U}from"@necto/state";var f=y(void 0);function S(t){let o=A(f);return t?.store||o||U()}function x({children:t,store:o}){let e=O(null);return o?V(f.Provider,{value:o},t):(e.current===null&&(e.current=g()),V(f.Provider,{value:e.current},t))}function i(t,o){let e=S(o),[[u,n,s],l]=b(r=>{let m=e.get(t);return Object.is(r[0],m)&&r[1]===e&&r[2]===t?r:[m,e,t]},void 0,()=>[e.get(t),e,t]),a=u;return(n!==e||s!==t)&&(l(),a=e.get(t)),L(()=>{let r=e.sub(t,()=>{l()});return l(),r},[e,t]),w(a),a}import{useCallback as v}from"react";function p(t,o){let e=S(o);return v((...n)=>{if(!("write"in t))throw new Error("state is not writable");return e.set(t,...n)},[e,t])}function c(t,o){return[i(t,o),p(t,o)]}import{useRef as d,useMemo as k}from"react";import{state as E}from"@necto/state";function R(t,o){let e=d(null),u=d(null);if(u.current===null){let a=typeof t=="function"?t():t;e.current=a,u.current=E(a)}let[n,s]=c(u.current,o);return k(()=>{let a=[n,s];return Object.defineProperty(a,"value",{get:()=>a[0],enumerable:!0,configurable:!0}),a.set=r=>s(r),a.update=r=>s(r),a.reset=()=>s(e.current),a},[n,s])}export{x as Provider,R as useLocalState,p as useSetState,c as useState,i as useStateValue,S as useStore};
|