valdres 0.2.0-alpha.56 → 0.2.0-alpha.58
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 +15 -11
- package/dist/types/index.d.ts +3 -0
- package/dist/types/src/lib/isFunction.d.ts +1 -0
- 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
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// index.ts
|
|
2
|
+
import { version } from "./package.json";
|
|
3
|
+
|
|
1
4
|
// src/lib/equal.ts
|
|
2
5
|
var hasElementType = typeof Element !== "undefined";
|
|
3
6
|
var hasMap = typeof Map === "function";
|
|
@@ -130,10 +133,10 @@ var isSelector = (state) => state && Object.hasOwn(state, "get");
|
|
|
130
133
|
// src/utils/isSelectorFamily.ts
|
|
131
134
|
var isSelectorFamily = (state) => state && Object.hasOwn(state, "__valdresSelectorFamilyMap");
|
|
132
135
|
|
|
136
|
+
// src/lib/isFunction.ts
|
|
137
|
+
var isFunction = (value) => typeof value === "function";
|
|
138
|
+
|
|
133
139
|
// src/lib/setAtom.ts
|
|
134
|
-
var isFunction = (value) => {
|
|
135
|
-
return typeof value === "function";
|
|
136
|
-
};
|
|
137
140
|
var setAtom = (atom, newValue, data, skipOnSet = false) => {
|
|
138
141
|
const currentValue = getState(atom, data);
|
|
139
142
|
if (isFunction(newValue)) {
|
|
@@ -653,7 +656,7 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
653
656
|
const txnSet = (atom, value) => {
|
|
654
657
|
if (!isAtom(atom))
|
|
655
658
|
throw new Error("Not an atom");
|
|
656
|
-
if (
|
|
659
|
+
if (isFunction(value)) {
|
|
657
660
|
const currentValue = txnGet(atom);
|
|
658
661
|
value = value(currentValue);
|
|
659
662
|
}
|
|
@@ -665,6 +668,7 @@ var transaction = (callback, data, autoCommit = true) => {
|
|
|
665
668
|
recursivlyResetTxnSelectorCache(atom, txnSubscribers, txnSelectorCache);
|
|
666
669
|
}
|
|
667
670
|
txnAtomMap.set(atom, value);
|
|
671
|
+
return value;
|
|
668
672
|
};
|
|
669
673
|
const txnReset = (atom) => {
|
|
670
674
|
const value = getAtomInitValue(atom, data);
|
|
@@ -773,15 +777,8 @@ var store = (id) => {
|
|
|
773
777
|
const data = createStoreData(id);
|
|
774
778
|
return storeFromStoreData(data);
|
|
775
779
|
};
|
|
776
|
-
// package.json
|
|
777
|
-
var version = "0.2.0-alpha.55";
|
|
778
780
|
|
|
779
781
|
// src/globalStore.ts
|
|
780
|
-
if (globalThis.__valdres__) {
|
|
781
|
-
throw new Error(`Error! An instance of valdres is already loaded`);
|
|
782
|
-
} else {
|
|
783
|
-
globalThis.__valdres__ = version;
|
|
784
|
-
}
|
|
785
782
|
var globalStore = Object.assign(store("valdres-global-store"), {
|
|
786
783
|
atoms: new Map,
|
|
787
784
|
atomFamilies: new Map
|
|
@@ -1049,6 +1046,13 @@ var selectorFamily = (get, options) => {
|
|
|
1049
1046
|
};
|
|
1050
1047
|
// src/utils/isFamilySelector.ts
|
|
1051
1048
|
var isFamilySelector = (state) => isFamilyState(state) && isSelector(state);
|
|
1049
|
+
|
|
1050
|
+
// index.ts
|
|
1051
|
+
if (globalThis.__valdres__) {
|
|
1052
|
+
throw new Error(`Error! An instance of valdres is already loaded. Loaded: ${globalThis.__valdres__}. Attempted to load: ${version}`);
|
|
1053
|
+
} else {
|
|
1054
|
+
globalThis.__valdres__ = version;
|
|
1055
|
+
}
|
|
1052
1056
|
export {
|
|
1053
1057
|
store,
|
|
1054
1058
|
selectorFamily,
|
package/dist/types/index.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isFunction: (value: unknown) => value is Function;
|
|
@@ -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.58",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Eigil Sagafos"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"dist"
|
|
20
20
|
],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "NODE_ENV=production bun build
|
|
22
|
+
"build": "NODE_ENV=production bun run build.ts",
|
|
23
23
|
"build:types": "rm -rf dist/types && bun run tsc",
|
|
24
24
|
"test": "bun test"
|
|
25
25
|
},
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"access": "public",
|
|
37
37
|
"registry": "https://registry.npmjs.org/"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "9783a71f127ea52a02868525a075bc78b1c9f9ef"
|
|
40
40
|
}
|