@necto-react/state 0.0.1
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/LICENSE +21 -0
- package/README.md +0 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +96 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.js +1 -0
- package/package.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Corinvo, LLC. and affiliates. All rights reserved.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
File without changes
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var m=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var w=Object.prototype.hasOwnProperty;var U=(t,e)=>{for(var r in e)m(t,r,{get:e[r],enumerable:!0})},E=(t,e,r,S)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of O(e))!w.call(t,o)&&o!==r&&m(t,o,{get:()=>e[o],enumerable:!(S=y(e,o))||S.enumerable});return t};var b=t=>E(m({},"__esModule",{value:!0}),t);var k={};U(k,{Provider:()=>V,useSetState:()=>p,useState:()=>d,useStateValue:()=>i,useStore:()=>s});module.exports=b(k);var n=require("react");var a=require("react"),l=require("@necto/state"),x=(0,a.createContext)(void 0);function s(t){let e=(0,a.useContext)(x);return t?.store||e||(0,l.getDefaultStore)()}function V({children:t,store:e}){let r=(0,a.useRef)(null);return e?(0,a.createElement)(x.Provider,{value:e},t):(r.current===null&&(r.current=(0,l.createStore)()),(0,a.createElement)(x.Provider,{value:r.current},t))}function i(t,e){let r=s(e),[[S,o,g],c]=(0,n.useReducer)(u=>{let A=r.get(t);return Object.is(u[0],A)&&u[1]===r&&u[2]===t?u:[A,r,t]},void 0,()=>[r.get(t),r,t]),f=S;return(o!==r||g!==t)&&(c(),f=r.get(t)),(0,n.useEffect)(()=>{let u=r.sub(t,()=>{c()});return c(),u},[r,t]),(0,n.useDebugValue)(f),f}var R=require("react");function p(t,e){let r=s(e);return(0,R.useCallback)((...o)=>{if(!("write"in t))throw new Error("state is not writable");return r.set(t,...o)},[r,t])}function d(t,e){return[i(t,e),p(t,e)]}0&&(module.exports={Provider,useSetState,useState,useStateValue,useStore});
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Store, WritableState, PrimitiveState, SetStateAction, State, ExtractStateValue, ExtractStateArgs, ExtractStateResult } from '@necto/state';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type UseStateOptions = {
|
|
12
|
+
store?: Store;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the MIT license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type SetState$1<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
23
|
+
/** useState(writableState) — returns [value, setter] */
|
|
24
|
+
declare function useState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseStateOptions): [Awaited<Value>, SetState$1<Args, Result>];
|
|
25
|
+
/** useState(primitiveState) — returns [value, setter] for a primitive state */
|
|
26
|
+
declare function useState<Value>(s: PrimitiveState<Value>, options?: UseStateOptions): [Awaited<Value>, SetState$1<[SetStateAction<Value>], void>];
|
|
27
|
+
/** useState(readOnlyState) — returns [value, never] for a read-only state */
|
|
28
|
+
declare function useState<Value>(s: State<Value>, options?: UseStateOptions): [Awaited<Value>, never];
|
|
29
|
+
/** useState(state) — generic overload */
|
|
30
|
+
declare function useState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseStateOptions): [
|
|
31
|
+
Awaited<ExtractStateValue<S>>,
|
|
32
|
+
SetState$1<ExtractStateArgs<S>, ExtractStateResult<S>>
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
37
|
+
*
|
|
38
|
+
* This source code is licensed under the MIT license found in the
|
|
39
|
+
* LICENSE file in the root directory of this source tree.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
type UseStateValueOptions = {
|
|
43
|
+
store?: Store;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the MIT license found in the
|
|
50
|
+
* LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** useStateValue(state) — subscribe and return the current value */
|
|
54
|
+
declare function useStateValue<Value>(s: State<Value>, options?: UseStateValueOptions): Awaited<Value>;
|
|
55
|
+
declare function useStateValue<S extends State<unknown>>(s: S, options?: UseStateValueOptions): Awaited<ExtractStateValue<S>>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
59
|
+
*
|
|
60
|
+
* This source code is licensed under the MIT license found in the
|
|
61
|
+
* LICENSE file in the root directory of this source tree.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
type UseSetStateOptions = {
|
|
65
|
+
store?: Store;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
70
|
+
*
|
|
71
|
+
* This source code is licensed under the MIT license found in the
|
|
72
|
+
* LICENSE file in the root directory of this source tree.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
type SetState<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
76
|
+
/** useSetState(state) — returns a stable setter function */
|
|
77
|
+
declare function useSetState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseSetStateOptions): SetState<Args, Result>;
|
|
78
|
+
declare function useSetState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseSetStateOptions): SetState<ExtractStateArgs<S>, ExtractStateResult<S>>;
|
|
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 UseStoreOptions = {
|
|
88
|
+
store?: Store;
|
|
89
|
+
};
|
|
90
|
+
declare function useStore(options?: UseStoreOptions): Store;
|
|
91
|
+
declare function Provider({ children, store, }: {
|
|
92
|
+
children?: ReactNode;
|
|
93
|
+
store?: Store;
|
|
94
|
+
}): ReactElement;
|
|
95
|
+
|
|
96
|
+
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { Store, WritableState, PrimitiveState, SetStateAction, State, ExtractStateValue, ExtractStateArgs, ExtractStateResult } from '@necto/state';
|
|
2
|
+
import { ReactNode, ReactElement } from 'react';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
6
|
+
*
|
|
7
|
+
* This source code is licensed under the MIT license found in the
|
|
8
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
type UseStateOptions = {
|
|
12
|
+
store?: Store;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
17
|
+
*
|
|
18
|
+
* This source code is licensed under the MIT license found in the
|
|
19
|
+
* LICENSE file in the root directory of this source tree.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type SetState$1<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
23
|
+
/** useState(writableState) — returns [value, setter] */
|
|
24
|
+
declare function useState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseStateOptions): [Awaited<Value>, SetState$1<Args, Result>];
|
|
25
|
+
/** useState(primitiveState) — returns [value, setter] for a primitive state */
|
|
26
|
+
declare function useState<Value>(s: PrimitiveState<Value>, options?: UseStateOptions): [Awaited<Value>, SetState$1<[SetStateAction<Value>], void>];
|
|
27
|
+
/** useState(readOnlyState) — returns [value, never] for a read-only state */
|
|
28
|
+
declare function useState<Value>(s: State<Value>, options?: UseStateOptions): [Awaited<Value>, never];
|
|
29
|
+
/** useState(state) — generic overload */
|
|
30
|
+
declare function useState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseStateOptions): [
|
|
31
|
+
Awaited<ExtractStateValue<S>>,
|
|
32
|
+
SetState$1<ExtractStateArgs<S>, ExtractStateResult<S>>
|
|
33
|
+
];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
37
|
+
*
|
|
38
|
+
* This source code is licensed under the MIT license found in the
|
|
39
|
+
* LICENSE file in the root directory of this source tree.
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
type UseStateValueOptions = {
|
|
43
|
+
store?: Store;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the MIT license found in the
|
|
50
|
+
* LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
/** useStateValue(state) — subscribe and return the current value */
|
|
54
|
+
declare function useStateValue<Value>(s: State<Value>, options?: UseStateValueOptions): Awaited<Value>;
|
|
55
|
+
declare function useStateValue<S extends State<unknown>>(s: S, options?: UseStateValueOptions): Awaited<ExtractStateValue<S>>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
59
|
+
*
|
|
60
|
+
* This source code is licensed under the MIT license found in the
|
|
61
|
+
* LICENSE file in the root directory of this source tree.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
type UseSetStateOptions = {
|
|
65
|
+
store?: Store;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Copyright (c) Corinvo, LLC. and affiliates.
|
|
70
|
+
*
|
|
71
|
+
* This source code is licensed under the MIT license found in the
|
|
72
|
+
* LICENSE file in the root directory of this source tree.
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
type SetState<Args extends unknown[], Result> = (...args: Args) => Result;
|
|
76
|
+
/** useSetState(state) — returns a stable setter function */
|
|
77
|
+
declare function useSetState<Value, Args extends unknown[], Result>(s: WritableState<Value, Args, Result>, options?: UseSetStateOptions): SetState<Args, Result>;
|
|
78
|
+
declare function useSetState<S extends WritableState<unknown, never[], unknown>>(s: S, options?: UseSetStateOptions): SetState<ExtractStateArgs<S>, ExtractStateResult<S>>;
|
|
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 UseStoreOptions = {
|
|
88
|
+
store?: Store;
|
|
89
|
+
};
|
|
90
|
+
declare function useStore(options?: UseStoreOptions): Store;
|
|
91
|
+
declare function Provider({ children, store, }: {
|
|
92
|
+
children?: ReactNode;
|
|
93
|
+
store?: Store;
|
|
94
|
+
}): ReactElement;
|
|
95
|
+
|
|
96
|
+
export { Provider, type UseSetStateOptions, type UseStateOptions, type UseStateValueOptions, useSetState, useState, useStateValue, useStore };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useDebugValue as O,useEffect as w,useReducer as U}from"react";import{createContext as d,createElement as f,useContext as A,useRef as R}from"react";import{createStore as g,getDefaultStore as y}from"@necto/state";var p=d(void 0);function a(t){let r=A(p);return t?.store||r||y()}function m({children:t,store:r}){let e=R(null);return r?f(p.Provider,{value:r},t):(e.current===null&&(e.current=g()),f(p.Provider,{value:e.current},t))}function s(t,r){let e=a(r),[[l,n,V],S]=U(o=>{let c=e.get(t);return Object.is(o[0],c)&&o[1]===e&&o[2]===t?o:[c,e,t]},void 0,()=>[e.get(t),e,t]),i=l;return(n!==e||V!==t)&&(S(),i=e.get(t)),w(()=>{let o=e.sub(t,()=>{S()});return S(),o},[e,t]),O(i),i}import{useCallback as E}from"react";function u(t,r){let e=a(r);return E((...n)=>{if(!("write"in t))throw new Error("state is not writable");return e.set(t,...n)},[e,t])}function x(t,r){return[s(t,r),u(t,r)]}export{m as Provider,u as useSetState,x as useState,s as useStateValue,a as useStore};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@necto-react/state",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "React bindings for @necto/state.",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist",
|
|
7
|
+
"README.md"
|
|
8
|
+
],
|
|
9
|
+
"type": "module",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/index.d.cts",
|
|
21
|
+
"default": "./dist/index.cjs"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"author": "Corinvo OSS Team",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@necto/state": "0.0.1"
|
|
29
|
+
},
|
|
30
|
+
"peerDependencies": {
|
|
31
|
+
"react": "^19.1.0",
|
|
32
|
+
"react-dom": "^19.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@testing-library/react": "^16.3.0",
|
|
36
|
+
"@types/react": "^19.1.2",
|
|
37
|
+
"@types/react-dom": "^19.1.2",
|
|
38
|
+
"jsdom": "^26.1.0",
|
|
39
|
+
"react": "^19.1.0",
|
|
40
|
+
"react-dom": "^19.1.0",
|
|
41
|
+
"tsup": "^8.4.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup --minify",
|
|
45
|
+
"test": "vitest"
|
|
46
|
+
}
|
|
47
|
+
}
|