valdres 0.2.0-alpha.2 → 0.2.0-alpha.21

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 (94) hide show
  1. package/dist/index.js +527 -259
  2. package/dist/types/index.d.ts +26 -0
  3. package/dist/types/src/atom.d.ts +16 -0
  4. package/dist/types/src/atomFamily.d.ts +10 -0
  5. package/dist/types/src/createStoreWithSelectorSet.d.ts +2 -0
  6. package/dist/types/src/lib/atomFamilyAtom.d.ts +8 -0
  7. package/dist/types/src/lib/createStoreData.d.ts +3 -0
  8. package/dist/types/src/lib/getState.d.ts +7 -0
  9. package/dist/types/src/lib/globalAtom.d.ts +4 -0
  10. package/dist/{src → types/src}/lib/initAtom.d.ts +2 -1
  11. package/dist/{src → types/src}/lib/initSelector.d.ts +1 -1
  12. package/dist/types/src/lib/propagateUpdatedAtoms.d.ts +4 -0
  13. package/dist/types/src/lib/setAtom.d.ts +3 -0
  14. package/dist/types/src/lib/storeFromStoreData.d.ts +4 -0
  15. package/dist/{src → types/src}/lib/transaction.d.ts +2 -1
  16. package/dist/types/src/lib/unsubscribe.d.ts +5 -0
  17. package/dist/{src → types/src}/lib/updateStateSubscribers.d.ts +1 -1
  18. package/dist/types/src/selector.d.ts +4 -0
  19. package/dist/types/src/selectorFamily.d.ts +3 -0
  20. package/dist/types/src/store.d.ts +1 -0
  21. package/dist/types/src/types/Atom.d.ts +12 -0
  22. package/dist/types/src/types/AtomDefaultValue.d.ts +2 -0
  23. package/dist/types/src/types/AtomFamily.d.ts +12 -0
  24. package/dist/types/src/types/AtomFamilyAtom.d.ts +6 -0
  25. package/dist/types/src/types/AtomFamilyGlobalAtom.d.ts +5 -0
  26. package/dist/types/src/types/AtomFamilySelector.d.ts +6 -0
  27. package/dist/types/src/types/AtomOnInit.d.ts +2 -0
  28. package/dist/types/src/types/AtomOnSet.d.ts +2 -0
  29. package/dist/types/src/types/AtomOptions.d.ts +11 -0
  30. package/dist/{src → types/src}/types/Family.d.ts +1 -1
  31. package/dist/types/src/types/FamilyKey.d.ts +3 -0
  32. package/dist/types/src/types/GetValue.d.ts +8 -0
  33. package/dist/types/src/types/GlobalAtom.d.ts +5 -0
  34. package/dist/types/src/types/GlobalAtomSetSelfFunc.d.ts +1 -0
  35. package/dist/types/src/types/ResetAtom.d.ts +2 -0
  36. package/dist/types/src/types/Selector.d.ts +9 -0
  37. package/dist/types/src/types/SelectorFamily.d.ts +5 -0
  38. package/dist/types/src/types/SelectorOptions.d.ts +3 -0
  39. package/dist/types/src/types/SetAtom.d.ts +3 -0
  40. package/dist/types/src/types/SetAtomValue.d.ts +1 -0
  41. package/dist/types/src/types/Store.d.ts +24 -0
  42. package/dist/{src → types/src}/types/StoreData.d.ts +9 -1
  43. package/dist/types/src/types/Subscription.d.ts +1 -0
  44. package/dist/types/src/utils/isAtom.d.ts +2 -0
  45. package/dist/types/src/utils/isAtomFamily.d.ts +2 -0
  46. package/dist/types/src/utils/isFamily.d.ts +1 -0
  47. package/dist/types/src/utils/isFamilyAtom.d.ts +2 -0
  48. package/dist/types/src/utils/isFamilySelector.d.ts +2 -0
  49. package/dist/types/src/utils/isFamilyState.d.ts +3 -0
  50. package/dist/types/src/utils/isSelector.d.ts +2 -0
  51. package/dist/types/src/utils/isSelectorFamily.d.ts +2 -0
  52. package/package.json +12 -7
  53. package/dist/src/atom.d.ts +0 -9
  54. package/dist/src/atom.test.d.ts +0 -1
  55. package/dist/src/atomFamily.d.ts +0 -2
  56. package/dist/src/atomFamily.test.d.ts +0 -1
  57. package/dist/src/createStore.d.ts +0 -2
  58. package/dist/src/createStore.test.d.ts +0 -1
  59. package/dist/src/getDefaultStore.d.ts +0 -2
  60. package/dist/src/lib/getState.d.ts +0 -3
  61. package/dist/src/lib/initAtom.test.d.ts +0 -1
  62. package/dist/src/lib/initSelector.test.d.ts +0 -1
  63. package/dist/src/lib/propagateUpdatedAtoms.d.ts +0 -3
  64. package/dist/src/lib/recursivlyUpdateSelectors.d.ts +0 -1
  65. package/dist/src/lib/setAtom.d.ts +0 -3
  66. package/dist/src/lib/setAtom.test.d.ts +0 -1
  67. package/dist/src/lib/subscribe.test.d.ts +0 -1
  68. package/dist/src/lib/transaction.test.d.ts +0 -1
  69. package/dist/src/lib/unsubscribe.d.ts +0 -3
  70. package/dist/src/selector.d.ts +0 -3
  71. package/dist/src/selector.test.d.ts +0 -1
  72. package/dist/src/selectorFamily.d.ts +0 -2
  73. package/dist/src/selectorFamily.test.d.ts +0 -1
  74. package/dist/src/types/Atom.d.ts +0 -9
  75. package/dist/src/types/AtomFamily.d.ts +0 -5
  76. package/dist/src/types/GetValue.d.ts +0 -2
  77. package/dist/src/types/ResetAtom.d.ts +0 -2
  78. package/dist/src/types/Selector.d.ts +0 -8
  79. package/dist/src/types/SelectorFamily.d.ts +0 -5
  80. package/dist/src/types/SetAtom.d.ts +0 -2
  81. package/dist/src/types/Store.d.ts +0 -14
  82. package/dist/src/utils/isAtom.d.ts +0 -3
  83. package/dist/src/utils/isFamily.d.ts +0 -1
  84. package/dist/src/utils/isSelector.d.ts +0 -2
  85. package/dist/test/utils/wait.d.ts +0 -2
  86. /package/dist/{src → types/src}/lib/resetAtom.d.ts +0 -0
  87. /package/dist/{src → types/src}/lib/setAtoms.d.ts +0 -0
  88. /package/dist/{src → types/src}/lib/stableStringify.d.ts +0 -0
  89. /package/dist/{src → types/src}/lib/subscribe.d.ts +0 -0
  90. /package/dist/{src → types/src}/lib/updateSelectorSubscribers.d.ts +0 -0
  91. /package/dist/{src → types/src}/types/State.d.ts +0 -0
  92. /package/dist/{src → types/src}/types/SubscribeFn.d.ts +0 -0
  93. /package/dist/{src → types/src}/types/TransactionFn.d.ts +0 -0
  94. /package/dist/{src → types/src}/utils/isPromiseLike.d.ts +0 -0
