valdres 0.2.0-alpha.67 → 0.2.0-alpha.69

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 CHANGED
@@ -146,14 +146,15 @@ var setAtom = (atom, newValue, data, skipOnSet = false) => {
146
146
  }
147
147
  if (atom.equal(currentValue, newValue))
148
148
  return newValue;
149
- data.values.set(atom, newValue);
149
+ const frozenNewValue = newValue;
150
+ data.values.set(atom, frozenNewValue);
150
151
  if (atom.onSet && !skipOnSet)
151
- atom.onSet(newValue, data);
152
+ atom.onSet(frozenNewValue, data);
152
153
  if (currentValue?.__isEmptyAtomPromise__) {
153
- currentValue.__resolveEmptyAtomPromise__(newValue);
154
+ currentValue.__resolveEmptyAtomPromise__(frozenNewValue);
154
155
  }
155
156
  propagateUpdatedAtoms([atom], data);
156
- return newValue;
157
+ return frozenNewValue;
157
158
  };
158
159
 
159
160
  // src/lib/initAtom.ts
@@ -899,6 +900,13 @@ function atom(defaultValue, options) {
899
900
  ...options
900
901
  };
901
902
  }
903
+ // src/selector.ts
904
+ var selector = (get, options) => {
905
+ if (!options)
906
+ return { equal, get };
907
+ return { equal, ...options, get };
908
+ };
909
+
902
910
  // src/lib/atomFamilyAtom.ts
903
911
  function atomFamilyAtom(defaultValue, options) {
904
912
  if (options.global) {
@@ -964,13 +972,6 @@ var stableStringify = (x) => {
964
972
  return stableStringifyRecurse(x);
965
973
  };
966
974
 
967
- // src/selector.ts
968
- var selector = (get, options) => {
969
- if (!options)
970
- return { equal, get };
971
- return { equal, ...options, get };
972
- };
973
-
974
975
  // src/lib/createAtomFamily.ts
975
976
  var createOptions = (options = {}, family, familyKey, keyStringified) => {
976
977
  if (options.name) {
@@ -1052,6 +1053,37 @@ var createStoreWithSelectorSet = (id) => {
1052
1053
  store2.kind = "storeWithSelectorSet";
1053
1054
  return store2;
1054
1055
  };
1056
+ // src/indexConstructor.ts
1057
+ var index = (family, callback) => {
1058
+ const map = new Map;
1059
+ return (term) => {
1060
+ const termKey = stableStringify(term);
1061
+ if (map.has(termKey))
1062
+ return map.get(termKey);
1063
+ const itemSelectorMap = new Map;
1064
+ const selectorMapIndex = selector((get) => {
1065
+ const ids = get(family);
1066
+ ids.forEach((id) => {
1067
+ if (itemSelectorMap.has(id))
1068
+ return;
1069
+ itemSelectorMap.set(id, selector((get2) => callback(get2(family(id)), term)));
1070
+ });
1071
+ return itemSelectorMap;
1072
+ });
1073
+ const filteredSelector = selector((get) => {
1074
+ const map2 = get(selectorMapIndex);
1075
+ const res = [];
1076
+ map2.forEach((selector2, key) => {
1077
+ if (get(selector2)) {
1078
+ res.push(key);
1079
+ }
1080
+ });
1081
+ return res;
1082
+ });
1083
+ map.set(termKey, filteredSelector);
1084
+ return filteredSelector;
1085
+ };
1086
+ };
1055
1087
  // src/selectorFamily.ts
1056
1088
  var createOptions2 = (options = {}, family, familyKey, keyStringified) => {
1057
1089
  if (options.name) {
@@ -1106,6 +1138,7 @@ export {
1106
1138
  isFamily,
1107
1139
  isAtomFamily,
1108
1140
  isAtom,
1141
+ index,
1109
1142
  globalStore,
1110
1143
  createStoreWithSelectorSet,
1111
1144
  atomFamily,
@@ -5,6 +5,7 @@ export { atom } from "./atom";
5
5
  export { atomFamily } from "./atomFamily";
6
6
  export { createStoreWithSelectorSet } from "./createStoreWithSelectorSet";
7
7
  export { globalStore } from "./globalStore";
8
+ export { index } from "./indexConstructor";
8
9
  export { selector } from "./selector";
9
10
  export { selectorFamily } from "./selectorFamily";
10
11
  export { store } from "./store";
@@ -0,0 +1,4 @@
1
+ import type { AtomFamily } from "./types/AtomFamily";
2
+ import type { FamilyKey } from "./types/FamilyKey";
3
+ import type { Selector } from "./types/Selector";
4
+ export declare const index: <T, K extends FamilyKey = FamilyKey, V = unknown>(family: AtomFamily<K, V>, callback: (value: V, term: T) => boolean) => ((term: T) => Selector<T[]>);
@@ -1,4 +1,4 @@
1
1
  import type { AtomFamily } from "../types/AtomFamily";
2
- import type { AtomOptions } from "../types/AtomOptions";
3
2
  import type { AtomFamilyDefaultValue } from "../types/AtomFamilyDefaultValue";
3
+ import type { AtomOptions } from "../types/AtomOptions";
4
4
  export declare const createAtomFamily: <Key, Value>(defaultValue: AtomFamilyDefaultValue<Key, Value>, options?: AtomOptions<Value>) => AtomFamily<Key, Value>;
@@ -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 | ((currentValue: Value) => Value), data: StoreData, skipOnSet?: boolean) => Value;
3
+ export declare const setAtom: <Value = any>(atom: Atom<Value>, newValue: Value | ((currentValue: Value) => Value), data: StoreData, skipOnSet?: boolean) => any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "valdres",
3
- "version": "0.2.0-alpha.67",
3
+ "version": "0.2.0-alpha.69",
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": "b2a032484129556e2138bd2a8b2491ef743833f0"
39
+ "gitHead": "302cb73fee8410a225d7c088211fc32520d79b3d"
40
40
  }