statedrive 0.0.13 → 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.
Files changed (77) hide show
  1. package/README.md +4 -4
  2. package/package.json +5 -4
  3. package/dist/_hook_factory.d.ts +0 -13
  4. package/dist/hooks.d.ts +0 -4
  5. package/dist/index.d.ts +0 -4
  6. package/dist/react/src/hooks.d.ts +0 -4
  7. package/dist/react/src/index.d.ts +0 -4
  8. package/dist/react.modern.js +0 -84
  9. package/dist/react.modern.js.map +0 -1
  10. package/dist/src/_hook_factory.d.ts +0 -13
  11. package/dist/src/state.d.ts +0 -4
  12. package/dist/src/subscribe.d.ts +0 -8
  13. package/dist/src/types.d.ts +0 -18
  14. package/dist/src/util.d.ts +0 -2
  15. package/dist/state.d.ts +0 -4
  16. package/dist/statedrive.modern.js +0 -2
  17. package/dist/statedrive.modern.js.map +0 -1
  18. package/dist/subscribe.d.ts +0 -8
  19. package/dist/types.d.ts +0 -18
  20. package/dist/util.d.ts +0 -2
  21. package/react/node_modules/@types/prop-types/LICENSE +0 -21
  22. package/react/node_modules/@types/prop-types/README.md +0 -16
  23. package/react/node_modules/@types/prop-types/index.d.ts +0 -92
  24. package/react/node_modules/@types/prop-types/package.json +0 -34
  25. package/react/node_modules/@types/react/LICENSE +0 -21
  26. package/react/node_modules/@types/react/README.md +0 -16
  27. package/react/node_modules/@types/react/experimental.d.ts +0 -181
  28. package/react/node_modules/@types/react/global.d.ts +0 -151
  29. package/react/node_modules/@types/react/index.d.ts +0 -3167
  30. package/react/node_modules/@types/react/jsx-dev-runtime.d.ts +0 -2
  31. package/react/node_modules/@types/react/jsx-runtime.d.ts +0 -2
  32. package/react/node_modules/@types/react/package.json +0 -150
  33. package/react/node_modules/@types/scheduler/LICENSE +0 -21
  34. package/react/node_modules/@types/scheduler/README.md +0 -16
  35. package/react/node_modules/@types/scheduler/index.d.ts +0 -32
  36. package/react/node_modules/@types/scheduler/package.json +0 -29
  37. package/react/node_modules/@types/scheduler/tracing.d.ts +0 -131
  38. package/react/node_modules/csstype/LICENSE +0 -19
  39. package/react/node_modules/csstype/README.md +0 -273
  40. package/react/node_modules/csstype/index.d.ts +0 -20553
  41. package/react/node_modules/csstype/index.js.flow +0 -6278
  42. package/react/node_modules/csstype/package.json +0 -62
  43. package/react/node_modules/js-tokens/CHANGELOG.md +0 -151
  44. package/react/node_modules/js-tokens/LICENSE +0 -21
  45. package/react/node_modules/js-tokens/README.md +0 -240
  46. package/react/node_modules/js-tokens/index.js +0 -23
  47. package/react/node_modules/js-tokens/package.json +0 -30
  48. package/react/node_modules/loose-envify/LICENSE +0 -21
  49. package/react/node_modules/loose-envify/README.md +0 -45
  50. package/react/node_modules/loose-envify/cli.js +0 -16
  51. package/react/node_modules/loose-envify/custom.js +0 -4
  52. package/react/node_modules/loose-envify/index.js +0 -3
  53. package/react/node_modules/loose-envify/loose-envify.js +0 -36
  54. package/react/node_modules/loose-envify/package.json +0 -36
  55. package/react/node_modules/loose-envify/replace.js +0 -65
  56. package/react/node_modules/object-assign/index.js +0 -90
  57. package/react/node_modules/object-assign/license +0 -21
  58. package/react/node_modules/object-assign/package.json +0 -42
  59. package/react/node_modules/object-assign/readme.md +0 -61
  60. package/react/node_modules/react/LICENSE +0 -21
  61. package/react/node_modules/react/README.md +0 -13
  62. package/react/node_modules/react/build-info.json +0 -8
  63. package/react/node_modules/react/cjs/react-jsx-dev-runtime.development.js +0 -1203
  64. package/react/node_modules/react/cjs/react-jsx-dev-runtime.production.min.js +0 -9
  65. package/react/node_modules/react/cjs/react-jsx-dev-runtime.profiling.min.js +0 -9
  66. package/react/node_modules/react/cjs/react-jsx-runtime.development.js +0 -1221
  67. package/react/node_modules/react/cjs/react-jsx-runtime.production.min.js +0 -10
  68. package/react/node_modules/react/cjs/react-jsx-runtime.profiling.min.js +0 -10
  69. package/react/node_modules/react/cjs/react.development.js +0 -2333
  70. package/react/node_modules/react/cjs/react.production.min.js +0 -23
  71. package/react/node_modules/react/index.js +0 -7
  72. package/react/node_modules/react/jsx-dev-runtime.js +0 -7
  73. package/react/node_modules/react/jsx-runtime.js +0 -7
  74. package/react/node_modules/react/package.json +0 -39
  75. package/react/node_modules/react/umd/react.development.js +0 -3357
  76. package/react/node_modules/react/umd/react.production.min.js +0 -31
  77. package/react/node_modules/react/umd/react.profiling.min.js +0 -36