@@ -0,0 +1,26 @@
1
+ export { atom } from "./src/atom";
2
+ export { atomFamily } from "./src/atomFamily";
3
+ export { createStoreWithSelectorSet } from "./src/createStoreWithSelectorSet";
4
+ export { selector } from "./src/selector";
5
+ export { selectorFamily } from "./src/selectorFamily";
6
+ export { store } from "./src/store";
7
+ export { isAtom } from "./src/utils/isAtom";
8
+ export { isAtomFamily } from "./src/utils/isAtomFamily";
9
+ export { isFamily } from "./src/utils/isFamily";
10
+ export { isFamilyAtom } from "./src/utils/isFamilyAtom";
11
+ export { isFamilySelector } from "./src/utils/isFamilySelector";
12
+ export { isFamilyState } from "./src/utils/isFamilyState";
13
+ export { isPromiseLike } from "./src/utils/isPromiseLike";
14
+ export { isSelector } from "./src/utils/isSelector";
15
+ export { isSelectorFamily } from "./src/utils/isSelectorFamily";
16
+ export type { Atom } from "./src/types/Atom";
17
+ export type { AtomFamily } from "./src/types/AtomFamily";
18
+ export type { GetValue } from "./src/types/GetValue";
19
+ export type { ResetAtom } from "./src/types/ResetAtom";
20
+ export type { Selector } from "./src/types/Selector";
21
+ export type { SelectorFamily } from "./src/types/SelectorFamily";
22
+ export type { SetAtom } from "./src/types/SetAtom";
23
+ export type { SetAtomValue } from "./src/types/SetAtomValue";
24
+ export type { State } from "./src/types/State";
25
+ export type { Store } from "./src/types/Store";
26
+ export type { StoreData } from "./src/types/StoreData";
@@ -0,0 +1,16 @@
1
+ import type { Atom } from "./types/Atom";
2
+ import type { AtomDefaultValue } from "./types/AtomDefaultValue";
3
+ import type { AtomOptions } from "./types/AtomOptions";
4
+ import type { GlobalAtom } from "./types/GlobalAtom";
5
+ /**
6
+ * [Docs Reference](https://valdres.dev/valdres/api/atom)
7
+ *
8
+ * @example
9
+ *
10
+ * const user = atom<string>("Default Value", { label: "userAtom"})
11
+ *
12
+ */
13
+ export declare function atom<V>(defaultValue: AtomDefaultValue<V>, options: AtomOptions<V> & {
14
+ global: true;
15
+ }): GlobalAtom<V>;
16
+ export declare function atom<V>(defaultValue?: AtomDefaultValue<V>, options?: AtomOptions<V>): Atom<V>;
@@ -0,0 +1,10 @@
1
+ import type { AtomFamily } from "./types/AtomFamily";
2
+ import type { AtomOptions } from "./types/AtomOptions";
3
+ import type { FamilyKey } from "./types/FamilyKey";
4
+ import type { Selector } from "./types/Selector";
5
+ import type { SelectorFamily } from "./types/SelectorFamily";
6
+ type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
7
+ type AtomFamilyDefaultValue<Key, Value> = undefined | Value | DefaultValueCallback<Key, Value> | Selector<Value> | SelectorFamily<Value, Key>;
8
+ /** [Docs Reference](https://valdres.dev/valdres/api/atomFamily) */
9
+ export declare function atomFamily<Key = FamilyKey, Value = unknown>(defaultValue?: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>): AtomFamily<Key, Value>;
10
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Store } from "./types/Store";
2
+ export declare const createStoreWithSelectorSet: (id?: string) => Store;
@@ -0,0 +1,8 @@
1
+ import type { AtomDefaultValue } from "../types/AtomDefaultValue";
2
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
3
+ import type { AtomFamilyGlobalAtom } from "../types/AtomFamilyGlobalAtom";
4
+ import type { AtomOptions } from "../types/AtomOptions";
5
+ export declare function atomFamilyAtom<Key, Value>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value> & {
6
+ global: true;
7
+ }): AtomFamilyGlobalAtom<Key, Value>;
8
+ export declare function atomFamilyAtom<Key, Value>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value>): AtomFamilyAtom<Key, Value>;
@@ -0,0 +1,3 @@
1
+ import type { ScopedStoreData, StoreData } from "../types/StoreData";
2
+ export declare function createStoreData(id?: string, parent?: undefined): StoreData;
3
+ export declare function createStoreData(id: string, parent: StoreData): ScopedStoreData;
@@ -0,0 +1,7 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { AtomFamily } from "../types/AtomFamily";
3
+ import type { Selector } from "../types/Selector";
4
+ import type { StoreData } from "../types/StoreData";
5
+ export declare function getState<V, K>(atom: Atom<V>, data: StoreData): V;
6
+ export declare function getState<V, K>(selector: Selector<V>, data: StoreData): V;
7
+ export declare function getState<V, K>(family: AtomFamily<V, K>, data: StoreData): K[];
@@ -0,0 +1,4 @@
1
+ import type { GlobalAtom } from "./../types/GlobalAtom";
2
+ import type { AtomOptions } from "./../types/AtomOptions";
3
+ import type { AtomDefaultValue } from "../types/AtomDefaultValue";
4
+ export declare const globalAtom: <Value = any>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value>) => GlobalAtom<Value>;
@@ -1,4 +1,5 @@
1
1
  import type { Atom } from "../types/Atom";
