@necto-react/state 0.0.1 → 0.0.2
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 +24 -1
- package/dist/index.d.ts +24 -1
- 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 x=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var k=(t,o)=>{for(var e in o)x(t,e,{get:o[e],enumerable:!0})},b=(t,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of v(o))!E.call(t,a)&&a!==e&&x(t,a,{get:()=>o[a],enumerable:!(s=w(o,a))||s.enumerable});return t};var L=t=>b(x({},"__esModule",{value:!0}),t);var W={};k(W,{Provider:()=>d,useLocalState:()=>y,useSetState:()=>l,useState:()=>p,useStateValue:()=>i,useStore:()=>u});module.exports=L(W);var S=require("react");var r=require("react"),c=require("@necto/state"),V=(0,r.createContext)(void 0);function u(t){let o=(0,r.useContext)(V);return t?.store||o||(0,c.getDefaultStore)()}function d({children:t,store:o}){let e=(0,r.useRef)(null);return o?(0,r.createElement)(V.Provider,{value:o},t):(e.current===null&&(e.current=(0,c.createStore)()),(0,r.createElement)(V.Provider,{value:e.current},t))}function i(t,o){let e=u(o),[[s,a,g],f]=(0,S.useReducer)(n=>{let A=e.get(t);return Object.is(n[0],A)&&n[1]===e&&n[2]===t?n:[A,e,t]},void 0,()=>[e.get(t),e,t]),m=s;return(a!==e||g!==t)&&(f(),m=e.get(t)),(0,S.useEffect)(()=>{let n=e.sub(t,()=>{f()});return f(),n},[e,t]),(0,S.useDebugValue)(m),m}var R=require("react");function l(t,o){let e=u(o);return(0,R.useCallback)((...a)=>{if(!("write"in t))throw new Error("state is not writable");return e.set(t,...a)},[e,t])}function p(t,o){return[i(t,o),l(t,o)]}var O=require("react"),U=require("@necto/state");function y(t,o){let e=(0,O.useRef)(null);if(e.current===null){let s=typeof t=="function"?t():t;e.current=(0,U.state)(s)}return p(e.current,o)}0&&(module.exports={Provider,useLocalState,useSetState,useState,useStateValue,useStore});
|
package/dist/index.d.cts
CHANGED
|
@@ -77,6 +77,29 @@ 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
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the MIT license found in the
|
|
95
|
+
* LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/** useLocalState(initialValue) — component-scoped state, drop-in replacement for React's useState */
|
|
99
|
+
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions): [Value, (value: SetStateAction<Value>) => void];
|
|
100
|
+
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
101
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): [Value, (value: SetStateAction<Value>) => void];
|
|
102
|
+
|
|
80
103
|
/**
|
|
81
104
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
105
|
*
|
|
@@ -93,4 +116,4 @@ declare function Provider({ children, store, }: {
|
|
|
93
116
|
store?: Store;
|
|
94
117
|
}): ReactElement;
|
|
95
118
|
|
|
96
|
-
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
|
119
|
+
export { Provider, type UseLocalStateOptions, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useLocalState, useSetState, useState, useStateValue, useStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,29 @@ 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
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the MIT license found in the
|
|
95
|
+
* LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/** useLocalState(initialValue) — component-scoped state, drop-in replacement for React's useState */
|
|
99
|
+
declare function useLocalState<Value>(initialValue: Value, options?: UseLocalStateOptions): [Value, (value: SetStateAction<Value>) => void];
|
|
100
|
+
/** useLocalState(initializer) — component-scoped state with lazy initializer */
|
|
101
|
+
declare function useLocalState<Value>(initializer: () => Value, options?: UseLocalStateOptions): [Value, (value: SetStateAction<Value>) => void];
|
|
102
|
+
|
|
80
103
|
/**
|
|
81
104
|
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
82
105
|
*
|
|
@@ -93,4 +116,4 @@ declare function Provider({ children, store, }: {
|
|
|
93
116
|
store?: Store;
|
|
94
117
|
}): ReactElement;
|
|
95
118
|
|
|
96
|
-
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
|
119
|
+
export { 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 g,useEffect as w,useReducer as v}from"react";import{createContext as y,createElement as m,useContext as A,useRef as R}from"react";import{createStore as O,getDefaultStore as U}from"@necto/state";var c=y(void 0);function r(t){let o=A(c);return t?.store||o||U()}function x({children:t,store:o}){let e=R(null);return o?m(c.Provider,{value:o},t):(e.current===null&&(e.current=O()),m(c.Provider,{value:e.current},t))}function u(t,o){let e=r(o),[[s,i,d],l]=v(a=>{let f=e.get(t);return Object.is(a[0],f)&&a[1]===e&&a[2]===t?a:[f,e,t]},void 0,()=>[e.get(t),e,t]),p=s;return(i!==e||d!==t)&&(l(),p=e.get(t)),w(()=>{let a=e.sub(t,()=>{l()});return l(),a},[e,t]),g(p),p}import{useCallback as E}from"react";function n(t,o){let e=r(o);return E((...i)=>{if(!("write"in t))throw new Error("state is not writable");return e.set(t,...i)},[e,t])}function S(t,o){return[u(t,o),n(t,o)]}import{useRef as k}from"react";import{state as b}from"@necto/state";function V(t,o){let e=k(null);if(e.current===null){let s=typeof t=="function"?t():t;e.current=b(s)}return S(e.current,o)}export{x as Provider,V as useLocalState,n as useSetState,S as useState,u as useStateValue,r as useStore};
|