valdres 0.1.0-alpha.8 → 0.1.0-alpha.9

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 (38) hide show
  1. package/dist/index.d.ts +14 -0
  2. package/dist/src/atom.d.ts +9 -0
  3. package/dist/src/atomFamily.d.ts +2 -0
  4. package/dist/src/createStore.d.ts +2 -0
  5. package/dist/src/getDefaultStore.d.ts +2 -0
  6. package/dist/src/lib/getState.d.ts +3 -0
  7. package/dist/src/lib/initAtom.d.ts +4 -0
  8. package/dist/src/lib/initSelector.d.ts +4 -0
  9. package/dist/src/lib/propagateUpdatedAtoms.d.ts +3 -0
  10. package/dist/src/lib/resetAtom.d.ts +3 -0
  11. package/dist/src/lib/setAtom.d.ts +3 -0
  12. package/dist/src/lib/setAtoms.d.ts +3 -0
  13. package/dist/src/lib/stableStringify.d.ts +1 -0
  14. package/dist/src/lib/subscribe.d.ts +3 -0
  15. package/dist/src/lib/transaction.d.ts +8 -0
  16. package/dist/src/lib/unsubscribe.d.ts +3 -0
  17. package/dist/src/lib/updateSelectorSubscribers.d.ts +3 -0
  18. package/dist/src/lib/updateStateSubscribers.d.ts +3 -0
  19. package/dist/src/selector.d.ts +5 -0
  20. package/dist/src/selectorFamily.d.ts +4 -0
  21. package/dist/src/types/Atom.d.ts +7 -0
  22. package/dist/src/types/AtomFamily.d.ts +5 -0
  23. package/dist/src/types/Family.d.ts +3 -0
  24. package/dist/src/types/GetValue.d.ts +2 -0
  25. package/dist/src/types/ResetAtom.d.ts +2 -0
  26. package/dist/src/types/Selector.d.ts +4 -0
  27. package/dist/src/types/SelectorFamily.d.ts +1 -0
  28. package/dist/src/types/SetAtom.d.ts +2 -0
  29. package/dist/src/types/State.d.ts +3 -0
  30. package/dist/src/types/Store.d.ts +14 -0
  31. package/dist/src/types/StoreData.d.ts +7 -0
  32. package/dist/src/types/SubscribeFn.d.ts +2 -0
  33. package/dist/src/types/TransactionFn.d.ts +4 -0
  34. package/dist/src/utils/isAtom.d.ts +2 -0
  35. package/dist/src/utils/isFamily.d.ts +1 -0
  36. package/dist/src/utils/isPromiseLike.d.ts +1 -0
  37. package/dist/src/utils/isSelector.d.ts +3 -0
  38. package/package.json +4 -2