2
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
2
3
  import type { StoreData } from "../types/StoreData";
3
4
  export declare const getAtomInitValue: <V>(atom: Atom<V>, data: StoreData) => any;
4
- export declare const initAtom: <V>(atom: Atom<V>, data: StoreData) => any;
5
+ export declare const initAtom: <V, K>(atom: Atom<V> | AtomFamilyAtom<K, V>, data: StoreData) => any;
@@ -1,4 +1,4 @@
1
1
  import type { StoreData } from "../types/StoreData";
2
2
  import type { Selector } from "../types/Selector";
3
3
  export declare const reEvaluateSelector: <V>(selector: Selector<V>, data: StoreData) => void;
4
- export declare const initSelector: <V>(selector: Selector<V>, data: StoreData) => V;
4
+ export declare const initSelector: <V>(selector: Selector<V>, data: StoreData) => V | Promise<V>;
@@ -0,0 +1,4 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { StoreData } from "../types/StoreData";
3
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
4
+ export declare const propagateUpdatedAtoms: (atoms: (Atom<any> | AtomFamilyAtom<any, any>)[], data: StoreData) => void;
@@ -0,0 +1,3 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const setAtom: <Value = any>(atom: Atom<Value>, newValue: Value, data: StoreData, skipOnSet?: boolean) => void;
@@ -0,0 +1,4 @@
1
+ import type { ScopedStore, Store } from "../types/Store";
2
+ import type { ScopedStoreData, StoreData } from "../types/StoreData";
3
+ export declare function storeFromStoreData(data: ScopedStoreData, detach: () => void): ScopedStore;
4
+ export declare function storeFromStoreData(data: StoreData): Store;
@@ -1,8 +1,9 @@
1
1
  import type { State } from "../types/State";
