valdres 0.2.0-alpha.41 → 0.2.0-alpha.44

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 (69) hide show
  1. package/dist/index.js +3 -1
  2. package/dist/types/index.d.ts +29 -0
  3. package/dist/types/src/atom.d.ts +16 -0
  4. package/dist/types/src/atomFamily.d.ts +4 -0
  5. package/dist/types/src/createStoreWithSelectorSet.d.ts +2 -0
  6. package/dist/types/src/globalStore.d.ts +4 -0
  7. package/dist/types/src/lib/atomFamilyAtom.d.ts +8 -0
  8. package/dist/types/src/lib/createAtomFamily.d.ts +4 -0
  9. package/dist/types/src/lib/createGlobalAtomFamily.d.ts +5 -0
  10. package/dist/types/src/lib/createStoreData.d.ts +3 -0
  11. package/dist/types/src/lib/equal.d.ts +1 -0
  12. package/dist/types/src/lib/getState.d.ts +7 -0
  13. package/dist/types/src/lib/globalAtom.d.ts +4 -0
  14. package/dist/types/src/lib/initAtom.d.ts +5 -0
  15. package/dist/types/src/lib/initSelector.d.ts +4 -0
  16. package/dist/types/src/lib/propagateUpdatedAtoms.d.ts +4 -0
  17. package/dist/types/src/lib/resetAtom.d.ts +3 -0
  18. package/dist/types/src/lib/setAtom.d.ts +3 -0
  19. package/dist/types/src/lib/setAtoms.d.ts +3 -0
  20. package/dist/types/src/lib/stableStringify.d.ts +1 -0
  21. package/dist/types/src/lib/storeFromStoreData.d.ts +4 -0
  22. package/dist/types/src/lib/subscribe.d.ts +4 -0
  23. package/dist/types/src/lib/transaction.d.ts +9 -0
  24. package/dist/types/src/lib/unsubscribe.d.ts +5 -0
  25. package/dist/types/src/lib/updateSelectorSubscribers.d.ts +3 -0
  26. package/dist/types/src/lib/updateStateSubscribers.d.ts +3 -0
  27. package/dist/types/src/selector.d.ts +4 -0
  28. package/dist/types/src/selectorFamily.d.ts +4 -0
  29. package/dist/types/src/store.d.ts +1 -0
  30. package/dist/types/src/types/Atom.d.ts +14 -0
  31. package/dist/types/src/types/AtomDefaultValue.d.ts +2 -0
  32. package/dist/types/src/types/AtomFamily.d.ts +12 -0
  33. package/dist/types/src/types/AtomFamilyAtom.d.ts +6 -0
  34. package/dist/types/src/types/AtomFamilyDefaultValue.d.ts +5 -0
  35. package/dist/types/src/types/AtomFamilyGlobalAtom.d.ts +3 -0
  36. package/dist/types/src/types/AtomFamilySelector.d.ts +6 -0
  37. package/dist/types/src/types/AtomOnInit.d.ts +2 -0
  38. package/dist/types/src/types/AtomOnSet.d.ts +2 -0
  39. package/dist/types/src/types/AtomOptions.d.ts +13 -0
  40. package/dist/types/src/types/EqualFunc.d.ts +1 -0
  41. package/dist/types/src/types/Family.d.ts +3 -0
  42. package/dist/types/src/types/FamilyKey.d.ts +3 -0
  43. package/dist/types/src/types/GetValue.d.ts +8 -0
  44. package/dist/types/src/types/GlobalAtom.d.ts +11 -0
  45. package/dist/types/src/types/GlobalAtomGetSelfFunc.d.ts +1 -0
  46. package/dist/types/src/types/GlobalAtomResetSelfFunc.d.ts +1 -0
  47. package/dist/types/src/types/GlobalAtomSetSelfFunc.d.ts +1 -0
  48. package/dist/types/src/types/ResetAtom.d.ts +2 -0
  49. package/dist/types/src/types/Selector.d.ts +11 -0
  50. package/dist/types/src/types/SelectorFamily.d.ts +6 -0
  51. package/dist/types/src/types/SelectorOptions.d.ts +5 -0
  52. package/dist/types/src/types/SetAtom.d.ts +3 -0
  53. package/dist/types/src/types/SetAtomValue.d.ts +1 -0
  54. package/dist/types/src/types/State.d.ts +4 -0
  55. package/dist/types/src/types/Store.d.ts +24 -0
  56. package/dist/types/src/types/StoreData.d.ts +17 -0
  57. package/dist/types/src/types/SubscribeFn.d.ts +2 -0
  58. package/dist/types/src/types/Subscription.d.ts +1 -0
  59. package/dist/types/src/types/TransactionFn.d.ts +4 -0
  60. package/dist/types/src/utils/isAtom.d.ts +2 -0
  61. package/dist/types/src/utils/isAtomFamily.d.ts +2 -0
  62. package/dist/types/src/utils/isFamily.d.ts +1 -0
  63. package/dist/types/src/utils/isFamilyAtom.d.ts +2 -0
  64. package/dist/types/src/utils/isFamilySelector.d.ts +2 -0
  65. package/dist/types/src/utils/isFamilyState.d.ts +3 -0
  66. package/dist/types/src/utils/isPromiseLike.d.ts +1 -0
  67. package/dist/types/src/utils/isSelector.d.ts +2 -0
  68. package/dist/types/src/utils/isSelectorFamily.d.ts +2 -0
  69. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -591,6 +591,8 @@ var transaction = (callback, data) => {
591
591
  }
