statedrive 0.0.12 → 0.0.14
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/README.md +64 -0
- package/package.json +7 -9
- package/{sd-react → react}/package.json +6 -7
- package/{sd-react → react}/src/hooks.ts +0 -0
- package/{sd-react → react}/src/index.ts +0 -0
- package/{sd-react → react}/yarn.lock +17 -11
- package/src/_hook_factory.ts +10 -12
- package/src/hooks.ts +5 -6
- package/src/state.ts +3 -3
- package/src/subscribe.ts +3 -4
- package/src/types.ts +1 -1
- package/dist/_hook_factory.d.ts +0 -13
- package/dist/hooks.d.ts +0 -4
- package/dist/index.d.ts +0 -4
- package/dist/react.modern.js +0 -2
- package/dist/react.modern.js.map +0 -1
- package/dist/sd-react/src/hooks.d.ts +0 -4
- package/dist/sd-react/src/index.d.ts +0 -4
- package/dist/src/_hook_factory.d.ts +0 -13
- package/dist/src/state.d.ts +0 -4
- package/dist/src/subscribe.d.ts +0 -8
- package/dist/src/types.d.ts +0 -18
- package/dist/src/util.d.ts +0 -2
- package/dist/state.d.ts +0 -4
- package/dist/statedrive.modern.js +0 -2
- package/dist/statedrive.modern.js.map +0 -1
- package/dist/subscribe.d.ts +0 -8
- package/dist/types.d.ts +0 -18
- package/dist/util.d.ts +0 -2
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Statedrive
|
|
2
|
+
|
|
3
|
+
easy shared state across the entire app
|
|
4
|
+
|
|
5
|
+
# Concept
|
|
6
|
+
|
|
7
|
+
Each state is a unique atom to which you can attach event listeners and run state updates.
|
|
8
|
+
|
|
9
|
+
# Installation
|
|
10
|
+
|
|
11
|
+
`npm i statedrive` or `yarn add statedrive`
|
|
12
|
+
|
|
13
|
+
# API
|
|
14
|
+
|
|
15
|
+
## For [ui-lib](https://github.com/hydrophobefireman/ui-lib)
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
import { createState } from "statedrive";
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## For react
|
|
22
|
+
|
|
23
|
+
```js
|
|
24
|
+
import {createState} from "statedrive/react"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
everything else is the same.
|
|
28
|
+
|
|
29
|
+
# Basic Usage
|
|
30
|
+
|
|
31
|
+
1. Create a state atom
|
|
32
|
+
state.js
|
|
33
|
+
```js
|
|
34
|
+
import { createState } from "statedrive";
|
|
35
|
+
export const userNameAtom = createState({ initialValue: "Foo" });
|
|
36
|
+
```
|
|
37
|
+
2. Use it within a react/ui-lib component
|
|
38
|
+
some-component.js
|
|
39
|
+
```ts
|
|
40
|
+
import { useSharedState } from "statedrive";
|
|
41
|
+
import { userNameAtom } from "./state.js";
|
|
42
|
+
export function ComponentA() {
|
|
43
|
+
const [name, setName] = useSharedState(userNameAtom);
|
|
44
|
+
return <input value={name} onChange={(e) => setName(e.target.value)} />;
|
|
45
|
+
}
|
|
46
|
+
export function ComponentB() {
|
|
47
|
+
const [name] = useSharedState(userNamaeAtom);
|
|
48
|
+
return <div>You Entered {name}</div>;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
3. Use it within your app elsewhere (any place where hooks don't work)
|
|
52
|
+
util.js
|
|
53
|
+
```js
|
|
54
|
+
import { get, set } from "statedrive";
|
|
55
|
+
import { userNameAtom } from "./state.js";
|
|
56
|
+
function updateName(newValue) {
|
|
57
|
+
setUserNameAtom, newValue;
|
|
58
|
+
}
|
|
59
|
+
function getName() {
|
|
60
|
+
return get(userNameAtom);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
And that's it, your entire app will be synced to this state and updated whenever needed.
|
package/package.json
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "statedrive",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/statedrive.modern.js",
|
|
6
6
|
"module": "dist/statedrive.modern.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build:no-minify": "microbundle src/index.ts --compress false -o ./dist -f modern --target web --raw true --tsconfig tsconfig.json",
|
|
9
9
|
"build:optimize": "microbundle src/index.ts -o ./dist -f modern --target web --raw true --tsconfig tsconfig.json",
|
|
10
|
-
"build:react": "microbundle --cwd
|
|
10
|
+
"build:react": "microbundle --cwd react src/index.ts -o ../dist/react.js -f modern --target web --raw true --tsconfig tsconfig.json",
|
|
11
11
|
"prebuild": "rm -rf ./dist",
|
|
12
12
|
"build": "npm run build:optimize && npm run build:react",
|
|
13
13
|
"output": "npm run build:no-minify && npm run postbuild"
|
|
14
14
|
},
|
|
15
15
|
"exports": {
|
|
16
16
|
".": "./dist/statedrive.modern.js",
|
|
17
|
-
"./
|
|
17
|
+
"./react": "./dist/react.modern.js"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -28,13 +28,11 @@
|
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"homepage": "https://github.com/Hydrophobefireman/statedrive#readme",
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"microbundle": "^0.
|
|
32
|
-
"typescript": "^4.
|
|
33
|
-
},
|
|
34
|
-
"dependencies": {
|
|
35
|
-
"@hydrophobefireman/j-utils": "^2.1.6"
|
|
31
|
+
"microbundle": "^0.13.3",
|
|
32
|
+
"typescript": "^4.3.2"
|
|
36
33
|
},
|
|
37
34
|
"peerDependencies": {
|
|
38
|
-
"@hydrophobefireman/ui-lib": "
|
|
35
|
+
"@hydrophobefireman/ui-lib": "latest",
|
|
36
|
+
"react": "latest"
|
|
39
37
|
}
|
|
40
38
|
}
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
"name": "statedrive-react",
|
|
3
3
|
"version": "1.0.0",
|
|
4
4
|
"description": "",
|
|
5
|
-
"types": "../dist/
|
|
5
|
+
"types": "../dist/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
|
-
"author": "",
|
|
10
|
-
"license": "ISC",
|
|
11
9
|
"devDependencies": {
|
|
12
|
-
"@types/react": "^17.0.
|
|
10
|
+
"@types/react": "^17.0.5"
|
|
13
11
|
},
|
|
14
12
|
"peerDependencies": {
|
|
15
|
-
"react": "^17.0.
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
"react": "^17.0.2"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC"
|
|
18
17
|
}
|
|
File without changes
|
|
File without changes
|
|
@@ -7,18 +7,24 @@
|
|
|
7
7
|
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
|
|
8
8
|
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==
|
|
9
9
|
|
|
10
|
-
"@types/react@^17.0.
|
|
11
|
-
version "17.0.
|
|
12
|
-
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.
|
|
13
|
-
integrity sha512-
|
|
10
|
+
"@types/react@^17.0.5":
|
|
11
|
+
version "17.0.5"
|
|
12
|
+
resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.5.tgz#3d887570c4489011f75a3fc8f965bf87d09a1bea"
|
|
13
|
+
integrity sha512-bj4biDB9ZJmGAYTWSKJly6bMr4BLUiBrx9ujiJEoP9XIDY9CTaPGxE5QWN/1WjpPLzYF7/jRNnV2nNxNe970sw==
|
|
14
14
|
dependencies:
|
|
15
15
|
"@types/prop-types" "*"
|
|
16
|
+
"@types/scheduler" "*"
|
|
16
17
|
csstype "^3.0.2"
|
|
17
18
|
|
|
19
|
+
"@types/scheduler@*":
|
|
20
|
+
version "0.16.1"
|
|
21
|
+
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.1.tgz#18845205e86ff0038517aab7a18a62a6b9f71275"
|
|
22
|
+
integrity sha512-EaCxbanVeyxDRTQBkdLb3Bvl/HK7PBK6UJjsSixB0iHKoWxE5uu2Q/DgtpOhPIojN0Zl1whvOd7PoHs2P0s5eA==
|
|
23
|
+
|
|
18
24
|
csstype@^3.0.2:
|
|
19
|
-
version "3.0.
|
|
20
|
-
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.
|
|
21
|
-
integrity sha512-
|
|
25
|
+
version "3.0.8"
|
|
26
|
+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.0.8.tgz#d2266a792729fb227cd216fb572f43728e1ad340"
|
|
27
|
+
integrity sha512-jXKhWqXPmlUeoQnF/EhTtTl4C9SnrxSH/jZUih3jmO6lBKr99rP3/+FmrMj4EFpOXzMtXHAZkd3x0E6h6Fgflw==
|
|
22
28
|
|
|
23
29
|
"js-tokens@^3.0.0 || ^4.0.0":
|
|
24
30
|
version "4.0.0"
|
|
@@ -37,10 +43,10 @@ object-assign@^4.1.1:
|
|
|
37
43
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
|
38
44
|
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
|
|
39
45
|
|
|
40
|
-
react@^17.0.
|
|
41
|
-
version "17.0.
|
|
42
|
-
resolved "https://registry.yarnpkg.com/react/-/react-17.0.
|
|
43
|
-
integrity sha512-
|
|
46
|
+
react@^17.0.2:
|
|
47
|
+
version "17.0.2"
|
|
48
|
+
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"
|
|
49
|
+
integrity sha512-gnhPt75i/dq/z3/6q/0asP78D0u592D5L1pd7M8P+dck6Fu/jJeL6iVVK23fptSUZj8Vjf++7wXA8UNclGQcbA==
|
|
44
50
|
dependencies:
|
|
45
51
|
loose-envify "^1.1.0"
|
|
46
52
|
object-assign "^4.1.1"
|
package/src/_hook_factory.ts
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { subscribe, unsubscribe } from "./subscribe";
|
|
3
|
-
import { get, set } from "./state";
|
|
4
|
-
import { FakeSet } from "@hydrophobefireman/j-utils";
|
|
5
|
-
|
|
1
|
+
import { SelectorOptions, SetSharedState, State, StateUpdater } from "./types";
|
|
6
2
|
import type {
|
|
7
|
-
useEffect as UseEffectType,
|
|
8
|
-
useState as UseStateType,
|
|
9
3
|
useCallback as UseCallbackType,
|
|
4
|
+
useEffect as UseEffectType,
|
|
10
5
|
useMemo as UseMemoType,
|
|
6
|
+
useState as UseStateType,
|
|
11
7
|
} from "@hydrophobefireman/ui-lib";
|
|
8
|
+
import { get, set } from "./state";
|
|
9
|
+
import { subscribe, unsubscribe } from "./subscribe";
|
|
12
10
|
|
|
13
11
|
namespace Hooks {
|
|
14
12
|
export type useEffect = typeof UseEffectType;
|
|
@@ -41,7 +39,7 @@ export function createUseSelector(
|
|
|
41
39
|
useCallback: Hooks.useCallback
|
|
42
40
|
) {
|
|
43
41
|
return function useSelector<R>(func: (options: SelectorOptions<R>) => R): R {
|
|
44
|
-
const hasSubscribed = useMemo(() => new
|
|
42
|
+
const hasSubscribed = useMemo(() => new Set<State<unknown>>(), []);
|
|
45
43
|
const [, setState] = useState(null);
|
|
46
44
|
const fn = useCallback(() => setState({}), []);
|
|
47
45
|
const _get = useCallback(
|
|
@@ -54,10 +52,10 @@ export function createUseSelector(
|
|
|
54
52
|
},
|
|
55
53
|
[hasSubscribed]
|
|
56
54
|
);
|
|
57
|
-
useEffect(
|
|
58
|
-
hasSubscribed,
|
|
59
|
-
fn
|
|
60
|
-
|
|
55
|
+
useEffect(
|
|
56
|
+
() => () => hasSubscribed.forEach((x) => unsubscribe(x, fn)),
|
|
57
|
+
[hasSubscribed, fn]
|
|
58
|
+
);
|
|
61
59
|
return func({ get: _get });
|
|
62
60
|
};
|
|
63
61
|
}
|
package/src/hooks.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as factory from "./_hook_factory";
|
|
2
|
+
|
|
2
3
|
import {
|
|
3
4
|
useCallback,
|
|
4
5
|
useEffect,
|
|
@@ -18,10 +19,8 @@ export const useSelector = /*#__PURE__*/ factory.createUseSelector(
|
|
|
18
19
|
useCallback
|
|
19
20
|
);
|
|
20
21
|
|
|
21
|
-
export const useSharedStateValue =
|
|
22
|
-
useSharedState
|
|
23
|
-
);
|
|
22
|
+
export const useSharedStateValue =
|
|
23
|
+
/*#__PURE__*/ factory.createUseSharedStateValue(useSharedState);
|
|
24
24
|
|
|
25
|
-
export const useSetSharedState =
|
|
26
|
-
useSharedState
|
|
27
|
-
);
|
|
25
|
+
export const useSetSharedState =
|
|
26
|
+
/*#__PURE__*/ factory.createUseSetSharedState(useSharedState);
|
package/src/state.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { State, StateOptions, StateUpdater } from "./types";
|
|
2
|
+
|
|
1
3
|
import { consumeUpdater } from "./util";
|
|
2
|
-
import { StateOptions, State, StateUpdater } from "./types";
|
|
3
4
|
import { notify } from "./subscribe";
|
|
4
|
-
import { FakeWeakMap } from "@hydrophobefireman/j-utils";
|
|
5
5
|
|
|
6
|
-
const valueMap = new
|
|
6
|
+
const valueMap = new WeakMap<State<unknown>, unknown>();
|
|
7
7
|
|
|
8
8
|
export function createState<T>(options: StateOptions<T>): State<T> {
|
|
9
9
|
const state = _state(options || {});
|
package/src/subscribe.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { FakeWeakMap, FakeSet } from "@hydrophobefireman/j-utils";
|
|
2
1
|
import { State } from "./types";
|
|
3
2
|
|
|
4
3
|
interface Listener<T> {
|
|
5
4
|
(oldValue: T, newValue: T): void;
|
|
6
5
|
}
|
|
7
|
-
type ListenerMap<T> =
|
|
8
|
-
const listenerMap: ListenerMap<unknown> = new
|
|
6
|
+
type ListenerMap<T> = WeakMap<State<T>, Set<Listener<T>>>;
|
|
7
|
+
const listenerMap: ListenerMap<unknown> = new WeakMap();
|
|
9
8
|
|
|
10
9
|
export function notify<T>(state: State<T>, oldValue: T, newValue: T) {
|
|
11
10
|
const listeners = (listenerMap as ListenerMap<T>).get(state);
|
|
@@ -15,7 +14,7 @@ export function notify<T>(state: State<T>, oldValue: T, newValue: T) {
|
|
|
15
14
|
export function subscribe<T>(state: State<T>, callback: Listener<T>) {
|
|
16
15
|
let listeners = (listenerMap as ListenerMap<T>).get(state);
|
|
17
16
|
if (listeners == null) {
|
|
18
|
-
listeners = new
|
|
17
|
+
listeners = new Set();
|
|
19
18
|
listenerMap.set(state, listeners);
|
|
20
19
|
}
|
|
21
20
|
listeners.add(callback);
|
package/src/types.ts
CHANGED
package/dist/_hook_factory.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { State, SelectorOptions, SetSharedState } from "./types";
|
|
2
|
-
import type { useEffect as UseEffectType, useState as UseStateType, useCallback as UseCallbackType, useMemo as UseMemoType } from "@hydrophobefireman/ui-lib";
|
|
3
|
-
declare namespace Hooks {
|
|
4
|
-
type useEffect = typeof UseEffectType;
|
|
5
|
-
type useState = typeof UseStateType;
|
|
6
|
-
type useCallback = typeof UseCallbackType;
|
|
7
|
-
type useMemo = typeof UseMemoType;
|
|
8
|
-
}
|
|
9
|
-
export declare function createUseSharedState(useEffect: Hooks.useEffect, useState: Hooks.useState): <T>(state: State<T>) => [T, SetSharedState<T>];
|
|
10
|
-
export declare function createUseSelector(useEffect: Hooks.useEffect, useState: Hooks.useState, useMemo: Hooks.useMemo, useCallback: Hooks.useCallback): <R>(func: (options: SelectorOptions<R>) => R) => R;
|
|
11
|
-
export declare function createUseSharedStateValue(useSharedState: ReturnType<typeof createUseSharedState>): <T>(s: State<T>) => T;
|
|
12
|
-
export declare function createUseSetSharedState(useSharedState: ReturnType<typeof createUseSharedState>): <T>(s: State<T>) => SetSharedState<T>;
|
|
13
|
-
export {};
|
package/dist/hooks.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const useSharedState: <T>(state: import("./types").State<T>) => [T, import("./types").SetSharedState<T>];
|
|
2
|
-
export declare const useSelector: <R>(func: (options: import("./types").SelectorOptions<R>) => R) => R;
|
|
3
|
-
export declare const useSharedStateValue: <T>(s: import("./types").State<T>) => T;
|
|
4
|
-
export declare const useSetSharedState: <T>(s: import("./types").State<T>) => import("./types").SetSharedState<T>;
|
package/dist/index.d.ts
DELETED
package/dist/react.modern.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{FakeWeakMap as n,FakeSet as t}from"@hydrophobefireman/j-utils";import{useState as e,useEffect as o,useCallback as r,useMemo as u}from"react";const c=new n;function i(n,t,e){const o=c.get(n);o&&o.forEach(n=>n(t,e))}function f(n,e){let o=c.get(n);null==o&&(o=new t,c.set(n,o)),o.add(e)}function s(n,t){const e=c.get(n);e&&e.delete(t)}const a=new n;function l(n){const t=function(n){return{name:n.name}}(n||{});return a.set(t,n.initialValue),t}function m(n){return a.get(n)}function d(n,t){const e=m(n),o=function(n,t){return"function"==typeof n?n(t):n}(t,e);a.set(n,o),i(n,e,o)}function g(n,t){return function(e){const[o,r]=t(()=>m(e));return n(()=>{const n=(n,t)=>r(t);return f(e,n),()=>s(e,n)},[e]),[o,n=>d(e,n)]}}function h(n,e,o,r){return function(u){const c=o(()=>new t,[]),[,i]=e(null),a=r(()=>i({}),[]),l=r(n=>(c.has(n)||(c.add(n),f(n,a)),m(n)),[c]);return n(()=>()=>c.forEach(n=>s(n,a)),[c,a]),u({get:l})}}function p(n){return function(t){return n(t)[0]}}function w(n){return function(t){return n(t)[1]}}const y=g(o,e),E=h(o,e,u,r),b=p(y),j=w(y);export{l as createState,m as get,i as notify,d as set,f as subscribe,s as unsubscribe,E as useSelector,j as useSetSharedState,y as useSharedState,b as useSharedStateValue};
|
|
2
|
-
//# sourceMappingURL=react.modern.js.map
|
package/dist/react.modern.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.modern.js","sources":["../src/subscribe.ts","../src/state.ts","../src/util.ts","../src/_hook_factory.ts","../sd-react/src/hooks.ts"],"sourcesContent":["import { FakeWeakMap, FakeSet } from \"@hydrophobefireman/j-utils\";\nimport { State } from \"./types\";\n\ninterface Listener<T> {\n (oldValue: T, newValue: T): void;\n}\ntype ListenerMap<T> = FakeWeakMap<State<T>, FakeSet<Listener<T>>>;\nconst listenerMap: ListenerMap<unknown> = new FakeWeakMap();\n\nexport function notify<T>(state: State<T>, oldValue: T, newValue: T) {\n const listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners) listeners.forEach((fn) => fn(oldValue, newValue));\n}\n\nexport function subscribe<T>(state: State<T>, callback: Listener<T>) {\n let listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners == null) {\n listeners = new FakeSet();\n listenerMap.set(state, listeners);\n }\n listeners.add(callback);\n}\n\nexport function unsubscribe<T>(state: State<T>, callback: Listener<T>) {\n const listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners) listeners.delete(callback);\n}\n","import { consumeUpdater } from \"./util\";\nimport { StateOptions, State, StateUpdater } from \"./types\";\nimport { notify } from \"./subscribe\";\nimport { FakeWeakMap } from \"@hydrophobefireman/j-utils\";\n\nconst valueMap = new FakeWeakMap<State<unknown>, unknown>();\n\nexport function createState<T>(options: StateOptions<T>): State<T> {\n const state = _state(options || {});\n valueMap.set(state, options.initialValue);\n return state;\n}\n\nfunction _state<T>(options: StateOptions<T> | State<T>) {\n return { name: options.name };\n}\n\nexport function get<T>(state: State<T>): T {\n return valueMap.get(state) as T;\n}\n\nexport function set<T>(state: State<T>, newValue: StateUpdater<T>) {\n const oldValue = get(state);\n const next = consumeUpdater(newValue, oldValue);\n valueMap.set(state, next);\n notify(state, oldValue, next);\n}\n","import { StateUpdater, FunctionUpdater } from \"./types\";\n\nexport function consumeUpdater<T>(u: StateUpdater<T>, oldValue: T) {\n if (typeof u === \"function\") return (u as FunctionUpdater<T>)(oldValue);\n return u;\n}\n","import { State, StateUpdater, SelectorOptions, SetSharedState } from \"./types\";\nimport { subscribe, unsubscribe } from \"./subscribe\";\nimport { get, set } from \"./state\";\nimport { FakeSet } from \"@hydrophobefireman/j-utils\";\n\nimport type {\n useEffect as UseEffectType,\n useState as UseStateType,\n useCallback as UseCallbackType,\n useMemo as UseMemoType,\n} from \"@hydrophobefireman/ui-lib\";\n\nnamespace Hooks {\n export type useEffect = typeof UseEffectType;\n export type useState = typeof UseStateType;\n export type useCallback = typeof UseCallbackType;\n export type useMemo = typeof UseMemoType;\n}\n\nexport function createUseSharedState(\n useEffect: Hooks.useEffect,\n useState: Hooks.useState\n) {\n return function useSharedState<T>(state: State<T>): [T, SetSharedState<T>] {\n const [value, setValue] = useState(() => get(state));\n\n useEffect(() => {\n const listener = (_: T, newVal: T) => setValue(newVal);\n subscribe(state, listener);\n return () => unsubscribe(state, listener);\n }, [state]);\n\n return [value, (nextValue: StateUpdater<T>) => set(state, nextValue)];\n };\n}\n\nexport function createUseSelector(\n useEffect: Hooks.useEffect,\n useState: Hooks.useState,\n useMemo: Hooks.useMemo,\n useCallback: Hooks.useCallback\n) {\n return function useSelector<R>(func: (options: SelectorOptions<R>) => R): R {\n const hasSubscribed = useMemo(() => new FakeSet<State<unknown>>(), []);\n const [, setState] = useState(null);\n const fn = useCallback(() => setState({}), []);\n const _get = useCallback(\n <S>(s: State<S>): S => {\n if (!hasSubscribed.has(s)) {\n hasSubscribed.add(s);\n subscribe(s, fn);\n }\n return get(s);\n },\n [hasSubscribed]\n );\n useEffect(() => () => hasSubscribed.forEach((x) => unsubscribe(x, fn)), [\n hasSubscribed,\n fn,\n ]);\n return func({ get: _get });\n };\n}\n\nexport function createUseSharedStateValue(\n useSharedState: ReturnType<typeof createUseSharedState>\n) {\n return function useSharedStateValue<T>(s: State<T>): T {\n return useSharedState(s)[0];\n };\n}\nexport function createUseSetSharedState(\n useSharedState: ReturnType<typeof createUseSharedState>\n) {\n return function useSetSharedState<T>(s: State<T>): SetSharedState<T> {\n return useSharedState(s)[1];\n };\n}\n","import * as factory from \"../../src/_hook_factory\";\n\nimport { useCallback, useEffect, useMemo, useState } from \"react\";\n\nexport const useSharedState = /*#__PURE__*/ factory.createUseSharedState(\n useEffect,\n useState\n);\n\nexport const useSelector = /*#__PURE__*/ factory.createUseSelector(\n useEffect,\n useState,\n useMemo,\n useCallback\n);\n\nexport const useSharedStateValue = /*#__PURE__*/ factory.createUseSharedStateValue(\n useSharedState\n);\n\nexport const useSetSharedState = /*#__PURE__*/ factory.createUseSetSharedState(\n useSharedState\n);\n"],"names":["listenerMap","FakeWeakMap","notify","state","oldValue","newValue","listeners","get","forEach","fn","subscribe","callback","FakeSet","set","add","unsubscribe","delete","valueMap","createState","options","name","_state","initialValue","next","u","consumeUpdater","createUseSharedState","useEffect","useState","value","setValue","listener","_","newVal","nextValue","createUseSelector","useMemo","useCallback","func","hasSubscribed","setState","_get","s","has","x","createUseSharedStateValue","useSharedState","createUseSetSharedState","factory","useSelector","useSharedStateValue","useSetSharedState"],"mappings":"oJAOA,MAAMA,EAAoC,IAAIC,EAE9C,SAAgBC,EAAUC,EAAiBC,EAAaC,GACtD,MAAMC,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUE,QAASC,GAAOA,EAAGL,EAAUC,IAGxD,SAAgBK,EAAaP,EAAiBQ,GAC5C,IAAIL,EAAaN,EAA+BO,IAAIJ,GACnC,MAAbG,IACFA,EAAY,IAAIM,EAChBZ,EAAYa,IAAIV,EAAOG,IAEzBA,EAAUQ,IAAIH,GAGhB,SAAgBI,EAAeZ,EAAiBQ,GAC9C,MAAML,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUU,OAAOL,SCpB5BM,EAAW,IAAIhB,EAErB,SAAgBiB,EAAeC,GAC7B,MAAMhB,EAKR,SAAmBgB,GACjB,MAAO,CAAEC,KAAMD,EAAQC,MANTC,CAAOF,GAAW,IAEhC,OADAF,EAASJ,IAAIV,EAAOgB,EAAQG,cACrBnB,WAOOI,EAAOJ,GACrB,OAAOc,EAASV,IAAIJ,GAGtB,SAAgBU,EAAOV,EAAiBE,GACtC,MAAMD,EAAWG,EAAIJ,GACfoB,WCrB0BC,EAAoBpB,GACpD,MAAiB,mBAANoB,EAA0BA,EAAyBpB,GACvDoB,EDmBMC,CAAepB,EAAUD,GACtCa,EAASJ,IAAIV,EAAOoB,GACpBrB,EAAOC,EAAOC,EAAUmB,YENVG,EACdC,EACAC,GAEA,gBAAkCzB,GAChC,MAAO0B,EAAOC,GAAYF,EAAS,IAAMrB,EAAIJ,IAQ7C,OANAwB,EAAU,KACR,MAAMI,EAAW,CAACC,EAAMC,IAAcH,EAASG,GAE/C,OADAvB,EAAUP,EAAO4B,GACV,IAAMhB,EAAYZ,EAAO4B,IAC/B,CAAC5B,IAEG,CAAC0B,EAAQK,GAA+BrB,EAAIV,EAAO+B,cAI9CC,EACdR,EACAC,EACAQ,EACAC,GAEA,gBAA+BC,GAC7B,MAAMC,EAAgBH,EAAQ,IAAM,IAAIxB,EAA2B,MAC1D4B,GAAYZ,EAAS,MACxBnB,EAAK4B,EAAY,IAAMG,EAAS,IAAK,IACrCC,EAAOJ,EACPK,IACGH,EAAcI,IAAID,KACrBH,EAAczB,IAAI4B,GAClBhC,EAAUgC,EAAGjC,IAERF,EAAImC,IAEb,CAACH,IAMH,OAJAZ,EAAU,IAAM,IAAMY,EAAc/B,QAASoC,GAAM7B,EAAY6B,EAAGnC,IAAM,CACtE8B,EACA9B,IAEK6B,EAAK,CAAE/B,IAAKkC,cAIPI,EACdC,GAEA,gBAAuCJ,GACrC,OAAOI,EAAeJ,GAAG,IAG7B,SAAgBK,EACdD,GAEA,gBAAqCJ,GACnC,OAAOI,EAAeJ,GAAG,ICvEhBI,MAAAA,EAA+BE,EAC1CrB,EACAC,GAGWqB,EAA4BD,EACvCrB,EACAC,EACAQ,EACAC,GAGWa,EAAoCF,EAC/CF,GAGWK,EAAkCH,EAC7CF"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const useSharedState: <T>(state: import(".").State<T>) => [T, import(".").SetSharedState<T>];
|
|
2
|
-
export declare const useSelector: <R>(func: (options: import(".").SelectorOptions<R>) => R) => R;
|
|
3
|
-
export declare const useSharedStateValue: <T>(s: import(".").State<T>) => T;
|
|
4
|
-
export declare const useSetSharedState: <T>(s: import(".").State<T>) => import(".").SetSharedState<T>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { State, SelectorOptions, SetSharedState } from "./types";
|
|
2
|
-
import type { useEffect as UseEffectType, useState as UseStateType, useCallback as UseCallbackType, useMemo as UseMemoType } from "@hydrophobefireman/ui-lib";
|
|
3
|
-
declare namespace Hooks {
|
|
4
|
-
type useEffect = typeof UseEffectType;
|
|
5
|
-
type useState = typeof UseStateType;
|
|
6
|
-
type useCallback = typeof UseCallbackType;
|
|
7
|
-
type useMemo = typeof UseMemoType;
|
|
8
|
-
}
|
|
9
|
-
export declare function createUseSharedState(useEffect: Hooks.useEffect, useState: Hooks.useState): <T>(state: State<T>) => [T, SetSharedState<T>];
|
|
10
|
-
export declare function createUseSelector(useEffect: Hooks.useEffect, useState: Hooks.useState, useMemo: Hooks.useMemo, useCallback: Hooks.useCallback): <R>(func: (options: SelectorOptions<R>) => R) => R;
|
|
11
|
-
export declare function createUseSharedStateValue(useSharedState: ReturnType<typeof createUseSharedState>): <T>(s: State<T>) => T;
|
|
12
|
-
export declare function createUseSetSharedState(useSharedState: ReturnType<typeof createUseSharedState>): <T>(s: State<T>) => SetSharedState<T>;
|
|
13
|
-
export {};
|
package/dist/src/state.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { StateOptions, State, StateUpdater } from "./types";
|
|
2
|
-
export declare function createState<T>(options: StateOptions<T>): State<T>;
|
|
3
|
-
export declare function get<T>(state: State<T>): T;
|
|
4
|
-
export declare function set<T>(state: State<T>, newValue: StateUpdater<T>): void;
|
package/dist/src/subscribe.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { State } from "./types";
|
|
2
|
-
interface Listener<T> {
|
|
3
|
-
(oldValue: T, newValue: T): void;
|
|
4
|
-
}
|
|
5
|
-
export declare function notify<T>(state: State<T>, oldValue: T, newValue: T): void;
|
|
6
|
-
export declare function subscribe<T>(state: State<T>, callback: Listener<T>): void;
|
|
7
|
-
export declare function unsubscribe<T>(state: State<T>, callback: Listener<T>): void;
|
|
8
|
-
export {};
|
package/dist/src/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface StateOptions<T> {
|
|
2
|
-
name?: string;
|
|
3
|
-
initialValue?: T;
|
|
4
|
-
}
|
|
5
|
-
export interface State<T> {
|
|
6
|
-
name: string | void;
|
|
7
|
-
}
|
|
8
|
-
export interface FunctionUpdater<T> {
|
|
9
|
-
(previous?: T): T;
|
|
10
|
-
}
|
|
11
|
-
export interface SetSharedState<T> {
|
|
12
|
-
(val: StateUpdater<T>): void;
|
|
13
|
-
}
|
|
14
|
-
export interface SelectorOptions<T> {
|
|
15
|
-
get(s: State<T>): T;
|
|
16
|
-
}
|
|
17
|
-
export declare type StateUpdater<T> = T | FunctionUpdater<T>;
|
|
18
|
-
export {};
|
package/dist/src/util.d.ts
DELETED
package/dist/state.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { StateOptions, State, StateUpdater } from "./types";
|
|
2
|
-
export declare function createState<T>(options: StateOptions<T>): State<T>;
|
|
3
|
-
export declare function get<T>(state: State<T>): T;
|
|
4
|
-
export declare function set<T>(state: State<T>, newValue: StateUpdater<T>): void;
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{FakeWeakMap as n,FakeSet as t}from"@hydrophobefireman/j-utils";import{useState as o,useEffect as e,useCallback as r,useMemo as u}from"@hydrophobefireman/ui-lib";const c=new n;function i(n,t,o){const e=c.get(n);e&&e.forEach(n=>n(t,o))}function f(n,o){let e=c.get(n);null==e&&(e=new t,c.set(n,e)),e.add(o)}function s(n,t){const o=c.get(n);o&&o.delete(t)}const a=new n;function l(n){const t=function(n){return{name:n.name}}(n||{});return a.set(t,n.initialValue),t}function m(n){return a.get(n)}function d(n,t){const o=m(n),e=function(n,t){return"function"==typeof n?n(t):n}(t,o);a.set(n,e),i(n,o,e)}function h(n,t){return function(o){const[e,r]=t(()=>m(o));return n(()=>{const n=(n,t)=>r(t);return f(o,n),()=>s(o,n)},[o]),[e,n=>d(o,n)]}}function p(n,o,e,r){return function(u){const c=e(()=>new t,[]),[,i]=o(null),a=r(()=>i({}),[]),l=r(n=>(c.has(n)||(c.add(n),f(n,a)),m(n)),[c]);return n(()=>()=>c.forEach(n=>s(n,a)),[c,a]),u({get:l})}}function g(n){return function(t){return n(t)[0]}}function w(n){return function(t){return n(t)[1]}}const b=h(e,o),y=p(e,o,u,r),E=g(b),j=w(b);export{l as createState,m as get,i as notify,d as set,f as subscribe,s as unsubscribe,y as useSelector,j as useSetSharedState,b as useSharedState,E as useSharedStateValue};
|
|
2
|
-
//# sourceMappingURL=statedrive.modern.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"statedrive.modern.js","sources":["../src/subscribe.ts","../src/state.ts","../src/util.ts","../src/_hook_factory.ts","../src/hooks.ts"],"sourcesContent":["import { FakeWeakMap, FakeSet } from \"@hydrophobefireman/j-utils\";\nimport { State } from \"./types\";\n\ninterface Listener<T> {\n (oldValue: T, newValue: T): void;\n}\ntype ListenerMap<T> = FakeWeakMap<State<T>, FakeSet<Listener<T>>>;\nconst listenerMap: ListenerMap<unknown> = new FakeWeakMap();\n\nexport function notify<T>(state: State<T>, oldValue: T, newValue: T) {\n const listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners) listeners.forEach((fn) => fn(oldValue, newValue));\n}\n\nexport function subscribe<T>(state: State<T>, callback: Listener<T>) {\n let listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners == null) {\n listeners = new FakeSet();\n listenerMap.set(state, listeners);\n }\n listeners.add(callback);\n}\n\nexport function unsubscribe<T>(state: State<T>, callback: Listener<T>) {\n const listeners = (listenerMap as ListenerMap<T>).get(state);\n if (listeners) listeners.delete(callback);\n}\n","import { consumeUpdater } from \"./util\";\nimport { StateOptions, State, StateUpdater } from \"./types\";\nimport { notify } from \"./subscribe\";\nimport { FakeWeakMap } from \"@hydrophobefireman/j-utils\";\n\nconst valueMap = new FakeWeakMap<State<unknown>, unknown>();\n\nexport function createState<T>(options: StateOptions<T>): State<T> {\n const state = _state(options || {});\n valueMap.set(state, options.initialValue);\n return state;\n}\n\nfunction _state<T>(options: StateOptions<T> | State<T>) {\n return { name: options.name };\n}\n\nexport function get<T>(state: State<T>): T {\n return valueMap.get(state) as T;\n}\n\nexport function set<T>(state: State<T>, newValue: StateUpdater<T>) {\n const oldValue = get(state);\n const next = consumeUpdater(newValue, oldValue);\n valueMap.set(state, next);\n notify(state, oldValue, next);\n}\n","import { StateUpdater, FunctionUpdater } from \"./types\";\n\nexport function consumeUpdater<T>(u: StateUpdater<T>, oldValue: T) {\n if (typeof u === \"function\") return (u as FunctionUpdater<T>)(oldValue);\n return u;\n}\n","import { State, StateUpdater, SelectorOptions, SetSharedState } from \"./types\";\nimport { subscribe, unsubscribe } from \"./subscribe\";\nimport { get, set } from \"./state\";\nimport { FakeSet } from \"@hydrophobefireman/j-utils\";\n\nimport type {\n useEffect as UseEffectType,\n useState as UseStateType,\n useCallback as UseCallbackType,\n useMemo as UseMemoType,\n} from \"@hydrophobefireman/ui-lib\";\n\nnamespace Hooks {\n export type useEffect = typeof UseEffectType;\n export type useState = typeof UseStateType;\n export type useCallback = typeof UseCallbackType;\n export type useMemo = typeof UseMemoType;\n}\n\nexport function createUseSharedState(\n useEffect: Hooks.useEffect,\n useState: Hooks.useState\n) {\n return function useSharedState<T>(state: State<T>): [T, SetSharedState<T>] {\n const [value, setValue] = useState(() => get(state));\n\n useEffect(() => {\n const listener = (_: T, newVal: T) => setValue(newVal);\n subscribe(state, listener);\n return () => unsubscribe(state, listener);\n }, [state]);\n\n return [value, (nextValue: StateUpdater<T>) => set(state, nextValue)];\n };\n}\n\nexport function createUseSelector(\n useEffect: Hooks.useEffect,\n useState: Hooks.useState,\n useMemo: Hooks.useMemo,\n useCallback: Hooks.useCallback\n) {\n return function useSelector<R>(func: (options: SelectorOptions<R>) => R): R {\n const hasSubscribed = useMemo(() => new FakeSet<State<unknown>>(), []);\n const [, setState] = useState(null);\n const fn = useCallback(() => setState({}), []);\n const _get = useCallback(\n <S>(s: State<S>): S => {\n if (!hasSubscribed.has(s)) {\n hasSubscribed.add(s);\n subscribe(s, fn);\n }\n return get(s);\n },\n [hasSubscribed]\n );\n useEffect(() => () => hasSubscribed.forEach((x) => unsubscribe(x, fn)), [\n hasSubscribed,\n fn,\n ]);\n return func({ get: _get });\n };\n}\n\nexport function createUseSharedStateValue(\n useSharedState: ReturnType<typeof createUseSharedState>\n) {\n return function useSharedStateValue<T>(s: State<T>): T {\n return useSharedState(s)[0];\n };\n}\nexport function createUseSetSharedState(\n useSharedState: ReturnType<typeof createUseSharedState>\n) {\n return function useSetSharedState<T>(s: State<T>): SetSharedState<T> {\n return useSharedState(s)[1];\n };\n}\n","import * as factory from \"./_hook_factory\";\nimport {\n useCallback,\n useEffect,\n useMemo,\n useState,\n} from \"@hydrophobefireman/ui-lib\";\n\nexport const useSharedState = /*#__PURE__*/ factory.createUseSharedState(\n useEffect,\n useState\n);\n\nexport const useSelector = /*#__PURE__*/ factory.createUseSelector(\n useEffect,\n useState,\n useMemo,\n useCallback\n);\n\nexport const useSharedStateValue = /*#__PURE__*/ factory.createUseSharedStateValue(\n useSharedState\n);\n\nexport const useSetSharedState = /*#__PURE__*/ factory.createUseSetSharedState(\n useSharedState\n);\n"],"names":["listenerMap","FakeWeakMap","notify","state","oldValue","newValue","listeners","get","forEach","fn","subscribe","callback","FakeSet","set","add","unsubscribe","delete","valueMap","createState","options","name","_state","initialValue","next","u","consumeUpdater","createUseSharedState","useEffect","useState","value","setValue","listener","_","newVal","nextValue","createUseSelector","useMemo","useCallback","func","hasSubscribed","setState","_get","s","has","x","createUseSharedStateValue","useSharedState","createUseSetSharedState","factory","useSelector","useSharedStateValue","useSetSharedState"],"mappings":"wKAOA,MAAMA,EAAoC,IAAIC,EAE9C,SAAgBC,EAAUC,EAAiBC,EAAaC,GACtD,MAAMC,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUE,QAASC,GAAOA,EAAGL,EAAUC,IAGxD,SAAgBK,EAAaP,EAAiBQ,GAC5C,IAAIL,EAAaN,EAA+BO,IAAIJ,GACnC,MAAbG,IACFA,EAAY,IAAIM,EAChBZ,EAAYa,IAAIV,EAAOG,IAEzBA,EAAUQ,IAAIH,GAGhB,SAAgBI,EAAeZ,EAAiBQ,GAC9C,MAAML,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUU,OAAOL,SCpB5BM,EAAW,IAAIhB,EAErB,SAAgBiB,EAAeC,GAC7B,MAAMhB,EAKR,SAAmBgB,GACjB,MAAO,CAAEC,KAAMD,EAAQC,MANTC,CAAOF,GAAW,IAEhC,OADAF,EAASJ,IAAIV,EAAOgB,EAAQG,cACrBnB,WAOOI,EAAOJ,GACrB,OAAOc,EAASV,IAAIJ,GAGtB,SAAgBU,EAAOV,EAAiBE,GACtC,MAAMD,EAAWG,EAAIJ,GACfoB,WCrB0BC,EAAoBpB,GACpD,MAAiB,mBAANoB,EAA0BA,EAAyBpB,GACvDoB,EDmBMC,CAAepB,EAAUD,GACtCa,EAASJ,IAAIV,EAAOoB,GACpBrB,EAAOC,EAAOC,EAAUmB,YENVG,EACdC,EACAC,GAEA,gBAAkCzB,GAChC,MAAO0B,EAAOC,GAAYF,EAAS,IAAMrB,EAAIJ,IAQ7C,OANAwB,EAAU,KACR,MAAMI,EAAW,CAACC,EAAMC,IAAcH,EAASG,GAE/C,OADAvB,EAAUP,EAAO4B,GACV,IAAMhB,EAAYZ,EAAO4B,IAC/B,CAAC5B,IAEG,CAAC0B,EAAQK,GAA+BrB,EAAIV,EAAO+B,cAI9CC,EACdR,EACAC,EACAQ,EACAC,GAEA,gBAA+BC,GAC7B,MAAMC,EAAgBH,EAAQ,IAAM,IAAIxB,EAA2B,MAC1D4B,GAAYZ,EAAS,MACxBnB,EAAK4B,EAAY,IAAMG,EAAS,IAAK,IACrCC,EAAOJ,EACPK,IACGH,EAAcI,IAAID,KACrBH,EAAczB,IAAI4B,GAClBhC,EAAUgC,EAAGjC,IAERF,EAAImC,IAEb,CAACH,IAMH,OAJAZ,EAAU,IAAM,IAAMY,EAAc/B,QAASoC,GAAM7B,EAAY6B,EAAGnC,IAAM,CACtE8B,EACA9B,IAEK6B,EAAK,CAAE/B,IAAKkC,cAIPI,EACdC,GAEA,gBAAuCJ,GACrC,OAAOI,EAAeJ,GAAG,IAG7B,SAAgBK,EACdD,GAEA,gBAAqCJ,GACnC,OAAOI,EAAeJ,GAAG,ICnEhBI,MAAAA,EAA+BE,EAC1CrB,EACAC,GAGWqB,EAA4BD,EACvCrB,EACAC,EACAQ,EACAC,GAGWa,EAAoCF,EAC/CF,GAGWK,EAAkCH,EAC7CF"}
|
package/dist/subscribe.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { State } from "./types";
|
|
2
|
-
interface Listener<T> {
|
|
3
|
-
(oldValue: T, newValue: T): void;
|
|
4
|
-
}
|
|
5
|
-
export declare function notify<T>(state: State<T>, oldValue: T, newValue: T): void;
|
|
6
|
-
export declare function subscribe<T>(state: State<T>, callback: Listener<T>): void;
|
|
7
|
-
export declare function unsubscribe<T>(state: State<T>, callback: Listener<T>): void;
|
|
8
|
-
export {};
|
package/dist/types.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface StateOptions<T> {
|
|
2
|
-
name?: string;
|
|
3
|
-
initialValue?: T;
|
|
4
|
-
}
|
|
5
|
-
export interface State<T> {
|
|
6
|
-
name: string | void;
|
|
7
|
-
}
|
|
8
|
-
export interface FunctionUpdater<T> {
|
|
9
|
-
(previous?: T): T;
|
|
10
|
-
}
|
|
11
|
-
export interface SetSharedState<T> {
|
|
12
|
-
(val: StateUpdater<T>): void;
|
|
13
|
-
}
|
|
14
|
-
export interface SelectorOptions<T> {
|
|
15
|
-
get(s: State<T>): T;
|
|
16
|
-
}
|
|
17
|
-
export declare type StateUpdater<T> = T | FunctionUpdater<T>;
|
|
18
|
-
export {};
|
package/dist/util.d.ts
DELETED