@necto-react/state 0.0.2 → 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 +11 -5
- package/dist/index.d.ts +11 -5
- 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
|
@@ -87,6 +87,12 @@ declare function useSetState<S extends WritableState<unknown, never[], unknown>>
|
|
|
87
87
|
type UseLocalStateOptions = {
|
|
88
88
|
store?: Store;
|
|
89
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
|
+
};
|
|
90
96
|
|
|
91
97
|
/**
|
|
92
98
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -95,10 +101,10 @@ type UseLocalStateOptions = {
|
|
|
95
101
|
* LICENSE file in the root directory of this source tree.
|
|
96
102
|
*/
|
|
97
103
|
|
|
98
|
-
/** useLocalState(initialValue) — component-scoped state, drop-in
|
|
99
|
-
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions):
|
|
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>;
|
|
100
106
|
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
101
|
-
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions):
|
|
107
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
102
108
|
|
|
103
109
|
/**
|
|
104
110
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -111,9 +117,9 @@ type UseStoreOptions = {
|
|
|
111
117
|
store?: Store;
|
|
112
118
|
};
|
|
113
119
|
declare function useStore(options?: UseStoreOptions): Store;
|
|
114
|
-
declare function Provider({ children, store
|
|
120
|
+
declare function Provider({ children, store }: {
|
|
115
121
|
children?: ReactNode;
|
|
116
122
|
store?: Store;
|
|
117
123
|
}): ReactElement;
|
|
118
124
|
|
|
119
|
-
export { Provider, type UseLocalStateOptions, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useLocalState, 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
|
@@ -87,6 +87,12 @@ declare function useSetState<S extends WritableState<unknown, never[], unknown>>
|
|
|
87
87
|
type UseLocalStateOptions = {
|
|
88
88
|
store?: Store;
|
|
89
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
|
+
};
|
|
90
96
|
|
|
91
97
|
/**
|
|
92
98
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -95,10 +101,10 @@ type UseLocalStateOptions = {
|
|
|
95
101
|
* LICENSE file in the root directory of this source tree.
|
|
96
102
|
*/
|
|
97
103
|
|
|
98
|
-
/** useLocalState(initialValue) — component-scoped state, drop-in
|
|
99
|
-
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions):
|
|
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>;
|
|
100
106
|
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
101
|
-
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions):
|
|
107
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): LocalStateResult<Value>;
|
|
102
108
|
|
|
103
109
|
/**
|
|
104
110
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
@@ -111,9 +117,9 @@ type UseStoreOptions = {
|
|
|
111
117
|
store?: Store;
|
|
112
118
|
};
|
|
113
119
|
declare function useStore(options?: UseStoreOptions): Store;
|
|
114
|
-
declare function Provider({ children, store
|
|
120
|
+
declare function Provider({ children, store }: {
|
|
115
121
|
children?: ReactNode;
|
|
116
122
|
store?: Store;
|
|
117
123
|
}): ReactElement;
|
|
118
124
|
|
|
119
|
-
export { Provider, type UseLocalStateOptions, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useLocalState, 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};
|