package/README.md CHANGED
@@ -6,7 +6,7 @@ easy shared state across the entire app
6
6
 
7
7
  Each state is a unique atom to which you can attach event listeners and run state updates.
8
8
 
9
- # installation
9
+ # Installation
10
10
 
11
11
  `npm i statedrive` or `yarn add statedrive`
12
12
 
@@ -20,7 +20,7 @@ import { createState } from "statedrive";
20
20
 
21
21
  ## For react
22
22
 
23
- ```
23
+ ```js
24
24
  import {createState} from "statedrive/react"
25
25
  ```
26
26
 
@@ -28,7 +28,7 @@ everything else is the same.
28
28
 
29
29
  # Basic Usage
30
30
 
31
- 1. create a state atom
31
+ 1. Create a state atom
32
32
  state.js
33
33
  ```js
34
34
  import { createState } from "statedrive";
@@ -48,7 +48,7 @@ everything else is the same.
48
48
  return <div>You Entered {name}</div>;
49
49
  }
50
50
  ```
51
- 3. use it within your app elsewhere (any place where hooks don't work)
51
+ 3. Use it within your app elsewhere (any place where hooks don't work)
52
52
  util.js
53
53
  ```js
54
54
  import { get, set } from "statedrive";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "statedrive",
3
- "version": "0.0.13",
3
+ "version": "0.0.14",
4
4
  "description": "",
5
5
  "main": "dist/statedrive.modern.js",
6
6
  "module": "dist/statedrive.modern.js",
@@ -28,10 +28,11 @@
28
28
  "sideEffects": false,
29
29
  "homepage": "https://github.com/Hydrophobefireman/statedrive#readme",
30
30
  "devDependencies": {
31
- "microbundle": "^0.13.0",
32
- "typescript": "^4.2.4"
31
+ "microbundle": "^0.13.3",
32
+ "typescript": "^4.3.2"
33
33
  },
34
34
  "peerDependencies": {
35
- "@hydrophobefireman/ui-lib": "^1.9.5"
35
+ "@hydrophobefireman/ui-lib": "latest",
36
+ "react": "latest"
36
37
  }
37
38
  }