2
2
  import type { StoreData } from "../types/StoreData";
3
+ import type { Atom } from "../types/Atom";
3
4
  type GetValdresValue = <V>(state: State<V>) => V;
4
5
  type SetValdresValue = <V>(state: State<V>, value: V) => void;
5
- type ResetValdresValue = <V>(state: State<V>) => V;
6
+ type ResetValdresValue = <V>(atom: Atom<V>) => V;
6
7
  type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
7
8
  export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
8
9
  export {};
@@ -0,0 +1,5 @@
1
+ import type { Family } from "../types/Family";
2
+ import type { State } from "../types/State";
3
+ import type { StoreData } from "../types/StoreData";
4
+ import type { Subscription } from "../types/Subscription";
5
+ export declare const unsubscribe: <V>(state: State<V> | Family<V>, subscription: Subscription, data: StoreData, mount?: any, maxAgeCleanup?: any) => void;
@@ -1,3 +1,3 @@
1
1
  import type { State } from "../types/State";
2
2
  import type { StoreData } from "../types/StoreData";
3
- export declare const updateStateSubscribers: (state: State, data: StoreData) => void;
3
+ export declare const updateStateSubscribers: <V>(state: State, data: StoreData) => void;
@@ -0,0 +1,4 @@
1
+ import type { GetValue } from "./types/GetValue";
2
+ import type { Selector } from "./types/Selector";
3
+ import type { SelectorOptions } from "./types/SelectorOptions";
4
+ export declare const selector: <Value, FamilyKey = undefined>(get: (get: GetValue, storeId: string) => Value, options?: SelectorOptions) => Selector<Value, FamilyKey>;
@@ -0,0 +1,3 @@
1
+ import type { SelectorFamily } from "./types/SelectorFamily";
2
+ import type { SelectorOptions } from "./types/SelectorOptions";
3
+ export declare const selectorFamily: <Value, Key>(get: any, options?: SelectorOptions) => SelectorFamily<Value, Key>;
@@ -0,0 +1 @@
1
+ export declare const store: (id?: string) => import("..").Store;
@@ -0,0 +1,12 @@
1
+ import type { AtomDefaultValue } from "./AtomDefaultValue";
2
+ import type { AtomOnInit } from "./AtomOnInit";
3
+ import type { AtomOnSet } from "./AtomOnSet";
4
+ export type Atom<Value = unknown> = {
5
+ defaultValue?: AtomDefaultValue<Value>;
6
+ label?: string;
7
+ onInit?: AtomOnInit<Value>;
8
+ onSet?: AtomOnSet<Value>;
9
+ onMount?: () => void | (() => void);
10
+ maxAge?: number;
11
+ staleWhileRevalidate?: number;
12
+ };
@@ -0,0 +1,2 @@
1
+ import type { Selector } from "./Selector";
2
+ export type AtomDefaultValue<Value = any> = Value | (() => Value | Promise<Value>) | Selector<Value> | undefined;
@@ -0,0 +1,12 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { AtomFamilyAtom } from "./AtomFamilyAtom";
3
+ import type { FamilyKey } from "./FamilyKey";
4
+ import type { Selector } from "./Selector";
5
+ export type AtomFamily<Key = FamilyKey, Value = unknown> = {
6
+ (key: Key): AtomFamilyAtom<Key, Value>;
7
+ release: (key: Key) => void;
8
+ label?: string;
9
+ __valdresAtomFamilyMap: Map<Key, AtomFamilyAtom<Key, Value>>;
10
+ __keysAtom: Atom<Set<Key>>;
11
+ __keysSelector: Selector<Key[]>;
12
+ };
@@ -0,0 +1,6 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { AtomFamily } from "./AtomFamily";
3
+ export type AtomFamilyAtom<Key = unknown, Value = unknown> = Atom<Value> & {
4
+ family: AtomFamily<Key, Value>;
5
+ familyKey: Key;
6
+ };
@@ -0,0 +1,5 @@
1
+ import type { AtomFamilyAtom } from "./AtomFamilyAtom";
2
+ import type { GlobalAtomSetSelfFunc } from "./GlobalAtomSetSelfFunc";
3
+ export type AtomFamilyGlobalAtom<Key = unknown, Value = unknown> = AtomFamilyAtom<Key, Value> & {
4
+ setSelf: GlobalAtomSetSelfFunc<Value>;
5
+ };
@@ -0,0 +1,6 @@
1
+ import type { Selector } from "./Selector";
2
+ import type { SelectorFamily } from "./SelectorFamily";
3
+ export type AtomFamilySelector<Value = unknown, Key = unknown> = Selector<Value> & {
4
+ family: SelectorFamily<Value, Key>;
5
+ familyKey: Key;
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { StoreData } from "./StoreData";
2
+ export type AtomOnInit<Value = unknown> = (setSelf: (value: Value) => void, store: StoreData) => void;
@@ -0,0 +1,2 @@
1
+ import type { StoreData } from "./StoreData";
2
+ export type AtomOnSet<Value = any> = (value: Value, store: StoreData) => void;
@@ -0,0 +1,11 @@
1
+ import type { AtomOnSet } from "./AtomOnSet";
2
+ import type { StoreData } from "./StoreData";
3
+ export type AtomOptions<Value = unknown> = {
4
+ global?: boolean;
5
+ label?: string;
6
+ onInit?: (setSelf: (value: Value) => void, store: StoreData) => void;
7
+ onSet?: AtomOnSet<Value>;
8
+ onMount?: () => () => void;
9
+ maxAge?: number;
10
+ staleWhileRevalidate?: number;
11
+ };
@@ -1,3 +1,3 @@
1
1
  import type { SelectorFamily } from "./SelectorFamily";
2
2
  import type { AtomFamily } from "./AtomFamily";
3
- export type Family<V, K = any> = AtomFamily<V, K> | SelectorFamily<V, K>;
3
+ export type Family<Key, Value = any> = AtomFamily<Key, Value> | SelectorFamily<Key, Value>;
@@ -0,0 +1,3 @@
1
+ export type FamilyKey = PropertyKey | PropertyKey[] | {
2
+ [key: PropertyKey]: FamilyKey;
3
+ };
@@ -0,0 +1,8 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { AtomFamily } from "./AtomFamily";
3
+ import type { Selector } from "./Selector";
4
+ export type GetValue = {
5
+ <V>(atom: Atom<V>, scopeId?: string): V;
6
+ <V>(selector: Selector<V>, scopeId?: string): V;
7
+ <V, K>(family: AtomFamily<K, V>, scopeId?: string): K[];
8
+ };
@@ -0,0 +1,5 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { GlobalAtomSetSelfFunc } from "./GlobalAtomSetSelfFunc";
3
+ export type GlobalAtom<Value = unknown> = Atom<Value> & {
4
+ setSelf: GlobalAtomSetSelfFunc<Value>;
5
+ };
@@ -0,0 +1 @@
1
+ export type GlobalAtomSetSelfFunc<Value = unknown> = (value: Value) => void;
@@ -0,0 +1,2 @@
1
+ import type { Atom } from "./Atom";
2
+ export type ResetAtom = <V>(state: Atom<V>) => V | Promise<V>;
@@ -0,0 +1,9 @@
1
+ import type { GetValue } from "./GetValue";
2
+ import type { SelectorFamily } from "./SelectorFamily";
3
+ export type Selector<Value = unknown, FamilyKey = undefined> = {
4
+ get: (get: GetValue, storeId: string) => Value;
5
+ label?: string;
6
+ family?: SelectorFamily<Value, FamilyKey>;
7
+ familyKey?: FamilyKey;
8
+ onMount?: () => void | (() => void);
9
+ };
@@ -0,0 +1,5 @@
1
+ import type { Selector } from "./Selector";
2
+ export type SelectorFamily<Value = any, Key = any> = {
3
+ (key: Key, defaultOverride?: any): Selector<Value>;
4
+ __valdresSelectorFamilyMap: Map<Key, Selector<Value, Key>>;
5
+ };
@@ -0,0 +1,3 @@
1
+ export type SelectorOptions = {
2
+ label?: string;
3
+ };
@@ -0,0 +1,3 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { SetAtomValue } from "./SetAtomValue";
3
+ export type SetAtom<Value = any> = (atom: Atom<Value>, value: SetAtomValue<Value>, scopeId?: string) => void;
@@ -0,0 +1 @@
1
+ export type SetAtomValue<Value> = Value | ((current: Value) => Value);
@@ -0,0 +1,24 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { AtomFamilyAtom } from "./AtomFamilyAtom";
3
+ import type { GetValue } from "./GetValue";
4
+ import type { ResetAtom } from "./ResetAtom";
5
+ import type { ScopedStoreData, StoreData } from "./StoreData";
6
+ import type { SubscribeFn } from "./SubscribeFn";
7
+ import type { TransactionFn } from "./TransactionFn";
8
+ type SetAtom = {
9
+ <V, K>(atom: AtomFamilyAtom<K, V>, value: V): void;
10
+ <V>(atom: Atom<V>, value: V): void;
11
+ };
12
+ export type Store<T = StoreData> = {
13
+ data: T;
14
+ get: GetValue;
15
+ set: SetAtom;
16
+ sub: SubscribeFn;
17
+ reset: ResetAtom;
18
+ txn: (callback: TransactionFn) => void;
19
+ scope: (scopeId: string) => ScopedStore;
20
+ };
21
+ export type ScopedStore = Store<ScopedStoreData> & {
22
+ detach: () => void;
23
+ };
24
+ export {};
@@ -1,4 +1,4 @@
1
- export type StoreData = {
1
+ export type RootStoreData = {
2
2
  id: string;
3
3
  values: WeakMap<WeakKey, any>;
4
4
  expiredValues: WeakMap<WeakKey, any>;
@@ -6,4 +6,12 @@ export type StoreData = {
6
6
  subscriptionsRequireEqualCheck: WeakMap<WeakKey, boolean>;
7
7
  stateConsumers: WeakMap<WeakKey, any>;
8
8
  stateDependencies: WeakMap<WeakKey, any>;
9
+ scopes: {
10
+ [scopeId: string]: ScopedStoreData;
11
+ };
9
12
  };
13
+ export type ScopedStoreData = RootStoreData & {
14
+ parent: StoreData;
15
+ scopeConsumers: Set<() => void>;
16
+ };
17
+ export type StoreData = RootStoreData | ScopedStoreData;
@@ -0,0 +1 @@
1
+ export type Subscription = {};
@@ -0,0 +1,2 @@
1
+ import type { Atom } from "../types/Atom";
2
+ export declare const isAtom: <V>(state: any) => state is Atom<V>;
@@ -0,0 +1,2 @@
1
+ import type { AtomFamily } from "../types/AtomFamily";
2
+ export declare const isAtomFamily: <K, V>(state: any) => state is AtomFamily<K, V>;
@@ -0,0 +1 @@
1
+ export declare const isFamily: (state: any) => state is import("../..").SelectorFamily<unknown, unknown> | import("../..").AtomFamily<unknown, unknown>;
@@ -0,0 +1,2 @@
1
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
2
+ export declare const isFamilyAtom: <K, V>(state: any) => state is AtomFamilyAtom<K, V>;
@@ -0,0 +1,2 @@
1
+ import type { AtomFamilySelector } from "../types/AtomFamilySelector";
2
+ export declare const isFamilySelector: <K, V>(state: any) => state is AtomFamilySelector<K, V>;
@@ -0,0 +1,3 @@
1
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
2
+ import type { AtomFamilySelector } from "../types/AtomFamilySelector";
3
+ export declare const isFamilyState: <K, V>(state: any) => state is AtomFamilyAtom<K, V> | AtomFamilySelector<K, V>;
@@ -0,0 +1,2 @@
1
+ import type { Selector } from "../types/Selector";
2
+ export declare const isSelector: <V>(state: any) => state is Selector<V>;
@@ -0,0 +1,2 @@
1
+ import type { SelectorFamily } from "../types/SelectorFamily";
2
+ export declare const isSelectorFamily: <K, V>(state: any) => state is SelectorFamily<K, V>;
package/package.json CHANGED
@@ -1,21 +1,26 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.2",
3
+ "version": "0.2.0-alpha.21",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Eigil Sagafos"
7
7
  },
8
+ "homepage": "https://valdres.dev",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/eigilsagafos/valdres.git"
12
+ },
8
13
  "type": "module",
9
14
  "exports": {
10
- "types": "./dist/index.d.ts",
11
- "default": "./dist/index.js"
15
+ "default": "./dist/index.js",
16
+ "types": "./dist/types/index.d.ts"
12
17
  },
13
18
  "files": [
14
19
  "dist"
15
20
  ],
16
21
  "scripts": {
17
- "build": "NODE_ENV=production bun scripts/build.ts",
18
- "build:types": "tsc",
22
+ "build": "NODE_ENV=production bun build index.ts --outdir ./dist --packages external",
23
+ "build:types": "rm -rf dist/types && tsc",
19
24
  "test": "bun test"
20
25
  },
21
26
  "dependencies": {
@@ -28,11 +33,11 @@
28
33
  "react": ">=18",
29
34
  "react-dom": ">=18",
30
35
  "recoil": "0.7.7",
31
- "typescript": "5.5.4"
36
+ "typescript": "5.6.2"
32
37
  },
33
38
  "publishConfig": {
34
39
  "access": "public",
35
40
  "registry": "https://registry.npmjs.org/"
36
41
  },
37
- "gitHead": "4f2355214e1e4d2cf9011705733b18ab425f8d20"
42
+ "gitHead": "6d564893ff8e43a913e9d7afa531e83d3d4e69b1"
38
43
  }