592
592
  txnSelectorCache.set(state, res);
593
593
  return res;
594
+ } else if (isFamily(state)) {
595
+ return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state.__keysSelector, data);
594
596
  } else {
595
597
  throw new Error("Unsupported state");
596
598
  }
@@ -693,7 +695,7 @@ var store = (id) => {
693
695
  return storeFromStoreData(data);
694
696
  };
695
697
  // package.json
696
- var version = "0.2.0-alpha.40";
698
+ var version = "0.2.0-alpha.43";
697
699
 
698
700
  // src/globalStore.ts
699
701
  if (globalThis.__valdres__) {
@@ -0,0 +1,29 @@
1
+ export { atom } from "./src/atom";
2
+ export { atomFamily } from "./src/atomFamily";
3
+ export { createStoreWithSelectorSet } from "./src/createStoreWithSelectorSet";
4
+ export { globalStore } from "./src/globalStore";
5
+ export { selector } from "./src/selector";
6
+ export { selectorFamily } from "./src/selectorFamily";
7
+ export { store } from "./src/store";
8
+ export { isAtom } from "./src/utils/isAtom";
9
+ export { isAtomFamily } from "./src/utils/isAtomFamily";
10
+ export { isFamily } from "./src/utils/isFamily";
11
+ export { isFamilyAtom } from "./src/utils/isFamilyAtom";
12
+ export { isFamilySelector } from "./src/utils/isFamilySelector";
13
+ export { isFamilyState } from "./src/utils/isFamilyState";
14
+ export { isPromiseLike } from "./src/utils/isPromiseLike";
15
+ export { isSelector } from "./src/utils/isSelector";
16
+ export { isSelectorFamily } from "./src/utils/isSelectorFamily";
17
+ export type { Atom } from "./src/types/Atom";
18
+ export type { AtomFamily } from "./src/types/AtomFamily";
19
+ export type { FamilyKey } from "./src/types/FamilyKey";
20
+ export type { GetValue } from "./src/types/GetValue";
21
+ export type { GlobalAtom } from "./src/types/GlobalAtom";
22
+ export type { ResetAtom } from "./src/types/ResetAtom";
23
+ export type { Selector } from "./src/types/Selector";
24
+ export type { SelectorFamily } from "./src/types/SelectorFamily";
25
+ export type { SetAtom } from "./src/types/SetAtom";
26
+ export type { SetAtomValue } from "./src/types/SetAtomValue";
27
+ export type { State } from "./src/types/State";
28
+ export type { Store } from "./src/types/Store";
29
+ 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", { name: "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,4 @@
1
+ import type { AtomOptions } from "./types/AtomOptions";
2
+ import type { FamilyKey } from "./types/FamilyKey";
3
+ import type { AtomFamilyDefaultValue } from "./types/AtomFamilyDefaultValue";
4
+ export declare function atomFamily<Key = FamilyKey, Value = unknown>(defaultValue?: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>): import("..").AtomFamily<Key, Value>;
@@ -0,0 +1,2 @@
1
+ import type { Store } from "./types/Store";
2
+ export declare const createStoreWithSelectorSet: (id?: string) => Store;
@@ -0,0 +1,4 @@
1
+ export declare const globalStore: import("..").Store & {
2
+ atoms: Map<any, any>;
3
+ atomFamilies: Map<any, any>;
4
+ };
@@ -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,4 @@
1
+ import type { AtomFamily } from "../types/AtomFamily";
2
+ import type { AtomOptions } from "../types/AtomOptions";
3
+ import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
4
+ export declare const createAtomFamily: <Key, Value>(defaultValue: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>) => AtomFamily<Key, Value>;
@@ -0,0 +1,5 @@
1
+ import type { AtomOptions } from "../types/AtomOptions";
2
+ import type { FamilyKey } from "../types/FamilyKey";
3
+ import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
4
+ import type { AtomFamily } from "../types/AtomFamily";
5
+ export declare const createGlobalAtomFamily: <Key = FamilyKey, Value = unknown>(defaultValue: AtomFamilyDefaultValue<Key, Value>, options: AtomOptions<Value>) => AtomFamily<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 @@
1
+ export declare const equal: (a: any, b: any) => boolean;
@@ -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 { AtomDefaultValue } from "../types/AtomDefaultValue";
2
+ import type { AtomOptions } from "./../types/AtomOptions";
3
+ import type { GlobalAtom } from "./../types/GlobalAtom";
4
+ export declare const globalAtom: <Value = unknown>(defaultValue: AtomDefaultValue<Value>, options: AtomOptions<Value>) => GlobalAtom<Value>;
@@ -0,0 +1,5 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
3
+ import type { StoreData } from "../types/StoreData";
4
+ export declare const getAtomInitValue: <V>(atom: Atom<V>, data: StoreData) => any;
5
+ export declare const initAtom: <V, K>(atom: Atom<V> | AtomFamilyAtom<K, V>, data: StoreData) => any;
@@ -0,0 +1,4 @@
1
+ import type { StoreData } from "../types/StoreData";
2
+ import type { Selector } from "../types/Selector";
3
+ export declare const reEvaluateSelector: <V>(selector: Selector<V>, data: StoreData) => void;
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 resetAtom: <V>(atom: Atom<V>, data: StoreData) => V | Promise<V>;
@@ -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,3 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const setAtoms: (pairs: Map<Atom<any>, any>, data: StoreData) => void;
@@ -0,0 +1 @@
1
+ export declare const stableStringify: (x: any) => string | number | boolean;
@@ -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;
@@ -0,0 +1,4 @@
1
+ import type { Family } from "../types/Family";
2
+ import type { State } from "../types/State";
3
+ import type { StoreData } from "../types/StoreData";
4
+ export declare const subscribe: <V>(state: State<V> | Family<V>, callback: () => void, requireDeepEqualCheckBeforeCallback: boolean, data: StoreData) => () => void;
@@ -0,0 +1,9 @@
1
+ import type { State } from "../types/State";
2
+ import type { StoreData } from "../types/StoreData";
3
+ import type { Atom } from "../types/Atom";
4
+ type GetValdresValue = <V>(state: State<V>) => V;
5
+ type SetValdresValue = <V>(state: State<V>, value: V) => void;
6
+ type ResetValdresValue = <V>(atom: Atom<V>) => V;
7
+ type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
8
+ export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
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;
@@ -0,0 +1,3 @@
1
+ import type { Selector } from "../types/Selector";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const updateSelectorSubscribers: (selector: Selector, data: StoreData) => void;
@@ -0,0 +1,3 @@
1
+ import type { State } from "../types/State";
2
+ import type { StoreData } from "../types/StoreData";
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<Value>) => Selector<Value, FamilyKey>;
@@ -0,0 +1,4 @@
1
+ import type { SelectorFamily } from "./types/SelectorFamily";
2
+ import type { SelectorOptions } from "./types/SelectorOptions";
3
+ import type { GetValue } from "./types/GetValue";
4
+ export declare const selectorFamily: <Key, Value>(get: (key: Key) => (get: GetValue) => Value, options?: SelectorOptions<Value>) => SelectorFamily<Key, Value>;
@@ -0,0 +1 @@
1
+ export declare const store: (id?: string) => import("..").Store;
@@ -0,0 +1,14 @@
1
+ import type { AtomDefaultValue } from "./AtomDefaultValue";
2
+ import type { AtomOnInit } from "./AtomOnInit";
3
+ import type { AtomOnSet } from "./AtomOnSet";
4
+ import type { EqualFunc } from "./EqualFunc";
5
+ export type Atom<Value = unknown> = {
6
+ equal: EqualFunc<Value>;
7
+ defaultValue?: AtomDefaultValue<Value>;
8
+ name?: string;
9
+ onInit?: AtomOnInit<Value>;
10
+ onSet?: AtomOnSet<Value>;
11
+ onMount?: () => void | (() => void);
12
+ maxAge?: number;
13
+ staleWhileRevalidate?: number;
14
+ };
@@ -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
+ name?: 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 { Selector } from "./Selector";
2
+ import type { SelectorFamily } from "./SelectorFamily";
3
+ type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
4
+ export type AtomFamilyDefaultValue<Key, Value> = undefined | Value | DefaultValueCallback<Key, Value> | Selector<Value> | SelectorFamily<Key, Value>;
5
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { AtomFamilyAtom } from "./AtomFamilyAtom";
2
+ import type { GlobalAtom } from "./GlobalAtom";
3
+ export type AtomFamilyGlobalAtom<Key = unknown, Value = unknown> = AtomFamilyAtom<Key, Value> & GlobalAtom<Value>;
@@ -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<Key, Value>;
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,13 @@
1
+ import type { AtomOnSet } from "./AtomOnSet";
2
+ import type { EqualFunc } from "./EqualFunc";
3
+ import type { StoreData } from "./StoreData";
4
+ export type AtomOptions<Value = unknown> = {
5
+ global?: boolean;
6
+ name?: string;
7
+ onInit?: (setSelf: (value: Value) => void, store: StoreData) => (() => void) | void;
8
+ onSet?: AtomOnSet<Value>;
9
+ onMount?: () => () => void;
10
+ maxAge?: number;
11
+ staleWhileRevalidate?: number;
12
+ equal?: EqualFunc<Value>;
13
+ };
@@ -0,0 +1 @@
1
+ export type EqualFunc<Value> = (a: Value, b: Value) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { SelectorFamily } from "./SelectorFamily";
2
+ import type { AtomFamily } from "./AtomFamily";
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>): V;
6
+ <V>(selector: Selector<V>): V;
7
+ <V, K>(family: AtomFamily<K, V>): K[];
8
+ };
@@ -0,0 +1,11 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { GlobalAtomGetSelfFunc } from "./GlobalAtomGetSelfFunc";
3
+ import type { GlobalAtomResetSelfFunc } from "./GlobalAtomResetSelfFunc";
4
+ import type { GlobalAtomSetSelfFunc } from "./GlobalAtomSetSelfFunc";
5
+ import type { StoreData } from "./StoreData";
6
+ export type GlobalAtom<Value = unknown> = Atom<Value> & {
7
+ setSelf: GlobalAtomSetSelfFunc<Value>;
8
+ resetSelf: GlobalAtomResetSelfFunc;
9
+ getSelf: GlobalAtomGetSelfFunc<Value>;
10
+ stores: Set<StoreData>;
11
+ };
@@ -0,0 +1 @@
1
+ export type GlobalAtomGetSelfFunc<Value = unknown> = () => Value;
@@ -0,0 +1 @@
1
+ export type GlobalAtomResetSelfFunc = () => void;
@@ -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,11 @@
1
+ import type { EqualFunc } from "./EqualFunc";
2
+ import type { GetValue } from "./GetValue";
3
+ import type { SelectorFamily } from "./SelectorFamily";
4
+ export type Selector<Value = unknown, FamilyKey = undefined> = {
5
+ get: (get: GetValue, storeId: string) => Value;
6
+ equal: EqualFunc<Value>;
7
+ name?: string;
8
+ family?: SelectorFamily<FamilyKey, Value>;
9
+ familyKey?: FamilyKey;
10
+ onMount?: () => void | (() => void);
11
+ };
@@ -0,0 +1,6 @@
1
+ import type { FamilyKey } from "./FamilyKey";
2
+ import type { Selector } from "./Selector";
3
+ export type SelectorFamily<Key = FamilyKey, Value = unknown> = {
4
+ (key: Key, defaultOverride?: any): Selector<Value>;
5
+ __valdresSelectorFamilyMap: Map<Key, Selector<Value, Key>>;
6
+ };
@@ -0,0 +1,5 @@
1
+ import type { EqualFunc } from "./EqualFunc";
2
+ export type SelectorOptions<Value> = {
3
+ name?: string;
4
+ equal?: EqualFunc<Value>;
5
+ };
@@ -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>) => void;
@@ -0,0 +1 @@
1
+ export type SetAtomValue<Value> = Value | ((current: Value) => Value);
@@ -0,0 +1,4 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { AtomFamily } from "./AtomFamily";
3
+ import type { Selector } from "./Selector";
4
+ export type State<K = any, V = any> = Atom<V> | Selector<V> | AtomFamily<K, V>;
@@ -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 {};
@@ -0,0 +1,17 @@
1
+ export type RootStoreData = {
2
+ id: string;
3
+ values: WeakMap<WeakKey, any>;
4
+ expiredValues: WeakMap<WeakKey, any>;
5
+ subscriptions: WeakMap<WeakKey, Set<any>>;
6
+ subscriptionsRequireEqualCheck: WeakMap<WeakKey, boolean>;
7
+ stateConsumers: WeakMap<WeakKey, any>;
8
+ stateDependencies: WeakMap<WeakKey, any>;
9
+ scopes: {
10
+ [scopeId: string]: ScopedStoreData;
11
+ };
12
+ };
13
+ export type ScopedStoreData = RootStoreData & {
14
+ parent: StoreData;
15
+ scopeConsumers: Set<() => void>;
16
+ };
17
+ export type StoreData = RootStoreData | ScopedStoreData;
@@ -0,0 +1,2 @@
1
+ import type { State } from "./State";
2
+ export type SubscribeFn = <V>(state: State<V>, callback: () => void, requireDeepEqualCheckBeforeCallback?: boolean) => () => void;
@@ -0,0 +1 @@
1
+ export type Subscription = {};
@@ -0,0 +1,4 @@
1
+ import type { GetValue } from "./GetValue";
2
+ import type { ResetAtom } from "./ResetAtom";
3
+ import type { SetAtom } from "./SetAtom";
4
+ export type TransactionFn = (set: SetAtom, get: GetValue, reset: ResetAtom, commit: () => void) => void;
@@ -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 @@
1
+ export declare const isPromiseLike: <T>(object: any) => object is Promise<T>;
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.41",
3
+ "version": "0.2.0-alpha.44",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Eigil Sagafos"
@@ -36,5 +36,5 @@
36
36
  "access": "public",
37
37
  "registry": "https://registry.npmjs.org/"
38
38
  },
39
- "gitHead": "052775e54393429f2109353e91504214377b30f0"
39
+ "gitHead": "1b5b205b6b1d2783a2e8b41932199a71da540901"
40
40
  }