valdres 0.2.0-alpha.42 → 0.2.0-alpha.45
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.
- package/dist/index.js +32 -4
- package/dist/types/index.d.ts +29 -0
- package/dist/types/src/atom.d.ts +16 -0
- package/dist/types/src/atomFamily.d.ts +4 -0
- package/dist/types/src/createStoreWithSelectorSet.d.ts +2 -0
- package/dist/types/src/globalStore.d.ts +4 -0
- package/dist/types/src/lib/atomFamilyAtom.d.ts +8 -0
- package/dist/types/src/lib/createAtomFamily.d.ts +4 -0
- package/dist/types/src/lib/createGlobalAtomFamily.d.ts +5 -0
- package/dist/types/src/lib/createStoreData.d.ts +3 -0
- package/dist/types/src/lib/equal.d.ts +1 -0
- package/dist/types/src/lib/getState.d.ts +7 -0
- package/dist/types/src/lib/globalAtom.d.ts +4 -0
- package/dist/types/src/lib/initAtom.d.ts +5 -0
- package/dist/types/src/lib/initSelector.d.ts +4 -0
- package/dist/types/src/lib/propagateUpdatedAtoms.d.ts +4 -0
- package/dist/types/src/lib/resetAtom.d.ts +3 -0
- package/dist/types/src/lib/setAtom.d.ts +3 -0
- package/dist/types/src/lib/setAtoms.d.ts +3 -0
- package/dist/types/src/lib/stableStringify.d.ts +1 -0
- package/dist/types/src/lib/storeFromStoreData.d.ts +4 -0
- package/dist/types/src/lib/subscribe.d.ts +4 -0
- package/dist/types/src/lib/transaction.d.ts +3 -0
- package/dist/types/src/lib/unsubscribe.d.ts +5 -0
- package/dist/types/src/lib/updateSelectorSubscribers.d.ts +3 -0
- package/dist/types/src/lib/updateStateSubscribers.d.ts +3 -0
- package/dist/types/src/selector.d.ts +4 -0
- package/dist/types/src/selectorFamily.d.ts +4 -0
- package/dist/types/src/store.d.ts +1 -0
- package/dist/types/src/types/Atom.d.ts +14 -0
- package/dist/types/src/types/AtomDefaultValue.d.ts +2 -0
- package/dist/types/src/types/AtomFamily.d.ts +12 -0
- package/dist/types/src/types/AtomFamilyAtom.d.ts +6 -0
- package/dist/types/src/types/AtomFamilyDefaultValue.d.ts +5 -0
- package/dist/types/src/types/AtomFamilyGlobalAtom.d.ts +3 -0
- package/dist/types/src/types/AtomFamilySelector.d.ts +6 -0
- package/dist/types/src/types/AtomOnInit.d.ts +2 -0
- package/dist/types/src/types/AtomOnSet.d.ts +2 -0
- package/dist/types/src/types/AtomOptions.d.ts +13 -0
- package/dist/types/src/types/EqualFunc.d.ts +1 -0
- package/dist/types/src/types/Family.d.ts +3 -0
- package/dist/types/src/types/FamilyKey.d.ts +3 -0
- package/dist/types/src/types/GetValue.d.ts +8 -0
- package/dist/types/src/types/GlobalAtom.d.ts +11 -0
- package/dist/types/src/types/GlobalAtomGetSelfFunc.d.ts +1 -0
- package/dist/types/src/types/GlobalAtomResetSelfFunc.d.ts +1 -0
- package/dist/types/src/types/GlobalAtomSetSelfFunc.d.ts +1 -0
- package/dist/types/src/types/ResetAtom.d.ts +2 -0
- package/dist/types/src/types/Selector.d.ts +11 -0
- package/dist/types/src/types/SelectorFamily.d.ts +6 -0
- package/dist/types/src/types/SelectorOptions.d.ts +5 -0
- package/dist/types/src/types/SetAtom.d.ts +3 -0
- package/dist/types/src/types/SetAtomValue.d.ts +1 -0
- package/dist/types/src/types/State.d.ts +4 -0
- package/dist/types/src/types/Store.d.ts +24 -0
- package/dist/types/src/types/StoreData.d.ts +17 -0
- package/dist/types/src/types/SubscribeFn.d.ts +2 -0
- package/dist/types/src/types/Subscription.d.ts +1 -0
- package/dist/types/src/types/TransactionFn.d.ts +4 -0
- package/dist/types/src/utils/isAtom.d.ts +2 -0
- package/dist/types/src/utils/isAtomFamily.d.ts +2 -0
- package/dist/types/src/utils/isFamily.d.ts +1 -0
- package/dist/types/src/utils/isFamilyAtom.d.ts +2 -0
- package/dist/types/src/utils/isFamilySelector.d.ts +2 -0
- package/dist/types/src/utils/isFamilyState.d.ts +3 -0
- package/dist/types/src/utils/isPromiseLike.d.ts +1 -0
- package/dist/types/src/utils/isSelector.d.ts +2 -0
- package/dist/types/src/utils/isSelectorFamily.d.ts +2 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -566,11 +566,12 @@ var recursivlyResetTxnSelectorCache = (state, txnSubscribers, txnSelectorCache)
|
|
|
566
566
|
}
|
|
567
567
|
}
|
|
568
568
|
};
|
|
569
|
-
var transaction = (callback, data) => {
|
|
569
|
+
var transaction = (callback, data, autoCommit = true) => {
|
|
570
570
|
let txnAtomMap = new Map;
|
|
571
571
|
let txnSelectorCache = new Map;
|
|
572
572
|
let txnSubscribers = new Map;
|
|
573
573
|
let dirtySelectors = new Set;
|
|
574
|
+
let scopedTransactions;
|
|
574
575
|
const txnGet = (state) => {
|
|
575
576
|
if (isAtom(state)) {
|
|
576
577
|
return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state, data);
|
|
@@ -591,6 +592,8 @@ var transaction = (callback, data) => {
|
|
|
591
592
|
}
|
|
592
593
|
txnSelectorCache.set(state, res);
|
|
593
594
|
return res;
|
|
595
|
+
} else if (isFamily(state)) {
|
|
596
|
+
return txnAtomMap.has(state) ? txnAtomMap.get(state) : getState(state.__keysSelector, data);
|
|
594
597
|
} else {
|
|
595
598
|
throw new Error("Unsupported state");
|
|
596
599
|
}
|
|
@@ -619,9 +622,34 @@ var transaction = (callback, data) => {
|
|
|
619
622
|
const commit = () => {
|
|
620
623
|
setAtoms(txnAtomMap, data);
|
|
621
624
|
dirtySelectors.clear();
|
|
625
|
+
if (scopedTransactions) {
|
|
626
|
+
for (const scopedTxn of Object.values(scopedTransactions)) {
|
|
627
|
+
scopedTxn[3]();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
622
630
|
};
|
|
623
|
-
const result = callback(txnSet, txnGet, txnReset, commit)
|
|
624
|
-
|
|
631
|
+
const result = callback(txnSet, txnGet, txnReset, commit, (scopeId, callback2) => {
|
|
632
|
+
if (scopeId in data.scopes) {
|
|
633
|
+
const scopedData = data.scopes[scopeId];
|
|
634
|
+
if (scopedTransactions?.[scopeId] === undefined) {
|
|
635
|
+
scopedTransactions ||= {};
|
|
636
|
+
transaction((set, get, reset, commit2, scope) => {
|
|
637
|
+
scopedTransactions[scopeId] = [
|
|
638
|
+
set,
|
|
639
|
+
get,
|
|
640
|
+
reset,
|
|
641
|
+
commit2,
|
|
642
|
+
scope
|
|
643
|
+
];
|
|
644
|
+
}, scopedData, false);
|
|
645
|
+
}
|
|
646
|
+
callback2(...scopedTransactions[scopeId]);
|
|
647
|
+
} else {
|
|
648
|
+
throw new Error("Scope not found");
|
|
649
|
+
}
|
|
650
|
+
});
|
|
651
|
+
if (autoCommit)
|
|
652
|
+
commit();
|
|
625
653
|
return result;
|
|
626
654
|
};
|
|
627
655
|
|
|
@@ -693,7 +721,7 @@ var store = (id) => {
|
|
|
693
721
|
return storeFromStoreData(data);
|
|
694
722
|
};
|
|
695
723
|
// package.json
|
|
696
|
-
var version = "0.2.0-alpha.
|
|
724
|
+
var version = "0.2.0-alpha.44";
|
|
697
725
|
|
|
698
726
|
// src/globalStore.ts
|
|
699
727
|
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,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 @@
|
|
|
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 @@
|
|
|
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,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,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,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,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,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,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,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 @@
|
|
|
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 {};
|
|
@@ -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 @@
|
|
|
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, scope: (scopeId: string, callback: TransactionFn) => void) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isFamily: (state: any) => state is import("../..").SelectorFamily<unknown, unknown> | import("../..").AtomFamily<unknown, unknown>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isPromiseLike: <T>(object: any) => object is Promise<T>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "valdres",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.45",
|
|
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": "
|
|
39
|
+
"gitHead": "8d9c1d1c9108b11ae9201a2bcd139f384d3884c5"
|
|
40
40
|
}
|