valdres 0.2.0-alpha.55 → 0.2.0-alpha.57
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 +9 -4
- package/dist/types/src/lib/isFunction.d.ts +1 -0
- package/dist/types/src/lib/setAtom.d.ts +1 -1
- package/dist/types/src/types/EqualFunc.d.ts +1 -1
- package/dist/types/src/types/SetAtom.d.ts +3 -1
- package/dist/types/src/types/TransactionInterface.d.ts +4 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -130,16 +130,19 @@ var isSelector = (state) => state && Object.hasOwn(state, "get");
|
|
|
130
130
|
// src/utils/isSelectorFamily.ts
|
|
131
131
|
var isSelectorFamily = (state) => state && Object.hasOwn(state, "__valdresSelectorFamilyMap");
|
|
132
132
|
|
|
133
|
+
// src/lib/isFunction.ts
|
|
134
|
+
var isFunction = (value) => typeof value === "function";
|
|
135
|
+
|
|
133
136
|
// src/lib/setAtom.ts
|
|
134
137
|
var setAtom = (atom, newValue, data, skipOnSet = false) => {
|
|
135
138
|
const currentValue = getState(atom, data);
|
|
136
|
-
if (
|
|
139
|
+
if (isFunction(newValue)) {
|
|
137
140
|
newValue = newValue(currentValue);
|
|
138
141
|
if (isPromiseLike(newValue) || isPromiseLike(currentValue))
|
|
139
142
|
throw new Error("Todo, how should we handle this?");
|
|
140
143
|
}
|
|
141
144
|
if (atom.equal(currentValue, newValue))
|
|
142
|
-
return;
|
|
145
|
+
return newValue;
|
|
143
146
|
data.values.set(atom, newValue);
|
|
144
147
|
if (atom.onSet && !skipOnSet)
|
|
145
148
|
atom.onSet(newValue, data);
|
|
@@ -147,6 +150,7 @@ var setAtom = (atom, newValue, data, skipOnSet = false) => {
|
|
|
147
150
|
currentValue.__resolveEmptyAtomPromise__(newValue);
|
|
148
151
|
}
|
|
149
152
|
propagateUpdatedAtoms([atom], data);
|
|
153
|
+
return newValue;
|
|
150
154
|
};
|
|
151
155
|
|
|
152
156
|
// src/lib/initAtom.ts
|
|
@@ -649,7 +653,7 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
649
653
|
const txnSet = (atom, value) => {
|
|
650
654
|
if (!isAtom(atom))
|
|
651
655
|
throw new Error("Not an atom");
|
|
652
|
-
if (
|
|
656
|
+
if (isFunction(value)) {
|
|
653
657
|
const currentValue = txnGet(atom);
|
|
654
658
|
value = value(currentValue);
|
|
655
659
|
}
|
|
@@ -661,6 +665,7 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
661
665
|
recursivlyResetTxnSelectorCache(atom, txnSubscribers, txnSelectorCache);
|
|
662
666
|
}
|
|
663
667
|
txnAtomMap.set(atom, value);
|
|
668
|
+
return value;
|
|
664
669
|
};
|
|
665
670
|
const txnReset = (atom) => {
|
|
666
671
|
const value = getAtomInitValue(atom, data);
|
|
@@ -770,7 +775,7 @@ var store = (id) => {
|
|
|
770
775
|
return storeFromStoreData(data);
|
|
771
776
|
};
|
|
772
777
|
// package.json
|
|
773
|
-
var version = "0.2.0-alpha.
|
|
778
|
+
var version = "0.2.0-alpha.56";
|
|
774
779
|
|
|
775
780
|
// src/globalStore.ts
|
|
776
781
|
if (globalThis.__valdres__) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isFunction: (value: unknown) => value is Function;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { Atom } from "../types/Atom";
|
|
2
2
|
import type { StoreData } from "../types/StoreData";
|
|
3
|
-
export declare const setAtom: <Value = any>(atom: Atom<Value>, newValue: Value, data: StoreData, skipOnSet?: boolean) =>
|
|
3
|
+
export declare const setAtom: <Value = any>(atom: Atom<Value>, newValue: Value | ((currentValue: Value) => Value), data: StoreData, skipOnSet?: boolean) => Value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type EqualFunc<Value> = (a: Value, b: Value) => boolean;
|
|
1
|
+
export type EqualFunc<Value = any> = (a: Value, b: Value) => boolean;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { Atom } from "./Atom";
|
|
1
2
|
import type { GetValue } from "./GetValue";
|
|
2
3
|
import type { ResetAtom } from "./ResetAtom";
|
|
3
4
|
import type { SetAtom } from "./SetAtom";
|
|
4
5
|
import type { StoreData } from "./StoreData";
|
|
5
6
|
import type { TransactionFn } from "./TransactionFn";
|
|
7
|
+
export type SetAtom2 = {
|
|
8
|
+
<V>(atom: Atom<V>, value: V): V;
|
|
9
|
+
};
|
|
6
10
|
export type TransactionInterface = {
|
|
7
11
|
set: SetAtom;
|
|
8
12
|
get: GetValue;
|
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.57",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Eigil Sagafos"
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "NODE_ENV=production bun build index.ts --outdir ./dist --packages external",
|
|
23
|
-
"build:types": "rm -rf dist/types && tsc",
|
|
23
|
+
"build:types": "rm -rf dist/types && bun run tsc",
|
|
24
24
|
"test": "bun test"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"access": "public",
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "ac804793bb3c428a50d3f2baf46d18a7dfeefee3"
|
|
40
40
|
}
|