@@ -1,13 +0,0 @@
1
- import { SelectorOptions, SetSharedState, State } from "./types";
2
- import type { useCallback as UseCallbackType, useEffect as UseEffectType, useMemo as UseMemoType, useState as UseStateType } 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
@@ -1,4 +0,0 @@
1
- export { createState, get, set } from "./state";
2
- export { notify, subscribe, unsubscribe } from "./subscribe";
3
- export * from "./types";
4
- export * from "./hooks";
@@ -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,4 +0,0 @@
1
- export { createState, get, set } from "../../src/state";
2
- export { notify, subscribe, unsubscribe } from "../../src/subscribe";
3
- export * from "../../src/types";
4
- export * from "./hooks";
@@ -1,84 +0,0 @@
1
- import {
2
- useCallback as e,
3
- useState as n,
4
- useMemo as o,
5
- useEffect as t,
6
- } from "react";
7
- const u = new WeakMap();
8
- function r(n, t, e) {
9
- const o = u.get(n);
10
- o && o.forEach((n) => n(t, e));
11
- }
12
- function c(n, t) {
13
- let e = u.get(n);
14
- null == e && ((e = new Set()), u.set(n, e)), e.add(t);
15
- }
16
- function f(n, t) {
17
- const e = u.get(n);
18
- e && e.delete(t);
19
- }
20
- const i = new WeakMap();
21
- function a(n) {
22
- const t = (function (n) {
23
- return { name: n.name };
24
- })(n || {});
25
- return i.set(t, n.initialValue), t;
26
- }
27
- function s(n) {
28
- return i.get(n);
29
- }
30
- function l(n, t) {
31
- const e = s(n),
32
- o = (function (n, t) {
33
- return "function" == typeof n ? n(t) : n;
34
- })(t, e);
35
- i.set(n, o), r(n, e, o);
36
- }
37
- function d(n, t) {
38
- return function (e) {
39
- const [o, u] = t(() => s(e));
40
- return (
41
- n(() => {
42
- const n = (n, t) => u(t);
43
- return c(e, n), () => f(e, n);
44
- }, [e]),
45
- [o, (n) => l(e, n)]
46
- );
47
- };
48
- }
49
- function g(n, t, e, o) {
50
- return function (u) {
51
- const r = e(() => new Set(), []),
52
- [, i] = t(null),
53
- a = o(() => i({}), []),
54
- l = o((n) => (r.has(n) || (r.add(n), c(n, a)), s(n)), [r]);
55
- return n(() => () => r.forEach((n) => f(n, a)), [r, a]), u({ get: l });
56
- };
57
- }
58
- function p(n) {
59
- return function (t) {
60
- return n(t)[0];
61
- };
62
- }
63
- function m(n) {
64
- return function (t) {
65
- return n(t)[1];
66
- };
67
- }
68
- const w = d(t, n),
69
- h = g(t, n, o, e),
70
- k = p(w),
71
- E = m(w);
72
- export {
73
- a as createState,
74
- s as get,
75
- r as notify,
76
- l as set,
77
- c as subscribe,
78
- f as unsubscribe,
79
- h as useSelector,
80
- E as useSetSharedState,
81
- w as useSharedState,
82
- k as useSharedStateValue,
83
- };
84
- //# sourceMappingURL=react.modern.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"react.modern.js","sources":["../src/subscribe.ts","../src/state.ts","../src/util.ts","../src/_hook_factory.ts","../react/src/hooks.ts"],"sourcesContent":["import { State } from \"./types\";\n\ninterface Listener<T> {\n (oldValue: T, newValue: T): void;\n}\ntype ListenerMap<T> = WeakMap<State<T>, Set<Listener<T>>>;\nconst listenerMap: ListenerMap<unknown> = new WeakMap();\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 Set();\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\";\n\nconst valueMap = new WeakMap<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 { SelectorOptions, SetSharedState, State, StateUpdater } from \"./types\";\nimport type {\n useCallback as UseCallbackType,\n useEffect as UseEffectType,\n useMemo as UseMemoType,\n useState as UseStateType,\n} from \"@hydrophobefireman/ui-lib\";\nimport { get, set } from \"./state\";\nimport { subscribe, unsubscribe } from \"./subscribe\";\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 Set<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(\n () => () => hasSubscribed.forEach((x) => unsubscribe(x, fn)),\n [hasSubscribed, 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","WeakMap","notify","state","oldValue","newValue","listeners","get","forEach","fn","subscribe","callback","Set","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":"8EAMA,MAAMA,EAAoC,IAAIC,iBAE9BC,EAAUC,EAAiBC,EAAaC,GACtD,MAAMC,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUE,QAASC,GAAOA,EAAGL,EAAUC,aAGxCK,EAAaP,EAAiBQ,GAC5C,IAAIL,EAAaN,EAA+BO,IAAIJ,GACnC,MAAbG,IACFA,EAAY,IAAIM,IAChBZ,EAAYa,IAAIV,EAAOG,IAEzBA,EAAUQ,IAAIH,YAGAI,EAAeZ,EAAiBQ,GAC9C,MAAML,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUU,OAAOL,GCpBlC,MAAMM,EAAW,IAAIhB,iBAELiB,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,YAGNU,EAAOV,EAAiBE,GACtC,MAAMD,EAAWG,EAAIJ,GACfoB,WCpB0BC,EAAoBpB,GACpD,MAAiB,mBAANoB,EAA0BA,EAAyBpB,GACvDoB,EDkBMC,CAAepB,EAAUD,GACtCa,EAASJ,IAAIV,EAAOoB,GACpBrB,EAAOC,EAAOC,EAAUmB,YEPVG,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,IAAuB,MACtD4B,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,EACE,IAAM,IAAMY,EAAc/B,QAASoC,GAAM7B,EAAY6B,EAAGnC,IACxD,CAAC8B,EAAe9B,IAEX6B,EAAK,CAAE/B,IAAKkC,cAIPI,EACdC,GAEA,gBAAuCJ,GACrC,OAAOI,EAAeJ,GAAG,aAGbK,EACdD,GAEA,gBAAqCJ,GACnC,OAAOI,EAAeJ,GAAG,ICrEhBI,MAAAA,EAA+BE,EAC1CrB,EACAC,GAGWqB,EAA4BD,EACvCrB,EACAC,EACAQ,EACAC,GAGWa,EAAoCF,EAC/CF,GAGWK,EAAkCH,EAC7CF"}
@@ -1,13 +0,0 @@
1
- import { SelectorOptions, SetSharedState, State } from "./types";
2
- import type { useCallback as UseCallbackType, useEffect as UseEffectType, useMemo as UseMemoType, useState as UseStateType } 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 {};
@@ -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,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 {};
@@ -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 {};
@@ -1,2 +0,0 @@
1
- import { StateUpdater } from "./types";
2
- export declare function consumeUpdater<T>(u: StateUpdater<T>, oldValue: T): T;
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{useState as n,useEffect as t,useCallback as e,useMemo as o}from"@hydrophobefireman/ui-lib";const u=new WeakMap;function r(n,t,e){const o=u.get(n);o&&o.forEach(n=>n(t,e))}function c(n,t){let e=u.get(n);null==e&&(e=new Set,u.set(n,e)),e.add(t)}function i(n,t){const e=u.get(n);e&&e.delete(t)}const f=new WeakMap;function a(n){const t=function(n){return{name:n.name}}(n||{});return f.set(t,n.initialValue),t}function s(n){return f.get(n)}function l(n,t){const e=s(n),o=function(n,t){return"function"==typeof n?n(t):n}(t,e);f.set(n,o),r(n,e,o)}function d(n,t){return function(e){const[o,u]=t(()=>s(e));return n(()=>{const n=(n,t)=>u(t);return c(e,n),()=>i(e,n)},[e]),[o,n=>l(e,n)]}}function p(n,t,e,o){return function(u){const r=e(()=>new Set,[]),[,f]=t(null),a=o(()=>f({}),[]),l=o(n=>(r.has(n)||(r.add(n),c(n,a)),s(n)),[r]);return n(()=>()=>r.forEach(n=>i(n,a)),[r,a]),u({get:l})}}function g(n){return function(t){return n(t)[0]}}function h(n){return function(t){return n(t)[1]}}const m=d(t,n),w=p(t,n,o,e),b=g(m),k=h(m);export{a as createState,s as get,r as notify,l as set,c as subscribe,i as unsubscribe,w as useSelector,k as useSetSharedState,m as useSharedState,b 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 { State } from \"./types\";\n\ninterface Listener<T> {\n (oldValue: T, newValue: T): void;\n}\ntype ListenerMap<T> = WeakMap<State<T>, Set<Listener<T>>>;\nconst listenerMap: ListenerMap<unknown> = new WeakMap();\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 Set();\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\";\n\nconst valueMap = new WeakMap<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 { SelectorOptions, SetSharedState, State, StateUpdater } from \"./types\";\nimport type {\n useCallback as UseCallbackType,\n useEffect as UseEffectType,\n useMemo as UseMemoType,\n useState as UseStateType,\n} from \"@hydrophobefireman/ui-lib\";\nimport { get, set } from \"./state\";\nimport { subscribe, unsubscribe } from \"./subscribe\";\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 Set<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(\n () => () => hasSubscribed.forEach((x) => unsubscribe(x, fn)),\n [hasSubscribed, 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","WeakMap","notify","state","oldValue","newValue","listeners","get","forEach","fn","subscribe","callback","Set","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":"kGAMA,MAAMA,EAAoC,IAAIC,iBAE9BC,EAAUC,EAAiBC,EAAaC,GACtD,MAAMC,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUE,QAASC,GAAOA,EAAGL,EAAUC,aAGxCK,EAAaP,EAAiBQ,GAC5C,IAAIL,EAAaN,EAA+BO,IAAIJ,GACnC,MAAbG,IACFA,EAAY,IAAIM,IAChBZ,EAAYa,IAAIV,EAAOG,IAEzBA,EAAUQ,IAAIH,YAGAI,EAAeZ,EAAiBQ,GAC9C,MAAML,EAAaN,EAA+BO,IAAIJ,GAClDG,GAAWA,EAAUU,OAAOL,GCpBlC,MAAMM,EAAW,IAAIhB,iBAELiB,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,YAGNU,EAAOV,EAAiBE,GACtC,MAAMD,EAAWG,EAAIJ,GACfoB,WCpB0BC,EAAoBpB,GACpD,MAAiB,mBAANoB,EAA0BA,EAAyBpB,GACvDoB,EDkBMC,CAAepB,EAAUD,GACtCa,EAASJ,IAAIV,EAAOoB,GACpBrB,EAAOC,EAAOC,EAAUmB,YEPVG,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,IAAuB,MACtD4B,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,EACE,IAAM,IAAMY,EAAc/B,QAASoC,GAAM7B,EAAY6B,EAAGnC,IACxD,CAAC8B,EAAe9B,IAEX6B,EAAK,CAAE/B,IAAKkC,cAIPI,EACdC,GAEA,gBAAuCJ,GACrC,OAAOI,EAAeJ,GAAG,aAGbK,EACdD,GAEA,gBAAqCJ,GACnC,OAAOI,EAAeJ,GAAG,ICjEhBI,MAAAA,EAA+BE,EAC1CrB,EACAC,GAGWqB,EAA4BD,EACvCrB,EACAC,EACAQ,EACAC,GAGWa,EAAoCF,EAC/CF,GAGWK,EAAkCH,EAC7CF"}
@@ -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
@@ -1,2 +0,0 @@
1
- import { StateUpdater } from "./types";
2
- export declare function consumeUpdater<T>(u: StateUpdater<T>, oldValue: T): T;
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation. 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
@@ -1,16 +0,0 @@
1
- # Installation
2
- > `npm install --save @types/prop-types`
3
-
4
- # Summary
5
- This package contains type definitions for prop-types (https://github.com/reactjs/prop-types).
6
-
7
- # Details
8
- Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/prop-types
9
-
10
- Additional Details
11
- * Last updated: Tue, 24 Sep 2019 20:14:29 GMT
12
- * Dependencies: none
13
- * Global values: none
14
-
15
- # Credits
16
- These definitions were written by DovydasNavickas <https://github.com/DovydasNavickas>, Ferdy Budhidharma <https://github.com/ferdaber>, and Sebastian Silbermann <https://github.com/eps1lon>.
@@ -1,92 +0,0 @@
1
- // Type definitions for prop-types 15.7
2
- // Project: https://github.com/reactjs/prop-types, https://facebook.github.io/react
3
- // Definitions by: DovydasNavickas <https://github.com/DovydasNavickas>
4
- // Ferdy Budhidharma <https://github.com/ferdaber>
5
- // Sebastian Silbermann <https://github.com/eps1lon>
6
- // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
- // TypeScript Version: 2.8
8
-
9
- export type ReactComponentLike =
10
- | string
11
- | ((props: any, context?: any) => any)
12
- | (new (props: any, context?: any) => any);
13
-
14
- export interface ReactElementLike {
15
- type: ReactComponentLike;
16
- props: any;
17
- key: string | number | null;
18
- }
19
-
20
- export interface ReactNodeArray extends Array<ReactNodeLike> {}
21
-
22
- export type ReactNodeLike =
23
- | {}
24
- | ReactElementLike
25
- | ReactNodeArray
26
- | string
27
- | number
28
- | boolean
29
- | null
30
- | undefined;
31
-
32
- export const nominalTypeHack: unique symbol;
33
-
34
- export type IsOptional<T> = undefined extends T ? true : false;
35
-
36
- export type RequiredKeys<V> = { [K in keyof V]-?: Exclude<V[K], undefined> extends Validator<infer T> ? IsOptional<T> extends true ? never : K : never }[keyof V];
37
- export type OptionalKeys<V> = Exclude<keyof V, RequiredKeys<V>>;
38
- export type InferPropsInner<V> = { [K in keyof V]-?: InferType<V[K]>; };
39
-
40
- export interface Validator<T> {
41
- (props: { [key: string]: any }, propName: string, componentName: string, location: string, propFullName: string): Error | null;
42
- [nominalTypeHack]?: {
43
- type: T;
44
- };
45
- }
46
-
47
- export interface Requireable<T> extends Validator<T | undefined | null> {
48
- isRequired: Validator<NonNullable<T>>;
49
- }
50
-
51
- export type ValidationMap<T> = { [K in keyof T]?: Validator<T[K]> };
52
-
53
- export type InferType<V> = V extends Validator<infer T> ? T : any;
54
- export type InferProps<V> =
55
- & InferPropsInner<Pick<V, RequiredKeys<V>>>
56
- & Partial<InferPropsInner<Pick<V, OptionalKeys<V>>>>;
57
-
58
- export const any: Requireable<any>;
59
- export const array: Requireable<any[]>;
60
- export const bool: Requireable<boolean>;
61
- export const func: Requireable<(...args: any[]) => any>;
62
- export const number: Requireable<number>;
63
- export const object: Requireable<object>;
64
- export const string: Requireable<string>;
65
- export const node: Requireable<ReactNodeLike>;
66
- export const element: Requireable<ReactElementLike>;
67
- export const symbol: Requireable<symbol>;
68
- export const elementType: Requireable<ReactComponentLike>;
69
- export function instanceOf<T>(expectedClass: new (...args: any[]) => T): Requireable<T>;
70
- export function oneOf<T>(types: ReadonlyArray<T>): Requireable<T>;
71
- export function oneOfType<T extends Validator<any>>(types: T[]): Requireable<NonNullable<InferType<T>>>;
72
- export function arrayOf<T>(type: Validator<T>): Requireable<T[]>;
73
- export function objectOf<T>(type: Validator<T>): Requireable<{ [K in keyof any]: T; }>;
74
- export function shape<P extends ValidationMap<any>>(type: P): Requireable<InferProps<P>>;
75
- export function exact<P extends ValidationMap<any>>(type: P): Requireable<Required<InferProps<P>>>;
76
-
77
- /**
78
- * Assert that the values match with the type specs.
79
- * Error messages are memorized and will only be shown once.
80
- *
81
- * @param typeSpecs Map of name to a ReactPropType
82
- * @param values Runtime values that need to be type-checked
83
- * @param location e.g. "prop", "context", "child context"
84
- * @param componentName Name of the component for error messages
85
- * @param getStack Returns the component stack
86
- */
87
- export function checkPropTypes(typeSpecs: any, values: any, location: string, componentName: string, getStack?: () => any): void;
88
-
89
- /**
90
- * Only available if NODE_ENV=production
91
- */
92
- export function resetWarningCache(): void;
@@ -1,34 +0,0 @@
1
- {
2
- "name": "@types/prop-types",
3
- "version": "15.7.3",
4
- "description": "TypeScript definitions for prop-types",
5
- "license": "MIT",
6
- "contributors": [
7
- {
8
- "name": "DovydasNavickas",
9
- "url": "https://github.com/DovydasNavickas",
10
- "githubUsername": "DovydasNavickas"
11
- },
12
- {
13
- "name": "Ferdy Budhidharma",
14
- "url": "https://github.com/ferdaber",
15
- "githubUsername": "ferdaber"
16
- },
17
- {
18
- "name": "Sebastian Silbermann",
19
- "url": "https://github.com/eps1lon",
20
- "githubUsername": "eps1lon"
21
- }
22
- ],
23
- "main": "",
24
- "types": "index",
25
- "repository": {
26
- "type": "git",
27
- "url": "https://github.com/DefinitelyTyped/DefinitelyTyped.git",
28
- "directory": "types/prop-types"
29
- },
30
- "scripts": {},
31
- "dependencies": {},
32
- "typesPublisherContentHash": "09cbaa49bc0d7139a168388028da20f8772c641a1e83848ef2cdcd0f91c7ee79",
33
- "typeScriptVersion": "2.8"
34
- }
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation.
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
@@ -1,16 +0,0 @@
1
- # Installation
2
- > `npm install --save @types/react`
3
-
4
- # Summary
5
- This package contains type definitions for React (http://facebook.github.io/react/).
6
-
7
- # Details
8
- Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/react.
9
-
10
- ### Additional Details
11
- * Last updated: Tue, 04 May 2021 21:01:29 GMT
12
- * Dependencies: [@types/csstype](https://npmjs.com/package/@types/csstype), [@types/prop-types](https://npmjs.com/package/@types/prop-types), [@types/scheduler](https://npmjs.com/package/@types/scheduler)
13
- * Global values: `React`
14
-
15
- # Credits
16
- These definitions were written by [Asana](https://asana.com), [AssureSign](http://www.assuresign.com), [Microsoft](https://microsoft.com), [John Reilly](https://github.com/johnnyreilly), [Benoit Benezech](https://github.com/bbenezech), [Patricio Zavolinsky](https://github.com/pzavolinsky), [Digiguru](https://github.com/digiguru), [Eric Anderson](https://github.com/ericanderson), [Dovydas Navickas](https://github.com/DovydasNavickas), [Josh Rutherford](https://github.com/theruther4d), [Guilherme Hübner](https://github.com/guilhermehubner), [Ferdy Budhidharma](https://github.com/ferdaber), [Johann Rakotoharisoa](https://github.com/jrakotoharisoa), [Olivier Pascal](https://github.com/pascaloliv), [Martin Hochel](https://github.com/hotell), [Frank Li](https://github.com/franklixuefei), [Jessica Franco](https://github.com/Jessidhia), [Saransh Kataria](https://github.com/saranshkataria), [Kanitkorn Sujautra](https://github.com/lukyth), [Sebastian Silbermann](https://github.com/eps1lon), [Kyle Scully](https://github.com/zieka), [Cong Zhang](https://github.com/dancerphil), [Dimitri Mitropoulos](https://github.com/dimitropoulos), [JongChan Choi](https://github.com/disjukr), [Victor Magalhães](https://github.com/vhfmag), and [Dale Tan](https://github.com/hellatan).