atom.io 0.15.0 → 0.15.2
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/data/dist/index.cjs +25 -15
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.d.ts +24 -14
- package/data/dist/index.js +25 -15
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +71 -39
- package/dist/{chunk-S7R5MU6A.js → chunk-K22LR3V6.js} +3 -2
- package/dist/chunk-K22LR3V6.js.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +1 -1
- package/internal/dist/index.cjs +113 -93
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +7 -4
- package/internal/dist/index.js +113 -93
- package/internal/dist/index.js.map +1 -1
- package/internal/src/caching.ts +9 -7
- package/internal/src/families/create-readonly-selector-family.ts +3 -1
- package/internal/src/index.ts +5 -0
- package/internal/src/mutable/tracker.ts +35 -17
- package/internal/src/read-or-compute-value.ts +8 -12
- package/internal/src/set-state/copy-mutable-in-transaction.ts +4 -4
- package/internal/src/set-state/set-atom-or-selector.ts +7 -4
- package/internal/src/transaction/apply-transaction.ts +1 -0
- package/package.json +5 -5
- package/react-devtools/dist/index.d.ts +2 -0
- package/realtime-client/dist/index.cjs +3 -0
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +3 -3
- package/realtime-client/dist/index.js +3 -0
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/index.ts +6 -6
- package/realtime-client/src/{use-pull-family-member.ts → pull-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable-family-member.ts → pull-mutable-family-member.ts} +1 -1
- package/realtime-client/src/{use-pull-mutable.ts → pull-mutable.ts} +1 -1
- package/realtime-client/src/{use-server-action.ts → server-action.ts} +3 -0
- package/realtime-react/dist/index.cjs +31 -17
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +4 -4
- package/realtime-react/dist/index.js +31 -17
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/realtime-context.tsx +2 -3
- package/realtime-react/src/use-pull-family-member.ts +6 -2
- package/realtime-react/src/use-pull-mutable-family-member.ts +6 -5
- package/realtime-react/src/use-pull-mutable.ts +6 -2
- package/realtime-react/src/use-pull.ts +5 -1
- package/realtime-react/src/use-push.ts +5 -4
- package/realtime-react/src/use-server-action.ts +5 -4
- package/src/index.ts +5 -0
- package/src/set-state.ts +3 -1
- package/transceivers/set-rtx/dist/index.cjs +8 -5
- package/transceivers/set-rtx/dist/index.cjs.map +1 -1
- package/transceivers/set-rtx/dist/index.js +8 -5
- package/transceivers/set-rtx/dist/index.js.map +1 -1
- package/transceivers/set-rtx/src/set-rtx.ts +8 -5
- package/dist/chunk-S7R5MU6A.js.map +0 -1
- /package/realtime-client/src/{use-pull.ts → pull.ts} +0 -0
- /package/realtime-client/src/{use-push.ts → push.ts} +0 -0
package/internal/dist/index.cjs
CHANGED
|
@@ -77,6 +77,55 @@ var Future = class extends Promise {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
+
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
81
|
+
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
82
|
+
const originValue = origin.valueMap.get(atom.key);
|
|
83
|
+
const targetValue = target.valueMap.get(atom.key);
|
|
84
|
+
if (originValue === targetValue) {
|
|
85
|
+
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
86
|
+
const jsonValue = transform.toJson(originValue);
|
|
87
|
+
const copiedValue = transform.fromJson(jsonValue);
|
|
88
|
+
target.valueMap.set(atom.key, copiedValue);
|
|
89
|
+
new Tracker(atom, origin);
|
|
90
|
+
return copiedValue;
|
|
91
|
+
}
|
|
92
|
+
return targetValue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
96
|
+
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
97
|
+
const target = newest(store);
|
|
98
|
+
const parent = target.parent;
|
|
99
|
+
if (parent !== null) {
|
|
100
|
+
if (`family` in atom) {
|
|
101
|
+
const family = parent.families.get(atom.family.key);
|
|
102
|
+
if (family && family.type === `atom_family`) {
|
|
103
|
+
const result = copyMutableFamilyMemberWithinTransaction(
|
|
104
|
+
atom,
|
|
105
|
+
family,
|
|
106
|
+
parent,
|
|
107
|
+
target
|
|
108
|
+
);
|
|
109
|
+
if (result) {
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (`toJson` in atom && `fromJson` in atom) {
|
|
115
|
+
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
116
|
+
return copiedValue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return oldValue;
|
|
120
|
+
}
|
|
121
|
+
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
122
|
+
if (`toJson` in family && `fromJson` in family) {
|
|
123
|
+
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
124
|
+
return copyCreated;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
80
129
|
// internal/src/caching.ts
|
|
81
130
|
function cacheValue(key, value, subject, target) {
|
|
82
131
|
const currentValue = target.valueMap.get(key);
|
|
@@ -102,11 +151,12 @@ function cacheValue(key, value, subject, target) {
|
|
|
102
151
|
target.valueMap.set(key, value);
|
|
103
152
|
return value;
|
|
104
153
|
}
|
|
105
|
-
var readCachedValue = (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
154
|
+
var readCachedValue = (token, target) => {
|
|
155
|
+
let value = target.valueMap.get(token.key);
|
|
156
|
+
if (token.type === `atom`) {
|
|
157
|
+
value = copyMutableIfWithinTransaction(value, token, target);
|
|
158
|
+
}
|
|
159
|
+
return value;
|
|
110
160
|
};
|
|
111
161
|
var evictCachedValue = (key, target) => {
|
|
112
162
|
const currentValue = target.valueMap.get(key);
|
|
@@ -121,17 +171,17 @@ var evictCachedValue = (key, target) => {
|
|
|
121
171
|
};
|
|
122
172
|
|
|
123
173
|
// internal/src/read-or-compute-value.ts
|
|
124
|
-
var readOrComputeValue = (state,
|
|
125
|
-
if (
|
|
126
|
-
|
|
127
|
-
return readCachedValue(state
|
|
174
|
+
var readOrComputeValue = (state, target) => {
|
|
175
|
+
if (target.valueMap.has(state.key)) {
|
|
176
|
+
target.logger.info(`\u{1F4D6}`, state.type, state.key, `reading cached value`);
|
|
177
|
+
return readCachedValue(state, target);
|
|
128
178
|
}
|
|
129
179
|
if (state.type !== `atom`) {
|
|
130
|
-
|
|
180
|
+
target.logger.info(`\u{1F9EE}`, state.type, state.key, `computing value`);
|
|
131
181
|
return state.get();
|
|
132
182
|
}
|
|
133
183
|
const fallback = state.default instanceof Function ? state.default() : state.default;
|
|
134
|
-
|
|
184
|
+
target.logger.info(
|
|
135
185
|
`\u{1F481}`,
|
|
136
186
|
`atom`,
|
|
137
187
|
state.key,
|
|
@@ -239,55 +289,6 @@ var StatefulSubject = class extends Subject {
|
|
|
239
289
|
}
|
|
240
290
|
};
|
|
241
291
|
|
|
242
|
-
// internal/src/set-state/copy-mutable-if-needed.ts
|
|
243
|
-
function copyMutableIfNeeded(atom, transform, origin, target) {
|
|
244
|
-
const originValue = origin.valueMap.get(atom.key);
|
|
245
|
-
const targetValue = target.valueMap.get(atom.key);
|
|
246
|
-
if (originValue === targetValue) {
|
|
247
|
-
origin.logger.info(`\u{1F4C3}`, `atom`, `${atom.key}`, `copying`);
|
|
248
|
-
const jsonValue = transform.toJson(originValue);
|
|
249
|
-
const copiedValue = transform.fromJson(jsonValue);
|
|
250
|
-
target.valueMap.set(atom.key, copiedValue);
|
|
251
|
-
new Tracker(atom, origin);
|
|
252
|
-
return copiedValue;
|
|
253
|
-
}
|
|
254
|
-
return targetValue;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// internal/src/set-state/copy-mutable-in-transaction.ts
|
|
258
|
-
function copyMutableIfWithinTransaction(oldValue, atom, store) {
|
|
259
|
-
const target = newest(store);
|
|
260
|
-
const parent = target.parent;
|
|
261
|
-
if (parent !== null) {
|
|
262
|
-
if (`toJson` in atom && `fromJson` in atom) {
|
|
263
|
-
const copiedValue = copyMutableIfNeeded(atom, atom, parent, target);
|
|
264
|
-
return copiedValue;
|
|
265
|
-
}
|
|
266
|
-
if (`family` in atom) {
|
|
267
|
-
const family = parent.families.get(atom.family.key);
|
|
268
|
-
if (family && family.type === `atom_family`) {
|
|
269
|
-
const result = copyMutableFamilyMemberWithinTransaction(
|
|
270
|
-
atom,
|
|
271
|
-
family,
|
|
272
|
-
parent,
|
|
273
|
-
target
|
|
274
|
-
);
|
|
275
|
-
if (result) {
|
|
276
|
-
return result;
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
return oldValue;
|
|
282
|
-
}
|
|
283
|
-
function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target) {
|
|
284
|
-
if (`toJson` in family && `fromJson` in family) {
|
|
285
|
-
const copyCreated = copyMutableIfNeeded(atom, family, origin, target);
|
|
286
|
-
return copyCreated;
|
|
287
|
-
}
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
292
|
// internal/src/set-state/emit-update.ts
|
|
292
293
|
var emitUpdate = (state, update, store) => {
|
|
293
294
|
store.logger.info(
|
|
@@ -400,10 +401,13 @@ var setAtom = (atom, next, target) => {
|
|
|
400
401
|
|
|
401
402
|
// internal/src/set-state/set-atom-or-selector.ts
|
|
402
403
|
var setAtomOrSelector = (state, value, store) => {
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
404
|
+
switch (state.type) {
|
|
405
|
+
case `atom`:
|
|
406
|
+
setAtom(state, value, store);
|
|
407
|
+
break;
|
|
408
|
+
case `selector`:
|
|
409
|
+
state.set(value);
|
|
410
|
+
break;
|
|
407
411
|
}
|
|
408
412
|
};
|
|
409
413
|
|
|
@@ -1224,15 +1228,6 @@ var subscribeToTransaction = (token, handleUpdate, key, store) => {
|
|
|
1224
1228
|
};
|
|
1225
1229
|
};
|
|
1226
1230
|
var Tracker = class {
|
|
1227
|
-
constructor(mutableState, store) {
|
|
1228
|
-
this.unsubscribeFromInnerValue = null;
|
|
1229
|
-
this.mutableState = mutableState;
|
|
1230
|
-
const target = newest(store);
|
|
1231
|
-
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
1232
|
-
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
1233
|
-
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
1234
|
-
target.trackers.set(mutableState.key, this);
|
|
1235
|
-
}
|
|
1236
1231
|
initializeState(mutableState, store) {
|
|
1237
1232
|
var _a;
|
|
1238
1233
|
const latestUpdateStateKey = `*${mutableState.key}`;
|
|
@@ -1262,32 +1257,41 @@ var Tracker = class {
|
|
|
1262
1257
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
1263
1258
|
`tracker:${store.config.name}:${target.transactionMeta === null ? `main` : target.transactionMeta.update.key}`,
|
|
1264
1259
|
(update) => {
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1260
|
+
if (target.operation.open) {
|
|
1261
|
+
const unsubscribe = target.subject.operationStatus.subscribe(
|
|
1262
|
+
mutableState.key,
|
|
1263
|
+
() => {
|
|
1264
|
+
unsubscribe();
|
|
1265
|
+
atom_io.setState(latestUpdateState, update, target);
|
|
1266
|
+
}
|
|
1267
|
+
);
|
|
1268
|
+
} else {
|
|
1269
|
+
atom_io.setState(mutableState, (current) => current, target);
|
|
1270
|
+
atom_io.setState(latestUpdateState, update, target);
|
|
1271
|
+
}
|
|
1272
1272
|
}
|
|
1273
1273
|
);
|
|
1274
|
-
subscribeToState(
|
|
1274
|
+
this.unsubscribeFromState = subscribeToState(
|
|
1275
1275
|
mutableState,
|
|
1276
1276
|
(update) => {
|
|
1277
|
-
var _a;
|
|
1278
1277
|
if (update.newValue !== update.oldValue) {
|
|
1279
|
-
|
|
1278
|
+
this.unsubscribeFromInnerValue();
|
|
1280
1279
|
const target2 = newest(store);
|
|
1281
1280
|
this.unsubscribeFromInnerValue = update.newValue.subscribe(
|
|
1282
1281
|
`tracker:${store.config.name}:${target2.transactionMeta === null ? `main` : target2.transactionMeta.update.key}`,
|
|
1283
1282
|
(update2) => {
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1283
|
+
if (target2.operation.open) {
|
|
1284
|
+
const unsubscribe = target2.subject.operationStatus.subscribe(
|
|
1285
|
+
mutableState.key,
|
|
1286
|
+
() => {
|
|
1287
|
+
unsubscribe();
|
|
1288
|
+
atom_io.setState(latestUpdateState, update2, target2);
|
|
1289
|
+
}
|
|
1290
|
+
);
|
|
1291
|
+
} else {
|
|
1292
|
+
atom_io.setState(mutableState, (current) => current, target2);
|
|
1293
|
+
atom_io.setState(latestUpdateState, update2, target2);
|
|
1294
|
+
}
|
|
1291
1295
|
}
|
|
1292
1296
|
);
|
|
1293
1297
|
}
|
|
@@ -1350,6 +1354,19 @@ var Tracker = class {
|
|
|
1350
1354
|
store
|
|
1351
1355
|
);
|
|
1352
1356
|
}
|
|
1357
|
+
constructor(mutableState, store) {
|
|
1358
|
+
this.mutableState = mutableState;
|
|
1359
|
+
const target = newest(store);
|
|
1360
|
+
this.latestUpdateState = this.initializeState(mutableState, target);
|
|
1361
|
+
this.observeCore(mutableState, this.latestUpdateState, target);
|
|
1362
|
+
this.updateCore(mutableState, this.latestUpdateState, target);
|
|
1363
|
+
target.trackers.set(mutableState.key, this);
|
|
1364
|
+
this.dispose = () => {
|
|
1365
|
+
this.unsubscribeFromInnerValue();
|
|
1366
|
+
this.unsubscribeFromState();
|
|
1367
|
+
target.trackers.delete(mutableState.key);
|
|
1368
|
+
};
|
|
1369
|
+
}
|
|
1353
1370
|
};
|
|
1354
1371
|
|
|
1355
1372
|
// internal/src/mutable/create-mutable-atom.ts
|
|
@@ -1434,7 +1451,7 @@ function createAtomFamily(options, store) {
|
|
|
1434
1451
|
}
|
|
1435
1452
|
function createReadonlySelectorFamily(options, store) {
|
|
1436
1453
|
const subject = new Subject();
|
|
1437
|
-
|
|
1454
|
+
const readonlySelectorFamily = Object.assign(
|
|
1438
1455
|
(key) => {
|
|
1439
1456
|
const target = newest(store);
|
|
1440
1457
|
const subKey = json.stringifyJson(key);
|
|
@@ -1460,6 +1477,8 @@ function createReadonlySelectorFamily(options, store) {
|
|
|
1460
1477
|
install: (store2) => createReadonlySelectorFamily(options, store2)
|
|
1461
1478
|
}
|
|
1462
1479
|
);
|
|
1480
|
+
store.families.set(options.key, readonlySelectorFamily);
|
|
1481
|
+
return readonlySelectorFamily;
|
|
1463
1482
|
}
|
|
1464
1483
|
function createSelectorFamily(options, store) {
|
|
1465
1484
|
const isReadonly = !(`set` in options);
|
|
@@ -2235,6 +2254,7 @@ var applyTransaction = (output, store) => {
|
|
|
2235
2254
|
const atom = child.atoms.get(mutableKey);
|
|
2236
2255
|
atom == null ? void 0 : atom.install(parent);
|
|
2237
2256
|
}
|
|
2257
|
+
tracker.dispose();
|
|
2238
2258
|
}
|
|
2239
2259
|
for (const atom of child.atoms.values()) {
|
|
2240
2260
|
if (!parent.atoms.has(atom.key)) {
|
|
@@ -2275,11 +2295,12 @@ function getState2(token, store = Internal2__namespace.IMPLICIT.STORE) {
|
|
|
2275
2295
|
return Internal2__namespace.readOrComputeValue(state, store);
|
|
2276
2296
|
}
|
|
2277
2297
|
function setState5(token, value, store = Internal2__namespace.IMPLICIT.STORE) {
|
|
2298
|
+
var _a;
|
|
2278
2299
|
const rejection = Internal2__namespace.openOperation(token, store);
|
|
2279
2300
|
if (rejection) {
|
|
2280
2301
|
return;
|
|
2281
2302
|
}
|
|
2282
|
-
const state = Internal2__namespace.withdraw(token, store);
|
|
2303
|
+
const state = (_a = Internal2__namespace.withdraw(token, store)) != null ? _a : Internal2__namespace.withdrawNewFamilyMember(token, store);
|
|
2283
2304
|
if (state === void 0) {
|
|
2284
2305
|
throw new Internal2__namespace.NotFoundError(token, store);
|
|
2285
2306
|
}
|
|
@@ -2426,7 +2447,6 @@ exports.isReadonlySelectorKey = isReadonlySelectorKey;
|
|
|
2426
2447
|
exports.isSelectorKey = isSelectorKey;
|
|
2427
2448
|
exports.isStateKey = isStateKey;
|
|
2428
2449
|
exports.isTransceiver = isTransceiver;
|
|
2429
|
-
exports.isValueCached = isValueCached;
|
|
2430
2450
|
exports.markAtomAsDefault = markAtomAsDefault;
|
|
2431
2451
|
exports.markAtomAsNotDefault = markAtomAsNotDefault;
|
|
2432
2452
|
exports.markDone = markDone;
|