@gaddario98/react-core 2.0.4 → 2.0.7
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/auth/index.d.ts +13 -3
- package/dist/auth/index.js +1 -1
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/index.mjs.map +1 -1
- package/dist/form/index.js +155 -143
- package/dist/form/index.js.map +1 -1
- package/dist/form/index.mjs +153 -141
- package/dist/form/index.mjs.map +1 -1
- package/dist/index.d.ts +61 -39
- package/dist/index.js +898 -1544
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +889 -1535
- package/dist/index.mjs.map +1 -1
- package/dist/pages/index.d.ts +31 -32
- package/dist/pages/index.js +148 -143
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/index.mjs +148 -143
- package/dist/pages/index.mjs.map +1 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/queries/index.d.ts +1 -1
- package/dist/queries/index.js +371 -314
- package/dist/queries/index.js.map +1 -1
- package/dist/queries/index.mjs +371 -314
- package/dist/queries/index.mjs.map +1 -1
- package/dist/state/index.js +183 -151
- package/dist/state/index.js.map +1 -1
- package/dist/state/index.mjs +183 -151
- package/dist/state/index.mjs.map +1 -1
- package/dist/utiles/index.js +230 -151
- package/dist/utiles/index.js.map +1 -1
- package/dist/utiles/index.mjs +230 -151
- package/dist/utiles/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/state/index.js
CHANGED
|
@@ -1004,29 +1004,29 @@ function getMountedOrPendingDependents(atom, atomState, mountedMap) {
|
|
|
1004
1004
|
var _a;
|
|
1005
1005
|
const dependents = /* @__PURE__ */ new Set();
|
|
1006
1006
|
for (const a of ((_a = mountedMap.get(atom)) == null ? void 0 : _a.t) || []) {
|
|
1007
|
-
|
|
1008
|
-
dependents.add(a);
|
|
1009
|
-
}
|
|
1007
|
+
dependents.add(a);
|
|
1010
1008
|
}
|
|
1011
1009
|
for (const atomWithPendingPromise of atomState.p) {
|
|
1012
1010
|
dependents.add(atomWithPendingPromise);
|
|
1013
1011
|
}
|
|
1014
1012
|
return dependents;
|
|
1015
1013
|
}
|
|
1016
|
-
const
|
|
1017
|
-
const
|
|
1018
|
-
const
|
|
1014
|
+
const BUILDING_BLOCK_atomRead = (_store, atom, ...params) => atom.read(...params);
|
|
1015
|
+
const BUILDING_BLOCK_atomWrite = (_store, atom, ...params) => atom.write(...params);
|
|
1016
|
+
const BUILDING_BLOCK_atomOnInit = (store, atom) => {
|
|
1019
1017
|
var _a;
|
|
1020
|
-
return (_a = atom.
|
|
1018
|
+
return (_a = atom.INTERNAL_onInit) == null ? void 0 : _a.call(atom, store);
|
|
1021
1019
|
};
|
|
1022
|
-
const
|
|
1020
|
+
const BUILDING_BLOCK_atomOnMount = (_store, atom, setAtom) => {
|
|
1023
1021
|
var _a;
|
|
1024
1022
|
return (_a = atom.onMount) == null ? void 0 : _a.call(atom, setAtom);
|
|
1025
1023
|
};
|
|
1026
|
-
const
|
|
1024
|
+
const BUILDING_BLOCK_ensureAtomState = (store, atom) => {
|
|
1025
|
+
var _a;
|
|
1027
1026
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1028
1027
|
const atomStateMap = buildingBlocks[0];
|
|
1029
|
-
const
|
|
1028
|
+
const storeHooks = buildingBlocks[6];
|
|
1029
|
+
const atomOnInit = buildingBlocks[9];
|
|
1030
1030
|
if ((undefined ? undefined.MODE : void 0) !== "production" && !atom) {
|
|
1031
1031
|
throw new Error("Atom is undefined or null");
|
|
1032
1032
|
}
|
|
@@ -1034,18 +1034,19 @@ const ensureAtomState = (store, atom) => {
|
|
|
1034
1034
|
if (!atomState) {
|
|
1035
1035
|
atomState = { d: /* @__PURE__ */ new Map(), p: /* @__PURE__ */ new Set(), n: 0 };
|
|
1036
1036
|
atomStateMap.set(atom, atomState);
|
|
1037
|
-
|
|
1037
|
+
(_a = storeHooks.i) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1038
|
+
atomOnInit == null ? void 0 : atomOnInit(store, atom);
|
|
1038
1039
|
}
|
|
1039
1040
|
return atomState;
|
|
1040
1041
|
};
|
|
1041
|
-
const
|
|
1042
|
+
const BUILDING_BLOCK_flushCallbacks = (store) => {
|
|
1042
1043
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1043
1044
|
const mountedMap = buildingBlocks[1];
|
|
1044
1045
|
const changedAtoms = buildingBlocks[3];
|
|
1045
1046
|
const mountCallbacks = buildingBlocks[4];
|
|
1046
1047
|
const unmountCallbacks = buildingBlocks[5];
|
|
1047
1048
|
const storeHooks = buildingBlocks[6];
|
|
1048
|
-
const
|
|
1049
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1049
1050
|
const errors = [];
|
|
1050
1051
|
const call = (fn) => {
|
|
1051
1052
|
try {
|
|
@@ -1071,28 +1072,28 @@ const flushCallbacks = (store) => {
|
|
|
1071
1072
|
mountCallbacks.clear();
|
|
1072
1073
|
callbacks.forEach(call);
|
|
1073
1074
|
if (changedAtoms.size) {
|
|
1074
|
-
|
|
1075
|
+
recomputeInvalidatedAtoms(store);
|
|
1075
1076
|
}
|
|
1076
1077
|
} while (changedAtoms.size || unmountCallbacks.size || mountCallbacks.size);
|
|
1077
1078
|
if (errors.length) {
|
|
1078
1079
|
throw new AggregateError(errors);
|
|
1079
1080
|
}
|
|
1080
1081
|
};
|
|
1081
|
-
const
|
|
1082
|
+
const BUILDING_BLOCK_recomputeInvalidatedAtoms = (store) => {
|
|
1082
1083
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1083
1084
|
const mountedMap = buildingBlocks[1];
|
|
1084
1085
|
const invalidatedAtoms = buildingBlocks[2];
|
|
1085
1086
|
const changedAtoms = buildingBlocks[3];
|
|
1086
|
-
const
|
|
1087
|
-
const
|
|
1088
|
-
const
|
|
1087
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1088
|
+
const readAtomState = buildingBlocks[14];
|
|
1089
|
+
const mountDependencies = buildingBlocks[17];
|
|
1089
1090
|
const topSortedReversed = [];
|
|
1090
1091
|
const visiting = /* @__PURE__ */ new WeakSet();
|
|
1091
1092
|
const visited = /* @__PURE__ */ new WeakSet();
|
|
1092
1093
|
const stack = Array.from(changedAtoms);
|
|
1093
1094
|
while (stack.length) {
|
|
1094
1095
|
const a = stack[stack.length - 1];
|
|
1095
|
-
const aState =
|
|
1096
|
+
const aState = ensureAtomState(store, a);
|
|
1096
1097
|
if (visited.has(a)) {
|
|
1097
1098
|
stack.pop();
|
|
1098
1099
|
continue;
|
|
@@ -1124,38 +1125,41 @@ const recomputeInvalidatedAtoms = (store) => {
|
|
|
1124
1125
|
}
|
|
1125
1126
|
}
|
|
1126
1127
|
if (hasChangedDeps) {
|
|
1127
|
-
|
|
1128
|
-
|
|
1128
|
+
readAtomState(store, a);
|
|
1129
|
+
mountDependencies(store, a);
|
|
1129
1130
|
}
|
|
1130
1131
|
invalidatedAtoms.delete(a);
|
|
1131
1132
|
}
|
|
1132
1133
|
};
|
|
1133
|
-
const
|
|
1134
|
+
const storeMutationSet = /* @__PURE__ */ new WeakSet();
|
|
1135
|
+
const BUILDING_BLOCK_readAtomState = (store, atom) => {
|
|
1134
1136
|
var _a, _b;
|
|
1135
1137
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1136
1138
|
const mountedMap = buildingBlocks[1];
|
|
1137
1139
|
const invalidatedAtoms = buildingBlocks[2];
|
|
1138
1140
|
const changedAtoms = buildingBlocks[3];
|
|
1139
1141
|
const storeHooks = buildingBlocks[6];
|
|
1140
|
-
const
|
|
1141
|
-
const
|
|
1142
|
-
const
|
|
1143
|
-
const
|
|
1144
|
-
const
|
|
1145
|
-
const
|
|
1146
|
-
const
|
|
1147
|
-
const
|
|
1142
|
+
const atomRead = buildingBlocks[7];
|
|
1143
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1144
|
+
const flushCallbacks = buildingBlocks[12];
|
|
1145
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1146
|
+
const readAtomState = buildingBlocks[14];
|
|
1147
|
+
const writeAtomState = buildingBlocks[16];
|
|
1148
|
+
const mountDependencies = buildingBlocks[17];
|
|
1149
|
+
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
1150
|
+
const atomState = ensureAtomState(store, atom);
|
|
1148
1151
|
if (isAtomStateInitialized(atomState)) {
|
|
1149
1152
|
if (mountedMap.has(atom) && invalidatedAtoms.get(atom) !== atomState.n) {
|
|
1150
1153
|
return atomState;
|
|
1151
1154
|
}
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1155
|
+
let hasChangedDeps = false;
|
|
1156
|
+
for (const [a, n] of atomState.d) {
|
|
1157
|
+
if (readAtomState(store, a).n !== n) {
|
|
1158
|
+
hasChangedDeps = true;
|
|
1159
|
+
break;
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
if (!hasChangedDeps) {
|
|
1159
1163
|
return atomState;
|
|
1160
1164
|
}
|
|
1161
1165
|
}
|
|
@@ -1163,15 +1167,15 @@ const readAtomState = (store, atom) => {
|
|
|
1163
1167
|
let isSync = true;
|
|
1164
1168
|
function mountDependenciesIfAsync() {
|
|
1165
1169
|
if (mountedMap.has(atom)) {
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1170
|
+
mountDependencies(store, atom);
|
|
1171
|
+
recomputeInvalidatedAtoms(store);
|
|
1172
|
+
flushCallbacks(store);
|
|
1169
1173
|
}
|
|
1170
1174
|
}
|
|
1171
1175
|
function getter(a) {
|
|
1172
1176
|
var _a2;
|
|
1173
1177
|
if (a === atom) {
|
|
1174
|
-
const aState2 =
|
|
1178
|
+
const aState2 = ensureAtomState(store, a);
|
|
1175
1179
|
if (!isAtomStateInitialized(aState2)) {
|
|
1176
1180
|
if (hasInitialValue(a)) {
|
|
1177
1181
|
setAtomStateValueOrPromise(store, a, a.init);
|
|
@@ -1181,7 +1185,7 @@ const readAtomState = (store, atom) => {
|
|
|
1181
1185
|
}
|
|
1182
1186
|
return returnAtomValue(aState2);
|
|
1183
1187
|
}
|
|
1184
|
-
const aState =
|
|
1188
|
+
const aState = readAtomState(store, a);
|
|
1185
1189
|
try {
|
|
1186
1190
|
return returnAtomValue(aState);
|
|
1187
1191
|
} finally {
|
|
@@ -1189,7 +1193,9 @@ const readAtomState = (store, atom) => {
|
|
|
1189
1193
|
if (isPendingPromise(atomState.v)) {
|
|
1190
1194
|
addPendingPromiseToDependency(atom, atomState.v, aState);
|
|
1191
1195
|
}
|
|
1192
|
-
(
|
|
1196
|
+
if (mountedMap.has(atom)) {
|
|
1197
|
+
(_a2 = mountedMap.get(a)) == null ? void 0 : _a2.t.add(atom);
|
|
1198
|
+
}
|
|
1193
1199
|
if (!isSync) {
|
|
1194
1200
|
mountDependenciesIfAsync();
|
|
1195
1201
|
}
|
|
@@ -1205,6 +1211,11 @@ const readAtomState = (store, atom) => {
|
|
|
1205
1211
|
return controller.signal;
|
|
1206
1212
|
},
|
|
1207
1213
|
get setSelf() {
|
|
1214
|
+
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1215
|
+
console.warn(
|
|
1216
|
+
"[DEPRECATED] setSelf is deprecated and will be removed in v3."
|
|
1217
|
+
);
|
|
1218
|
+
}
|
|
1208
1219
|
if ((undefined ? undefined.MODE : void 0) !== "production" && !isActuallyWritableAtom(atom)) {
|
|
1209
1220
|
console.warn("setSelf function cannot be used with read-only atom");
|
|
1210
1221
|
}
|
|
@@ -1215,10 +1226,10 @@ const readAtomState = (store, atom) => {
|
|
|
1215
1226
|
}
|
|
1216
1227
|
if (!isSync) {
|
|
1217
1228
|
try {
|
|
1218
|
-
return
|
|
1229
|
+
return writeAtomState(store, atom, ...args);
|
|
1219
1230
|
} finally {
|
|
1220
|
-
|
|
1221
|
-
|
|
1231
|
+
recomputeInvalidatedAtoms(store);
|
|
1232
|
+
flushCallbacks(store);
|
|
1222
1233
|
}
|
|
1223
1234
|
}
|
|
1224
1235
|
};
|
|
@@ -1228,7 +1239,15 @@ const readAtomState = (store, atom) => {
|
|
|
1228
1239
|
};
|
|
1229
1240
|
const prevEpochNumber = atomState.n;
|
|
1230
1241
|
try {
|
|
1231
|
-
|
|
1242
|
+
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1243
|
+
storeMutationSet.delete(store);
|
|
1244
|
+
}
|
|
1245
|
+
const valueOrPromise = atomRead(store, atom, getter, options);
|
|
1246
|
+
if ((undefined ? undefined.MODE : void 0) !== "production" && storeMutationSet.has(store)) {
|
|
1247
|
+
console.warn(
|
|
1248
|
+
"Detected store mutation during atom read. This is not supported."
|
|
1249
|
+
);
|
|
1250
|
+
}
|
|
1232
1251
|
setAtomStateValueOrPromise(store, atom, valueOrPromise);
|
|
1233
1252
|
if (isPromiseLike$1(valueOrPromise)) {
|
|
1234
1253
|
registerAbortHandler(valueOrPromise, () => controller == null ? void 0 : controller.abort());
|
|
@@ -1250,51 +1269,56 @@ const readAtomState = (store, atom) => {
|
|
|
1250
1269
|
}
|
|
1251
1270
|
}
|
|
1252
1271
|
};
|
|
1253
|
-
const
|
|
1272
|
+
const BUILDING_BLOCK_invalidateDependents = (store, atom) => {
|
|
1254
1273
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1255
1274
|
const mountedMap = buildingBlocks[1];
|
|
1256
1275
|
const invalidatedAtoms = buildingBlocks[2];
|
|
1257
|
-
const
|
|
1276
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1258
1277
|
const stack = [atom];
|
|
1259
1278
|
while (stack.length) {
|
|
1260
1279
|
const a = stack.pop();
|
|
1261
|
-
const aState =
|
|
1280
|
+
const aState = ensureAtomState(store, a);
|
|
1262
1281
|
for (const d of getMountedOrPendingDependents(a, aState, mountedMap)) {
|
|
1263
|
-
const dState =
|
|
1282
|
+
const dState = ensureAtomState(store, d);
|
|
1264
1283
|
invalidatedAtoms.set(d, dState.n);
|
|
1265
1284
|
stack.push(d);
|
|
1266
1285
|
}
|
|
1267
1286
|
}
|
|
1268
1287
|
};
|
|
1269
|
-
const
|
|
1288
|
+
const BUILDING_BLOCK_writeAtomState = (store, atom, ...args) => {
|
|
1270
1289
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1271
1290
|
const changedAtoms = buildingBlocks[3];
|
|
1272
1291
|
const storeHooks = buildingBlocks[6];
|
|
1273
|
-
const
|
|
1274
|
-
const
|
|
1275
|
-
const
|
|
1276
|
-
const
|
|
1277
|
-
const
|
|
1278
|
-
const
|
|
1279
|
-
const
|
|
1292
|
+
const atomWrite = buildingBlocks[8];
|
|
1293
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1294
|
+
const flushCallbacks = buildingBlocks[12];
|
|
1295
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1296
|
+
const readAtomState = buildingBlocks[14];
|
|
1297
|
+
const invalidateDependents = buildingBlocks[15];
|
|
1298
|
+
const writeAtomState = buildingBlocks[16];
|
|
1299
|
+
const mountDependencies = buildingBlocks[17];
|
|
1300
|
+
const setAtomStateValueOrPromise = buildingBlocks[20];
|
|
1280
1301
|
let isSync = true;
|
|
1281
|
-
const getter = (a) => returnAtomValue(
|
|
1302
|
+
const getter = (a) => returnAtomValue(readAtomState(store, a));
|
|
1282
1303
|
const setter = (a, ...args2) => {
|
|
1283
1304
|
var _a;
|
|
1284
|
-
const aState =
|
|
1305
|
+
const aState = ensureAtomState(store, a);
|
|
1285
1306
|
try {
|
|
1286
1307
|
if (a === atom) {
|
|
1287
1308
|
if (!hasInitialValue(a)) {
|
|
1288
1309
|
throw new Error("atom not writable");
|
|
1289
1310
|
}
|
|
1311
|
+
if ((undefined ? undefined.MODE : void 0) !== "production") {
|
|
1312
|
+
storeMutationSet.add(store);
|
|
1313
|
+
}
|
|
1290
1314
|
const prevEpochNumber = aState.n;
|
|
1291
1315
|
const v = args2[0];
|
|
1292
1316
|
setAtomStateValueOrPromise(store, a, v);
|
|
1293
|
-
|
|
1317
|
+
mountDependencies(store, a);
|
|
1294
1318
|
if (prevEpochNumber !== aState.n) {
|
|
1295
1319
|
changedAtoms.add(a);
|
|
1320
|
+
invalidateDependents(store, a);
|
|
1296
1321
|
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
1297
|
-
invalidateDependents2(store, a);
|
|
1298
1322
|
}
|
|
1299
1323
|
return void 0;
|
|
1300
1324
|
} else {
|
|
@@ -1302,68 +1326,69 @@ const writeAtomState = (store, atom, ...args) => {
|
|
|
1302
1326
|
}
|
|
1303
1327
|
} finally {
|
|
1304
1328
|
if (!isSync) {
|
|
1305
|
-
|
|
1306
|
-
|
|
1329
|
+
recomputeInvalidatedAtoms(store);
|
|
1330
|
+
flushCallbacks(store);
|
|
1307
1331
|
}
|
|
1308
1332
|
}
|
|
1309
1333
|
};
|
|
1310
1334
|
try {
|
|
1311
|
-
return
|
|
1335
|
+
return atomWrite(store, atom, getter, setter, ...args);
|
|
1312
1336
|
} finally {
|
|
1313
1337
|
isSync = false;
|
|
1314
1338
|
}
|
|
1315
1339
|
};
|
|
1316
|
-
const
|
|
1340
|
+
const BUILDING_BLOCK_mountDependencies = (store, atom) => {
|
|
1317
1341
|
var _a;
|
|
1318
1342
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1319
1343
|
const mountedMap = buildingBlocks[1];
|
|
1320
1344
|
const changedAtoms = buildingBlocks[3];
|
|
1321
1345
|
const storeHooks = buildingBlocks[6];
|
|
1322
|
-
const
|
|
1323
|
-
const
|
|
1324
|
-
const
|
|
1325
|
-
const
|
|
1326
|
-
const atomState =
|
|
1346
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1347
|
+
const invalidateDependents = buildingBlocks[15];
|
|
1348
|
+
const mountAtom = buildingBlocks[18];
|
|
1349
|
+
const unmountAtom = buildingBlocks[19];
|
|
1350
|
+
const atomState = ensureAtomState(store, atom);
|
|
1327
1351
|
const mounted = mountedMap.get(atom);
|
|
1328
1352
|
if (mounted && !isPendingPromise(atomState.v)) {
|
|
1329
1353
|
for (const [a, n] of atomState.d) {
|
|
1330
1354
|
if (!mounted.d.has(a)) {
|
|
1331
|
-
const aState =
|
|
1332
|
-
const aMounted =
|
|
1355
|
+
const aState = ensureAtomState(store, a);
|
|
1356
|
+
const aMounted = mountAtom(store, a);
|
|
1333
1357
|
aMounted.t.add(atom);
|
|
1334
1358
|
mounted.d.add(a);
|
|
1335
1359
|
if (n !== aState.n) {
|
|
1336
1360
|
changedAtoms.add(a);
|
|
1361
|
+
invalidateDependents(store, a);
|
|
1337
1362
|
(_a = storeHooks.c) == null ? void 0 : _a.call(storeHooks, a);
|
|
1338
|
-
invalidateDependents2(store, a);
|
|
1339
1363
|
}
|
|
1340
1364
|
}
|
|
1341
1365
|
}
|
|
1342
|
-
for (const a of mounted.d
|
|
1366
|
+
for (const a of mounted.d) {
|
|
1343
1367
|
if (!atomState.d.has(a)) {
|
|
1344
1368
|
mounted.d.delete(a);
|
|
1345
|
-
const aMounted =
|
|
1369
|
+
const aMounted = unmountAtom(store, a);
|
|
1346
1370
|
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
1347
1371
|
}
|
|
1348
1372
|
}
|
|
1349
1373
|
}
|
|
1350
1374
|
};
|
|
1351
|
-
const
|
|
1375
|
+
const BUILDING_BLOCK_mountAtom = (store, atom) => {
|
|
1352
1376
|
var _a;
|
|
1353
1377
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1354
1378
|
const mountedMap = buildingBlocks[1];
|
|
1355
1379
|
const mountCallbacks = buildingBlocks[4];
|
|
1356
1380
|
const storeHooks = buildingBlocks[6];
|
|
1357
|
-
const
|
|
1358
|
-
const
|
|
1359
|
-
const
|
|
1360
|
-
const
|
|
1361
|
-
const
|
|
1362
|
-
const
|
|
1363
|
-
const
|
|
1381
|
+
const atomOnMount = buildingBlocks[10];
|
|
1382
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1383
|
+
const flushCallbacks = buildingBlocks[12];
|
|
1384
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1385
|
+
const readAtomState = buildingBlocks[14];
|
|
1386
|
+
const writeAtomState = buildingBlocks[16];
|
|
1387
|
+
const mountAtom = buildingBlocks[18];
|
|
1388
|
+
const atomState = ensureAtomState(store, atom);
|
|
1364
1389
|
let mounted = mountedMap.get(atom);
|
|
1365
1390
|
if (!mounted) {
|
|
1366
|
-
|
|
1391
|
+
readAtomState(store, atom);
|
|
1367
1392
|
for (const a of atomState.d.keys()) {
|
|
1368
1393
|
const aMounted = mountAtom(store, a);
|
|
1369
1394
|
aMounted.t.add(atom);
|
|
@@ -1374,22 +1399,21 @@ const mountAtom = (store, atom) => {
|
|
|
1374
1399
|
t: /* @__PURE__ */ new Set()
|
|
1375
1400
|
};
|
|
1376
1401
|
mountedMap.set(atom, mounted);
|
|
1377
|
-
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1378
1402
|
if (isActuallyWritableAtom(atom)) {
|
|
1379
1403
|
const processOnMount = () => {
|
|
1380
1404
|
let isSync = true;
|
|
1381
1405
|
const setAtom = (...args) => {
|
|
1382
1406
|
try {
|
|
1383
|
-
return
|
|
1407
|
+
return writeAtomState(store, atom, ...args);
|
|
1384
1408
|
} finally {
|
|
1385
1409
|
if (!isSync) {
|
|
1386
|
-
|
|
1387
|
-
|
|
1410
|
+
recomputeInvalidatedAtoms(store);
|
|
1411
|
+
flushCallbacks(store);
|
|
1388
1412
|
}
|
|
1389
1413
|
}
|
|
1390
1414
|
};
|
|
1391
1415
|
try {
|
|
1392
|
-
const onUnmount =
|
|
1416
|
+
const onUnmount = atomOnMount(store, atom, setAtom);
|
|
1393
1417
|
if (onUnmount) {
|
|
1394
1418
|
mounted.u = () => {
|
|
1395
1419
|
isSync = true;
|
|
@@ -1406,40 +1430,48 @@ const mountAtom = (store, atom) => {
|
|
|
1406
1430
|
};
|
|
1407
1431
|
mountCallbacks.add(processOnMount);
|
|
1408
1432
|
}
|
|
1433
|
+
(_a = storeHooks.m) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1409
1434
|
}
|
|
1410
1435
|
return mounted;
|
|
1411
1436
|
};
|
|
1412
|
-
const
|
|
1413
|
-
var _a;
|
|
1437
|
+
const BUILDING_BLOCK_unmountAtom = (store, atom) => {
|
|
1438
|
+
var _a, _b;
|
|
1414
1439
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1415
1440
|
const mountedMap = buildingBlocks[1];
|
|
1416
1441
|
const unmountCallbacks = buildingBlocks[5];
|
|
1417
1442
|
const storeHooks = buildingBlocks[6];
|
|
1418
|
-
const
|
|
1419
|
-
const
|
|
1420
|
-
const atomState =
|
|
1443
|
+
const ensureAtomState = buildingBlocks[11];
|
|
1444
|
+
const unmountAtom = buildingBlocks[19];
|
|
1445
|
+
const atomState = ensureAtomState(store, atom);
|
|
1421
1446
|
let mounted = mountedMap.get(atom);
|
|
1422
|
-
if (mounted
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1447
|
+
if (!mounted || mounted.l.size) {
|
|
1448
|
+
return mounted;
|
|
1449
|
+
}
|
|
1450
|
+
let isDependent = false;
|
|
1451
|
+
for (const a of mounted.t) {
|
|
1452
|
+
if ((_a = mountedMap.get(a)) == null ? void 0 : _a.d.has(atom)) {
|
|
1453
|
+
isDependent = true;
|
|
1454
|
+
break;
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
if (!isDependent) {
|
|
1426
1458
|
if (mounted.u) {
|
|
1427
1459
|
unmountCallbacks.add(mounted.u);
|
|
1428
1460
|
}
|
|
1429
1461
|
mounted = void 0;
|
|
1430
1462
|
mountedMap.delete(atom);
|
|
1431
|
-
(_a = storeHooks.u) == null ? void 0 : _a.call(storeHooks, atom);
|
|
1432
1463
|
for (const a of atomState.d.keys()) {
|
|
1433
|
-
const aMounted =
|
|
1464
|
+
const aMounted = unmountAtom(store, a);
|
|
1434
1465
|
aMounted == null ? void 0 : aMounted.t.delete(atom);
|
|
1435
1466
|
}
|
|
1467
|
+
(_b = storeHooks.u) == null ? void 0 : _b.call(storeHooks, atom);
|
|
1436
1468
|
return void 0;
|
|
1437
1469
|
}
|
|
1438
1470
|
return mounted;
|
|
1439
1471
|
};
|
|
1440
|
-
const
|
|
1441
|
-
const
|
|
1442
|
-
const atomState =
|
|
1472
|
+
const BUILDING_BLOCK_setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
|
|
1473
|
+
const ensureAtomState = getInternalBuildingBlocks(store)[11];
|
|
1474
|
+
const atomState = ensureAtomState(store, atom);
|
|
1443
1475
|
const hasPrevValue = "v" in atomState;
|
|
1444
1476
|
const prevValue = atomState.v;
|
|
1445
1477
|
if (isPromiseLike$1(valueOrPromise)) {
|
|
@@ -1447,7 +1479,7 @@ const setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
|
|
|
1447
1479
|
addPendingPromiseToDependency(
|
|
1448
1480
|
atom,
|
|
1449
1481
|
valueOrPromise,
|
|
1450
|
-
|
|
1482
|
+
ensureAtomState(store, a)
|
|
1451
1483
|
);
|
|
1452
1484
|
}
|
|
1453
1485
|
}
|
|
@@ -1460,35 +1492,35 @@ const setAtomStateValueOrPromise = (store, atom, valueOrPromise) => {
|
|
|
1460
1492
|
}
|
|
1461
1493
|
}
|
|
1462
1494
|
};
|
|
1463
|
-
const
|
|
1464
|
-
const
|
|
1465
|
-
return returnAtomValue(
|
|
1495
|
+
const BUILDING_BLOCK_storeGet = (store, atom) => {
|
|
1496
|
+
const readAtomState = getInternalBuildingBlocks(store)[14];
|
|
1497
|
+
return returnAtomValue(readAtomState(store, atom));
|
|
1466
1498
|
};
|
|
1467
|
-
const
|
|
1499
|
+
const BUILDING_BLOCK_storeSet = (store, atom, ...args) => {
|
|
1468
1500
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1469
|
-
const
|
|
1470
|
-
const
|
|
1471
|
-
const
|
|
1501
|
+
const flushCallbacks = buildingBlocks[12];
|
|
1502
|
+
const recomputeInvalidatedAtoms = buildingBlocks[13];
|
|
1503
|
+
const writeAtomState = buildingBlocks[16];
|
|
1472
1504
|
try {
|
|
1473
|
-
return
|
|
1505
|
+
return writeAtomState(store, atom, ...args);
|
|
1474
1506
|
} finally {
|
|
1475
|
-
|
|
1476
|
-
|
|
1507
|
+
recomputeInvalidatedAtoms(store);
|
|
1508
|
+
flushCallbacks(store);
|
|
1477
1509
|
}
|
|
1478
1510
|
};
|
|
1479
|
-
const
|
|
1511
|
+
const BUILDING_BLOCK_storeSub = (store, atom, listener) => {
|
|
1480
1512
|
const buildingBlocks = getInternalBuildingBlocks(store);
|
|
1481
|
-
const
|
|
1482
|
-
const
|
|
1483
|
-
const
|
|
1484
|
-
const mounted =
|
|
1513
|
+
const flushCallbacks = buildingBlocks[12];
|
|
1514
|
+
const mountAtom = buildingBlocks[18];
|
|
1515
|
+
const unmountAtom = buildingBlocks[19];
|
|
1516
|
+
const mounted = mountAtom(store, atom);
|
|
1485
1517
|
const listeners = mounted.l;
|
|
1486
1518
|
listeners.add(listener);
|
|
1487
|
-
|
|
1519
|
+
flushCallbacks(store);
|
|
1488
1520
|
return () => {
|
|
1489
1521
|
listeners.delete(listener);
|
|
1490
|
-
|
|
1491
|
-
|
|
1522
|
+
unmountAtom(store, atom);
|
|
1523
|
+
flushCallbacks(store);
|
|
1492
1524
|
};
|
|
1493
1525
|
};
|
|
1494
1526
|
const buildingBlockMap = /* @__PURE__ */ new WeakMap();
|
|
@@ -1504,16 +1536,16 @@ const getInternalBuildingBlocks = (store) => {
|
|
|
1504
1536
|
function buildStore(...buildArgs) {
|
|
1505
1537
|
const store = {
|
|
1506
1538
|
get(atom) {
|
|
1507
|
-
const
|
|
1508
|
-
return
|
|
1539
|
+
const storeGet = getInternalBuildingBlocks(store)[21];
|
|
1540
|
+
return storeGet(store, atom);
|
|
1509
1541
|
},
|
|
1510
1542
|
set(atom, ...args) {
|
|
1511
|
-
const
|
|
1512
|
-
return
|
|
1543
|
+
const storeSet = getInternalBuildingBlocks(store)[22];
|
|
1544
|
+
return storeSet(store, atom, ...args);
|
|
1513
1545
|
},
|
|
1514
1546
|
sub(atom, listener) {
|
|
1515
|
-
const
|
|
1516
|
-
return
|
|
1547
|
+
const storeSub = getInternalBuildingBlocks(store)[23];
|
|
1548
|
+
return storeSub(store, atom, listener);
|
|
1517
1549
|
}
|
|
1518
1550
|
};
|
|
1519
1551
|
const buildingBlocks = [
|
|
@@ -1533,24 +1565,24 @@ function buildStore(...buildArgs) {
|
|
|
1533
1565
|
{},
|
|
1534
1566
|
// storeHooks
|
|
1535
1567
|
// atom interceptors
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1568
|
+
BUILDING_BLOCK_atomRead,
|
|
1569
|
+
BUILDING_BLOCK_atomWrite,
|
|
1570
|
+
BUILDING_BLOCK_atomOnInit,
|
|
1571
|
+
BUILDING_BLOCK_atomOnMount,
|
|
1540
1572
|
// building-block functions
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1573
|
+
BUILDING_BLOCK_ensureAtomState,
|
|
1574
|
+
BUILDING_BLOCK_flushCallbacks,
|
|
1575
|
+
BUILDING_BLOCK_recomputeInvalidatedAtoms,
|
|
1576
|
+
BUILDING_BLOCK_readAtomState,
|
|
1577
|
+
BUILDING_BLOCK_invalidateDependents,
|
|
1578
|
+
BUILDING_BLOCK_writeAtomState,
|
|
1579
|
+
BUILDING_BLOCK_mountDependencies,
|
|
1580
|
+
BUILDING_BLOCK_mountAtom,
|
|
1581
|
+
BUILDING_BLOCK_unmountAtom,
|
|
1582
|
+
BUILDING_BLOCK_setAtomStateValueOrPromise,
|
|
1583
|
+
BUILDING_BLOCK_storeGet,
|
|
1584
|
+
BUILDING_BLOCK_storeSet,
|
|
1585
|
+
BUILDING_BLOCK_storeSub,
|
|
1554
1586
|
void 0
|
|
1555
1587
|
].map((fn, i) => buildArgs[i] || fn);
|
|
1556
1588
|
buildingBlockMap.set(store, Object.freeze(buildingBlocks));
|
|
@@ -1748,11 +1780,11 @@ function useAtom(atom, options) {
|
|
|
1748
1780
|
// We do wrong type assertion here, which results in throwing an error.
|
|
1749
1781
|
useSetAtom(atom)
|
|
1750
1782
|
];
|
|
1751
|
-
}const RESET = Symbol(
|
|
1783
|
+
}const RESET = /* @__PURE__ */ Symbol(
|
|
1752
1784
|
(undefined ? undefined.MODE : void 0) !== "production" ? "RESET" : ""
|
|
1753
1785
|
);
|
|
1754
1786
|
|
|
1755
|
-
const isPromiseLike$
|
|
1787
|
+
const isPromiseLike$2 = (x) => typeof (x == null ? void 0 : x.then) === "function";
|
|
1756
1788
|
function createJSONStorage(getStringStorage = () => {
|
|
1757
1789
|
try {
|
|
1758
1790
|
return window.localStorage;
|
|
@@ -1784,7 +1816,7 @@ function createJSONStorage(getStringStorage = () => {
|
|
|
1784
1816
|
return lastValue;
|
|
1785
1817
|
};
|
|
1786
1818
|
const str = (_b = (_a2 = getStringStorage()) == null ? void 0 : _a2.getItem(key)) != null ? _b : null;
|
|
1787
|
-
if (isPromiseLike$
|
|
1819
|
+
if (isPromiseLike$2(str)) {
|
|
1788
1820
|
return str.then(parse);
|
|
1789
1821
|
}
|
|
1790
1822
|
return parse(str);
|
|
@@ -1861,7 +1893,7 @@ function atomWithStorage(key, initialValue, storage = defaultStorage, options) {
|
|
|
1861
1893
|
set(baseAtom, initialValue);
|
|
1862
1894
|
return storage.removeItem(key);
|
|
1863
1895
|
}
|
|
1864
|
-
if (isPromiseLike$
|
|
1896
|
+
if (isPromiseLike$2(nextValue)) {
|
|
1865
1897
|
return nextValue.then((resolvedValue) => {
|
|
1866
1898
|
set(baseAtom, resolvedValue);
|
|
1867
1899
|
return storage.setItem(key, resolvedValue);
|