valdres 0.2.0-alpha.7 → 0.2.0-alpha.8

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 (43) hide show
  1. package/dist/index.d.ts +21 -0
  2. package/dist/src/atom.d.ts +8 -0
  3. package/dist/src/atomFamily.d.ts +4 -0
  4. package/dist/src/createStore.d.ts +2 -0
  5. package/dist/src/createStoreWithSelectorSet.d.ts +2 -0
  6. package/dist/src/getDefaultStore.d.ts +2 -0
  7. package/dist/src/lib/createStoreData.d.ts +2 -0
  8. package/dist/src/lib/getState.d.ts +7 -0
  9. package/dist/src/lib/initAtom.d.ts +4 -0
  10. package/dist/src/lib/initSelector.d.ts +4 -0
  11. package/dist/src/lib/propagateUpdatedAtoms.d.ts +3 -0
  12. package/dist/src/lib/resetAtom.d.ts +3 -0
  13. package/dist/src/lib/setAtom.d.ts +3 -0
  14. package/dist/src/lib/setAtoms.d.ts +3 -0
  15. package/dist/src/lib/stableStringify.d.ts +1 -0
  16. package/dist/src/lib/storeFromStoreData.d.ts +3 -0
  17. package/dist/src/lib/subscribe.d.ts +4 -0
  18. package/dist/src/lib/transaction.d.ts +9 -0
  19. package/dist/src/lib/unsubscribe.d.ts +5 -0
  20. package/dist/src/lib/updateSelectorSubscribers.d.ts +3 -0
  21. package/dist/src/lib/updateStateSubscribers.d.ts +3 -0
  22. package/dist/src/selector.d.ts +3 -0
  23. package/dist/src/selectorFamily.d.ts +2 -0
  24. package/dist/src/types/Atom.d.ts +9 -0
  25. package/dist/src/types/AtomFamily.d.ts +5 -0
  26. package/dist/src/types/Family.d.ts +3 -0
  27. package/dist/src/types/GetValue.d.ts +8 -0
  28. package/dist/src/types/ResetAtom.d.ts +2 -0
  29. package/dist/src/types/Selector.d.ts +9 -0
  30. package/dist/src/types/SelectorFamily.d.ts +5 -0
  31. package/dist/src/types/SetAtom.d.ts +3 -0
  32. package/dist/src/types/SetAtomValue.d.ts +1 -0
  33. package/dist/src/types/State.d.ts +3 -0
  34. package/dist/src/types/Store.d.ts +14 -0
  35. package/dist/src/types/StoreData.d.ts +9 -0
  36. package/dist/src/types/SubscribeFn.d.ts +2 -0
  37. package/dist/src/types/Subscription.d.ts +1 -0
  38. package/dist/src/types/TransactionFn.d.ts +4 -0
  39. package/dist/src/utils/isAtom.d.ts +2 -0
  40. package/dist/src/utils/isFamily.d.ts +1 -0
  41. package/dist/src/utils/isPromiseLike.d.ts +1 -0
  42. package/dist/src/utils/isSelector.d.ts +2 -0
  43. package/package.json +2 -2
