valdres 1.0.0-beta.0 → 1.0.0-beta.1
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 +10 -7
- package/dist/types/atomFamily.d.ts +11 -1
- package/dist/types/index.d.ts +5 -1
- package/dist/types/lib/createGlobalAtomFamily.d.ts +1 -1
- package/dist/types/lib/initAtom.d.ts +1 -1
- package/dist/types/lib/initSelector.d.ts +2 -2
- package/dist/types/lib/transaction.d.ts +1 -1
- package/dist/types/types/SyncSetAtom.d.ts +4 -0
- package/dist/types/types/TransactionInterface.d.ts +2 -6
- package/dist/types/utils/isFamily.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1566,14 +1566,17 @@ class Transaction {
|
|
|
1566
1566
|
set = (atom, value) => {
|
|
1567
1567
|
if (!isAtom(atom))
|
|
1568
1568
|
throw new Error("Not an atom");
|
|
1569
|
+
let resolved;
|
|
1569
1570
|
if (isFunction(value)) {
|
|
1570
1571
|
const currentValue = this.get(atom);
|
|
1571
|
-
|
|
1572
|
+
resolved = value(currentValue);
|
|
1573
|
+
} else {
|
|
1574
|
+
resolved = value;
|
|
1572
1575
|
}
|
|
1573
|
-
if (!atom.mutable && !isProd() &&
|
|
1574
|
-
|
|
1576
|
+
if (!atom.mutable && !isProd() && resolved !== null && (typeof resolved === "object" || typeof resolved === "function")) {
|
|
1577
|
+
resolved = deepFreeze(resolved);
|
|
1575
1578
|
}
|
|
1576
|
-
this._atomMap.set(atom,
|
|
1579
|
+
this._atomMap.set(atom, resolved);
|
|
1577
1580
|
if (!this.dirty)
|
|
1578
1581
|
this.dirty = true;
|
|
1579
1582
|
if (isFamilyAtom(atom)) {
|
|
@@ -1587,7 +1590,7 @@ class Transaction {
|
|
|
1587
1590
|
index.renderedArray = null;
|
|
1588
1591
|
this.recursivelyUpdateAtomFamilyIndexes(atom.family);
|
|
1589
1592
|
}
|
|
1590
|
-
return
|
|
1593
|
+
return resolved;
|
|
1591
1594
|
};
|
|
1592
1595
|
batchSetFamilyAtoms = (family, pairs) => {
|
|
1593
1596
|
if (!this._atomMap.has(family)) {
|
|
@@ -2399,9 +2402,9 @@ var isFamilySelector = (state) => isFamilyState(state) && isSelector(state);
|
|
|
2399
2402
|
|
|
2400
2403
|
// src/index.ts
|
|
2401
2404
|
if (globalThis.__valdres__) {
|
|
2402
|
-
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"1.0.0-beta.
|
|
2405
|
+
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${"1.0.0-beta.1"}`);
|
|
2403
2406
|
} else {
|
|
2404
|
-
globalThis.__valdres__ = "1.0.0-beta.
|
|
2407
|
+
globalThis.__valdres__ = "1.0.0-beta.1";
|
|
2405
2408
|
}
|
|
2406
2409
|
export {
|
|
2407
2410
|
store,
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
import type { AtomFamily } from "./types/AtomFamily";
|
|
1
2
|
import type { AtomFamilyDefaultValue } from "./types/AtomFamilyDefaultValue";
|
|
3
|
+
import type { AtomFamilyAtom } from "./types/AtomFamilyAtom";
|
|
2
4
|
import type { AtomOptions } from "./types/AtomOptions";
|
|
3
|
-
|
|
5
|
+
import type { GlobalAtom } from "./types/GlobalAtom";
|
|
6
|
+
type GlobalAtomFamily<Value, Args extends [any, ...any[]] = [any, ...any[]]> = Omit<AtomFamily<Value, Args>, never> & {
|
|
7
|
+
(...args: Args): AtomFamilyAtom<Value, Args> & GlobalAtom<Value>;
|
|
8
|
+
};
|
|
9
|
+
export declare function atomFamily<Value extends any, Args extends [any, ...any[]] = [any, ...any[]]>(defaultValue: AtomFamilyDefaultValue<Value, Args> | undefined, options: AtomOptions<Value> & {
|
|
10
|
+
global: true;
|
|
11
|
+
}): GlobalAtomFamily<Value, Args>;
|
|
12
|
+
export declare function atomFamily<Value extends any, Args extends [any, ...any[]] = [any, ...any[]]>(defaultValue?: AtomFamilyDefaultValue<Value, Args>, options?: AtomOptions<Value>): AtomFamily<Value, Args>;
|
|
13
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -27,12 +27,16 @@ export type { AtomFamily } from "./types/AtomFamily";
|
|
|
27
27
|
export type { FamilyKey } from "./types/FamilyKey";
|
|
28
28
|
export type { GetValue } from "./types/GetValue";
|
|
29
29
|
export type { Reactive } from "./types/Reactive";
|
|
30
|
-
export type { GlobalAtom } from "./types/GlobalAtom";
|
|
30
|
+
export type { GlobalAtom, MaxAgeInterval } from "./types/GlobalAtom";
|
|
31
|
+
export type { GlobalAtomGetSelfFunc } from "./types/GlobalAtomGetSelfFunc";
|
|
32
|
+
export type { GlobalAtomResetSelfFunc } from "./types/GlobalAtomResetSelfFunc";
|
|
33
|
+
export type { GlobalAtomSetSelfFunc } from "./types/GlobalAtomSetSelfFunc";
|
|
31
34
|
export type { ResetAtom } from "./types/ResetAtom";
|
|
32
35
|
export type { Selector, SelectorGetOptions } from "./types/Selector";
|
|
33
36
|
export type { SelectorFamily } from "./types/SelectorFamily";
|
|
34
37
|
export type { SetAtom } from "./types/SetAtom";
|
|
35
38
|
export type { SetAtomValue } from "./types/SetAtomValue";
|
|
39
|
+
export type { SyncSetAtom } from "./types/SyncSetAtom";
|
|
36
40
|
export type { State } from "./types/State";
|
|
37
41
|
export type { Store } from "./types/Store";
|
|
38
42
|
export type { StoreData } from "./types/StoreData";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { AtomFamily } from "../types/AtomFamily";
|
|
2
2
|
import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
|
|
3
3
|
import type { AtomOptions } from "../types/AtomOptions";
|
|
4
|
-
export declare const createGlobalAtomFamily: <Value extends
|
|
4
|
+
export declare const createGlobalAtomFamily: <Value extends unknown, Args extends [any, ...any[]] = [any, ...any[]]>(defaultValue: AtomFamilyDefaultValue<Value, Args>, options: AtomOptions<Value>) => AtomFamily<Value, Args>;
|
|
@@ -2,4 +2,4 @@ import type { Atom } from "../types/Atom";
|
|
|
2
2
|
import type { AtomFamilyAtom } from "../types/AtomFamilyAtom";
|
|
3
3
|
import type { StoreData } from "../types/StoreData";
|
|
4
4
|
export declare const getAtomInitValue: <V = any>(atom: Atom<V>, data: StoreData, initializedAtomsSet: Set<Atom>) => any;
|
|
5
|
-
export declare const initAtom: <Value extends
|
|
5
|
+
export declare const initAtom: <Value extends unknown, Args extends [any, ...any[]] = [any, ...any[]]>(atom: Atom<Value> | AtomFamilyAtom<Value, Args>, data: StoreData, initializedAtomsSet: Set<Atom>) => void;
|
|
@@ -19,6 +19,6 @@ export declare let _evalDepth: number;
|
|
|
19
19
|
* Each level uses ~8-10 JS stack frames, so 100 levels ≈ 800-1000 frames,
|
|
20
20
|
* safely under the typical ~10000 frame limit. */
|
|
21
21
|
export declare const MAX_EVAL_DEPTH = 100;
|
|
22
|
-
export declare const evaluateSelector: <V>(selector: Selector<V>, data: StoreData, initializedAtomsSet: Set<Atom>, circularDependencySet?: WeakSet<WeakKey>, addedDepsOut?: Set<State>, removedDepsOut?: Set<State>) =>
|
|
23
|
-
export declare const handleSelectorResult: <Value>(value: Value | Promise<Value> | SuspendAndWaitForResolveError, selector: Selector<Value>, data: StoreData) => Promise<any
|
|
22
|
+
export declare const evaluateSelector: <V>(selector: Selector<V>, data: StoreData, initializedAtomsSet: Set<Atom>, circularDependencySet?: WeakSet<WeakKey>, addedDepsOut?: Set<State>, removedDepsOut?: Set<State>) => V | Promise<V> | SuspendAndWaitForResolveError;
|
|
23
|
+
export declare const handleSelectorResult: <Value>(value: Value | Promise<Value> | SuspendAndWaitForResolveError, selector: Selector<Value>, data: StoreData) => Value | Promise<any>;
|
|
24
24
|
export declare const initSelector: <V>(selector: Selector<V>, data: StoreData, initializedAtomsSet: Set<Atom>, circularDependencySet?: WeakSet<WeakKey>) => boolean;
|
|
@@ -17,7 +17,7 @@ export declare class Transaction {
|
|
|
17
17
|
private hasTxnOrData;
|
|
18
18
|
private valueFromTxnOrData;
|
|
19
19
|
get: GetValue;
|
|
20
|
-
set: <V>(atom: Atom<V>, value: V | ((currentValue: V) => V)) => V
|
|
20
|
+
set: <V>(atom: Atom<V>, value: V | ((currentValue: V) => V)) => V;
|
|
21
21
|
batchSetFamilyAtoms: (family: any, pairs: any) => void;
|
|
22
22
|
del: (atom: AtomFamilyAtom<any, any>) => void;
|
|
23
23
|
scope: (scopeId: string, callback: (txn: Transaction) => any) => any;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import type { Atom } from "./Atom";
|
|
2
1
|
import type { AtomFamilyAtom } from "./AtomFamilyAtom";
|
|
3
2
|
import type { GetValue } from "./GetValue";
|
|
4
3
|
import type { ResetAtom } from "./ResetAtom";
|
|
5
|
-
import type { SetAtom } from "./SetAtom";
|
|
6
4
|
import type { StoreData } from "./StoreData";
|
|
5
|
+
import type { SyncSetAtom } from "./SyncSetAtom";
|
|
7
6
|
import type { TransactionFn } from "./TransactionFn";
|
|
8
|
-
export type SetAtom2 = {
|
|
9
|
-
<V>(atom: Atom<V>, value: V): V;
|
|
10
|
-
};
|
|
11
7
|
export type TransactionInterface = {
|
|
12
|
-
set:
|
|
8
|
+
set: SyncSetAtom;
|
|
13
9
|
get: GetValue;
|
|
14
10
|
del: (atom: AtomFamilyAtom<any, any>) => void;
|
|
15
11
|
reset: ResetAtom;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const isFamily: (state: any) => state is import("..").
|
|
1
|
+
export declare const isFamily: (state: any) => state is import("..").AtomFamily<unknown, [any, ...any[]]> | import("..").SelectorFamily<unknown, [any, ...any[]]>;
|