@@ -1,9 +0,0 @@
1
- import type { Atom } from "./types/Atom";
2
- type AtomOptions<M = any> = {
3
- label?: string;
4
- onInit?: () => void;
5
- onMount?: () => M;
6
- onUnmount?: (mountRes?: M) => void;
7
- };
8
- export declare const atom: <Value, FamilyKey = undefined, MountReturnValue = undefined>(defaultValue?: Value | (() => Value | Promise<Value>), options?: AtomOptions<MountReturnValue>) => Atom<Value, FamilyKey>;
9
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import type { AtomFamily } from "./types/AtomFamily";
2
- export declare const atomFamily: <Value, Key>(defaultValue?: Value | ((arg: Key) => Value | Promise<Value>), debugLabel?: string) => AtomFamily<Value, Key>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import type { Store } from "./types/Store";
2
- export declare const createStore: (id?: string) => Store;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- export declare const getDefaultStore: () => any;
2
- export declare const resetDefaultStore: () => import("./types/Store").Store;
@@ -1,3 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const getState: <V>(state: State<V>, data: StoreData) => V | Promise<V>;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const propagateUpdatedAtoms: (atoms: Atom[], data: StoreData) => void;
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const setAtom: <V>(atom: Atom<V>, newValue: V, data: StoreData) => void;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,3 +0,0 @@
1
- import type { State } from "../types/State";
2
- import type { StoreData } from "../types/StoreData";
3
- export declare const unsubscribe: <V>(state: State<V>, subscription: any, data: StoreData, mountRes?: any) => void;
@@ -1,3 +0,0 @@
1
- import type { GetValue } from "./types/GetValue";
2
- import type { Selector } from "./types/Selector";
3
- export declare const selector: <Value, FamilyKey = undefined>(get: (get: GetValue) => Value, debugLabel?: string) => Selector<Value, FamilyKey>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,2 +0,0 @@
1
- import type { SelectorFamily } from "./types/SelectorFamily";
2
- export declare const selectorFamily: <Value, Key>(get: any, debugLabel?: string) => SelectorFamily<Value, Key>;
@@ -1 +0,0 @@
1
- export {};
@@ -1,9 +0,0 @@
1
- import type { AtomFamily } from "./AtomFamily";
2
- export type Atom<Value = unknown, FamilyKey = undefined, MountRes = undefined> = {
3
- defaultValue?: Value | (() => Value | Promise<Value>);
4
- label?: string;
5
- family?: AtomFamily<Value, FamilyKey>;
6
- familyKey?: FamilyKey;
7
- onMount?: () => MountRes;
8
- onUnmount?: (mountRes?: MountRes) => void;
9
- };
@@ -1,5 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type AtomFamily<Value, Key> = {
3
- (key: Key, defaultOverride?: any): Atom<Value>;
4
- _map: Map<Key, Atom<Value, Key>>;
5
- };
@@ -1,2 +0,0 @@
1
- import type { State } from "./State";
2
- export type GetValue = <V>(state: State<V>) => V | Promise<V>;
@@ -1,2 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type ResetAtom = <V>(state: Atom<V>) => V;
@@ -1,8 +0,0 @@
1
- import type { GetValue } from "./GetValue";
2
- import type { SelectorFamily } from "./SelectorFamily";
3
- export type Selector<Value = any, FamilyKey = undefined> = {
4
- get: (get: GetValue) => Value;
5
- debugLabel?: string;
6
- family?: SelectorFamily<Value, FamilyKey>;
7
- familyKey?: FamilyKey;
8
- };
@@ -1,5 +0,0 @@
1
- import type { Selector } from "./Selector";
2
- export type SelectorFamily<Value, Key> = {
3
- (key: Key, defaultOverride?: any): Selector<Value>;
4
- _map: Map<Key, Selector<Value, Key>>;
5
- };
@@ -1,2 +0,0 @@
1
- import type { Atom } from "./Atom";
2
- export type SetAtom = <V>(atom: Atom<V>, value: V | ((current: V) => V)) => void;
@@ -1,14 +0,0 @@
1
- import type { GetValue } from "./GetValue";
2
- import type { ResetAtom } from "./ResetAtom";
3
- import type { SetAtom } from "./SetAtom";
4
- import type { StoreData } from "./StoreData";
5
- import type { SubscribeFn } from "./SubscribeFn";
6
- import type { TransactionFn } from "./TransactionFn";
7
- export type Store = {
8
- data: StoreData;
9
- get: GetValue;
10
- set: SetAtom;
11
- sub: SubscribeFn;
12
- reset: ResetAtom;
13
- txn: (callback: TransactionFn) => void;
14
- };
@@ -1,3 +0,0 @@
1
- import type { Atom } from "../types/Atom";
2
- import type { State } from "../types/State";
3
- export declare const isAtom: (state: State) => state is Atom;
@@ -1 +0,0 @@
1
- export declare const isFamily: (state: any) => boolean;
@@ -1,2 +0,0 @@
1
- import type { Selector } from "../types/Selector";
2
- export declare const isSelector: (state: any) => state is Selector;