@@ -0,0 +1,14 @@
1
+ export { atom } from "./src/atom";
2
+ export { atomFamily } from "./src/atomFamily";
3
+ export { createStore } from "./src/createStore";
4
+ export { getDefaultStore, resetDefaultStore } from "./src/getDefaultStore";
5
+ export { selector } from "./src/selector";
6
+ export { selectorFamily } from "./src/selectorFamily";
7
+ export { isAtom } from "./src/utils/isAtom";
8
+ export { isSelector } from "./src/utils/isSelector";
9
+ export { isFamily } from "./src/utils/isFamily";
10
+ export { isPromiseLike } from "./src/utils/isPromiseLike";
11
+ export type { Atom } from "./src/types/Atom";
12
+ export type { Selector } from "./src/types/Selector";
13
+ export type { State } from "./src/types/State";
14
+ export type { Store } from "./src/types/Store";
@@ -0,0 +1,9 @@
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 {};
@@ -0,0 +1,2 @@
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>;
@@ -0,0 +1,2 @@
1
+ import type { Store } from "./types/Store";
2
+ export declare const createStore: (id?: string) => Store;
@@ -0,0 +1,2 @@
1
+ export declare const getDefaultStore: () => any;
2
+ export declare const resetDefaultStore: () => import("..").Store;
@@ -0,0 +1,3 @@
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>;
@@ -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;
@@ -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 { State } from "../types/State";
2
+ import type { StoreData } from "../types/StoreData";
3
+ export declare const subscribe: <V>(state: State<V>, callback: any, data: StoreData) => () => void;
@@ -0,0 +1,8 @@
1
+ import type { State } from "../types/State";
2
+ import type { StoreData } from "../types/StoreData";
3
+ type GetValdresValue = <V>(state: State<V>) => V;
4
+ type SetValdresValue = <V>(state: State<V>, value: V) => void;
5
+ type ResetValdresValue = <V>(state: State<V>) => V;
6
+ type TransactionInterface = (set: SetValdresValue, get: GetValdresValue, reset: ResetValdresValue, commit: () => void) => void;
7
+ export declare const transaction: (callback: TransactionInterface, data: StoreData) => void;
8
+ export {};
@@ -0,0 +1,3 @@
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, store: StoreData, mountRes?: 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, oldValue: any) => 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,5 @@
1
+ import type { GetValue } from "./types/GetValue";
2
+ export declare const selector: (get: GetValue, debugLabel?: string) => {
3
+ get: GetValue;
4
+ debugLabel: string;
5
+ };
@@ -0,0 +1,4 @@
1
+ export declare const selectorFamily: <V, A>(get: any, debugLabel?: string) => {
2
+ (key: A): any;
3
+ _map: Map<any, any>;
4
+ };
@@ -0,0 +1,7 @@
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
+ };
@@ -0,0 +1,5 @@
1
+ import type { Atom } from "./Atom";
2
+ export type AtomFamily<Value, Key> = {
3
+ (key: Key, defaultOverride?: any): Atom<Value, Key>;
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> = AtomFamily<V, K> | SelectorFamily<V, K>;
@@ -0,0 +1,2 @@
1
+ import type { State } from "./State";
2
+ export type GetValue = <V>(state: State<V>) => V;
@@ -0,0 +1,2 @@
1
+ import type { Atom } from "./Atom";
2
+ export type ResetAtom = <V>(state: Atom<V>) => V;
@@ -0,0 +1,4 @@
1
+ export type Selector<V = any> = {
2
+ get: () => {};
3
+ debugLabel?: string;
4
+ };
@@ -0,0 +1 @@
1
+ export type SelectorFamily<A, V> = {};
@@ -0,0 +1,2 @@
1
+ import type { Atom } from "./Atom";
2
+ export type SetAtom = <V>(atom: Atom<V>, value: V) => void;
@@ -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,7 @@
1
+ export type StoreData = {
2
+ id: string;
3
+ values: WeakMap<WeakKey, any>;
4
+ subscriptions: WeakMap<WeakKey, any>;
5
+ stateConsumers: WeakMap<WeakKey, any>;
6
+ stateDependencies: WeakMap<WeakKey, any>;
7
+ };
@@ -0,0 +1,2 @@
1
+ import type { State } from "./State";
2
+ export type SubscribeFn = <V>(state: State<V>, callback: () => void) => () => void;
@@ -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 { State } from "../types/State";
2
+ export declare const isAtom: (state: State) => boolean;
@@ -0,0 +1 @@
1
+ export declare const isFamily: (state: any) => boolean;
@@ -0,0 +1 @@
1
+ export declare const isPromiseLike: (object: any) => boolean;
@@ -0,0 +1,3 @@
1
+ import type { Selector } from "../types/Selector";
2
+ import type { State } from "../types/State";
3
+ export declare const isSelector: (state: State) => state is Selector;
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.1.0-alpha.8",
3
+ "version": "0.1.0-alpha.9",
4
4
  "module": "dist/index.js",
5
+ "types": "dist/index.d.ts",
5
6
  "files": [
6
7
  "dist"
7
8
  ],
8
9
  "type": "module",
9
10
  "scripts": {
10
11
  "build": "bun scripts/build.ts",
12
+ "build:types": "tsc index.ts --declaration --emitDeclarationOnly --outDir dist",
11
13
  "test": "bun test"
12
14
  },
13
15
  "dependencies": {
@@ -24,5 +26,5 @@
24
26
  "access": "public",
25
27
  "registry": "https://registry.npmjs.org/"
26
28
  },
27
- "gitHead": "d4b29c9b00ea2da90297ec6f13f5f7eb18392e41"
29
+ "gitHead": "1324ed703443d3b6bea79193a6e398da5cad0ca0"
28
30
  }