@@ -0,0 +1,21 @@
1
+ export { atom } from "./src/atom";
2
+ export { atomFamily } from "./src/atomFamily";
3
+ export { createStore } from "./src/createStore";
4
+ export { createStoreWithSelectorSet } from "./src/createStoreWithSelectorSet";
5
+ export { getDefaultStore, resetDefaultStore } from "./src/getDefaultStore";
6
+ export { selector } from "./src/selector";
7
+ export { selectorFamily } from "./src/selectorFamily";
8
+ export { isAtom } from "./src/utils/isAtom";
9
+ export { isSelector } from "./src/utils/isSelector";
10
+ export { isFamily } from "./src/utils/isFamily";
11
+ export { isPromiseLike } from "./src/utils/isPromiseLike";
12
+ export type { Atom } from "./src/types/Atom";
13
+ export type { AtomFamily } from "./src/types/AtomFamily";
14
+ export type { GetValue } from "./src/types/GetValue";
15
+ export type { Selector } from "./src/types/Selector";
16
+ export type { SelectorFamily } from "./src/types/SelectorFamily";
17
+ export type { SetAtom } from "./src/types/SetAtom";
18
+ export type { SetAtomValue } from "./src/types/SetAtomValue";
19
+ export type { State } from "./src/types/State";
20
+ export type { Store } from "./src/types/Store";
21
+ export type { StoreData } from "./src/types/StoreData";
@@ -0,0 +1,8 @@
1
+ import type { Atom } from "./types/Atom";
2
+ type AtomOptions<Value> = {
3
+ label?: string;
4
+ onInit?: (setSelf: (value: Value) => void) => void;
5
+ onMount?: () => () => void;
6
+ };
7
+ export declare const atom: <Value, FamilyKey = undefined>(defaultValue?: Value | (() => Value | Promise<Value>), options?: AtomOptions<Value>) => Atom<Value, FamilyKey>;
8
+ export {};
@@ -0,0 +1,4 @@
1
+ import type { AtomFamily } from "./types/AtomFamily";
2
+ type DefaultValueCallback<Key, Value> = (arg: Key) => Value | Promise<Value>;
3
+ export declare const atomFamily: <Value = unknown, Key = unknown>(defaultValue?: Value | DefaultValueCallback<Key, Value>, debugLabel?: string) => AtomFamily<Value, Key>;
4
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Store } from "./types/Store";
2
+ export declare const createStore: (id?: string) => Store;
@@ -0,0 +1,2 @@
1
+ import type { Store } from "./types/Store";
2
+ export declare const createStoreWithSelectorSet: (id?: string) => Store;
@@ -0,0 +1,2 @@
1
+ export declare const getDefaultStore: () => any;
2
+ export declare const resetDefaultStore: () => import("..").Store;
@@ -0,0 +1,2 @@
1
+ import type { StoreData } from "../types/StoreData";
2
+ export declare const createStoreData: (id?: string) => StoreData;
@@ -0,0 +1,7 @@
1
+ import type { StoreData } from "../types/StoreData";
2
+ import type { Atom } from "../types/Atom";
3
+ import type { AtomFamily } from "../types/AtomFamily";
4
+ import type { Selector } from "../types/Selector";
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 { Atom } from "../types/Atom";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const getAtomInitValue: <V>(atom: Atom<V>, data: StoreData) => any;
4
+ export declare const initAtom: <V>(atom: Atom<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,3 @@
1
+ import type { Atom } from "../types/Atom";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const propagateUpdatedAtoms: (atoms: Atom[], 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: <V>(atom: Atom<V>, newValue: V, 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 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,3 @@
1
+ import type { Store } from "../types/Store";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const 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: any, 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) => 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: (state: State, data: StoreData) => void;
@@ -0,0 +1,3 @@
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>;
@@ -0,0 +1,2 @@
1
+ import type { SelectorFamily } from "./types/SelectorFamily";
2
+ export declare const selectorFamily: <Value, Key>(get: any, debugLabel?: string) => SelectorFamily<Value, Key>;
@@ -0,0 +1,9 @@
1
+ import type { AtomFamily } from "./AtomFamily";
2
+ export type Atom<Value = unknown, FamilyKey = undefined> = {
3
+ defaultValue?: Value | (() => Value | Promise<Value>);
4
+ label?: string;
5
+ family?: AtomFamily<Value, FamilyKey>;
6
+ familyKey?: FamilyKey;
7
+ onInit?: (setSelf: (value: Value) => void) => void;
8
+ onMount?: () => void | (() => void);
9
+ };
@@ -0,0 +1,5 @@
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
+ };
@@ -0,0 +1,3 @@
1
+ import type { SelectorFamily } from "./SelectorFamily";
2
+ import type { AtomFamily } from "./AtomFamily";
3
+ export type Family<V, K = any> = AtomFamily<V, K> | SelectorFamily<V, K>;
@@ -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, K>(atom: Atom<V>): V;
6
+ <V, K>(selector: Selector<V>): V;
7
+ <V, K>(family: AtomFamily<V, K>): K[];
8
+ };
@@ -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) => Value;
5
+ debugLabel?: 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, Key> = {
3
+ (key: Key, defaultOverride?: any): Selector<Value>;
4
+ _map: Map<Key, Selector<Value, Key>>;
5
+ };
@@ -0,0 +1,3 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { SetAtomValue } from "./SetAtomValue";
3
+ export type SetAtom<V = unknown> = (atom: Atom<V>, value: SetAtomValue<V>) => void;
@@ -0,0 +1 @@
1
+ export type SetAtomValue<V> = V | ((current: V) => V);
@@ -0,0 +1,3 @@
1
+ import type { Atom } from "./Atom";
2
+ import type { Selector } from "./Selector";
3
+ export type State<V = any> = Atom<V> | Selector<V>;
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1,9 @@
1
+ export type StoreData = {
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
+ };
@@ -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: (state: any) => state is Atom;
@@ -0,0 +1 @@
1
+ export declare const isFamily: (state: any) => boolean;
@@ -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: (state: any) => state is Selector;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.7",
3
+ "version": "0.2.0-alpha.8",
4
4
  "license": "MIT",
5
5
  "author": {
6
6
  "name": "Eigil Sagafos"
@@ -39,5 +39,5 @@
39
39
  "access": "public",
40
40
  "registry": "https://registry.npmjs.org/"
41
41
  },
42
- "gitHead": "3ef9fcf34827ece4d4e32b81b28b4b21aaa1b887"
42
+ "gitHead": "c7f6e2d76adc15985444d02244522841d52aa233"
43
43
  }