atom.io 0.9.9 → 0.9.10
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/internal/dist/index.d.mts +23 -7
- package/internal/dist/index.d.ts +23 -7
- package/internal/dist/index.js +223 -228
- package/internal/dist/index.js.map +1 -1
- package/internal/dist/index.mjs +219 -227
- package/internal/dist/index.mjs.map +1 -1
- package/internal/src/atom/is-default.ts +2 -2
- package/internal/src/caching.ts +6 -4
- package/internal/src/index.ts +1 -0
- package/internal/src/keys.ts +30 -0
- package/internal/src/selector/get-selector-dependency-keys.ts +20 -0
- package/internal/src/selector/index.ts +1 -1
- package/internal/src/selector/trace-selector-atoms.ts +26 -26
- package/internal/src/selector/update-selector-atoms.ts +4 -4
- package/internal/src/store/index.ts +0 -1
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +4 -5
- package/package.json +2 -2
- package/internal/src/selector/lookup-selector-sources.ts +0 -20
- package/internal/src/store/lookup.ts +0 -26
package/internal/dist/index.mjs
CHANGED
|
@@ -52,94 +52,6 @@ function deposit(state) {
|
|
|
52
52
|
return token;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
// src/subject.ts
|
|
56
|
-
var Subject = class {
|
|
57
|
-
constructor() {
|
|
58
|
-
this.subscribers = /* @__PURE__ */ new Map();
|
|
59
|
-
}
|
|
60
|
-
subscribe(key, subscriber) {
|
|
61
|
-
this.subscribers.set(key, subscriber);
|
|
62
|
-
const unsubscribe = () => this.unsubscribe(key);
|
|
63
|
-
return unsubscribe;
|
|
64
|
-
}
|
|
65
|
-
unsubscribe(key) {
|
|
66
|
-
this.subscribers.delete(key);
|
|
67
|
-
}
|
|
68
|
-
next(value) {
|
|
69
|
-
for (const subscriber of this.subscribers.values()) {
|
|
70
|
-
subscriber(value);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
// src/transaction/abort-transaction.ts
|
|
76
|
-
var abortTransaction = (store) => {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
if (store.transactionStatus.phase === `idle`) {
|
|
79
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
80
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
81
|
-
);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
store.transactionStatus = { phase: `idle` };
|
|
85
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
86
|
-
};
|
|
87
|
-
var applyTransaction = (output, store) => {
|
|
88
|
-
var _a, _b, _c, _d, _e;
|
|
89
|
-
if (store.transactionStatus.phase !== `building`) {
|
|
90
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
91
|
-
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
92
|
-
);
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
store.transactionStatus.phase = `applying`;
|
|
96
|
-
store.transactionStatus.output = output;
|
|
97
|
-
const { atomUpdates } = store.transactionStatus;
|
|
98
|
-
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
99
|
-
`\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
|
|
100
|
-
);
|
|
101
|
-
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
102
|
-
for (const { key, newValue } of atomUpdates) {
|
|
103
|
-
const token = { key, type: `atom` };
|
|
104
|
-
if (!store.valueMap.has(token.key)) {
|
|
105
|
-
if (token.family) {
|
|
106
|
-
const family = store.families.get(token.family.key);
|
|
107
|
-
if (family) {
|
|
108
|
-
family(token.family.subKey);
|
|
109
|
-
}
|
|
110
|
-
} else {
|
|
111
|
-
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
112
|
-
if (!newAtom) {
|
|
113
|
-
throw new Error(
|
|
114
|
-
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
115
|
-
);
|
|
116
|
-
}
|
|
117
|
-
store.atoms.set(newAtom.key, newAtom);
|
|
118
|
-
store.valueMap.set(newAtom.key, newAtom.default);
|
|
119
|
-
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
setState(token, newValue, store);
|
|
123
|
-
}
|
|
124
|
-
const myTransaction = withdraw(
|
|
125
|
-
{ key: store.transactionStatus.key, type: `transaction` },
|
|
126
|
-
store
|
|
127
|
-
);
|
|
128
|
-
if (myTransaction === void 0) {
|
|
129
|
-
throw new Error(
|
|
130
|
-
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
myTransaction.subject.next({
|
|
134
|
-
key: store.transactionStatus.key,
|
|
135
|
-
atomUpdates,
|
|
136
|
-
output,
|
|
137
|
-
params: store.transactionStatus.params
|
|
138
|
-
});
|
|
139
|
-
store.transactionStatus = { phase: `idle` };
|
|
140
|
-
(_e = store.config.logger) == null ? void 0 : _e.info(`\u{1F6EC}`, `transaction "${myTransaction.key}" applied`);
|
|
141
|
-
};
|
|
142
|
-
|
|
143
55
|
// ../../rel8/junction/src/junction.ts
|
|
144
56
|
var Junction = class {
|
|
145
57
|
constructor(data, config) {
|
|
@@ -338,6 +250,180 @@ var Junction = class {
|
|
|
338
250
|
}
|
|
339
251
|
};
|
|
340
252
|
|
|
253
|
+
// src/subject.ts
|
|
254
|
+
var Subject = class {
|
|
255
|
+
constructor() {
|
|
256
|
+
this.subscribers = /* @__PURE__ */ new Map();
|
|
257
|
+
}
|
|
258
|
+
subscribe(key, subscriber) {
|
|
259
|
+
this.subscribers.set(key, subscriber);
|
|
260
|
+
const unsubscribe = () => this.unsubscribe(key);
|
|
261
|
+
return unsubscribe;
|
|
262
|
+
}
|
|
263
|
+
unsubscribe(key) {
|
|
264
|
+
this.subscribers.delete(key);
|
|
265
|
+
}
|
|
266
|
+
next(value) {
|
|
267
|
+
for (const subscriber of this.subscribers.values()) {
|
|
268
|
+
subscriber(value);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// src/store/store.ts
|
|
274
|
+
var Store = class {
|
|
275
|
+
constructor(name, store = null) {
|
|
276
|
+
this.valueMap = /* @__PURE__ */ new Map();
|
|
277
|
+
this.atoms = /* @__PURE__ */ new Map();
|
|
278
|
+
this.selectors = /* @__PURE__ */ new Map();
|
|
279
|
+
this.readonlySelectors = /* @__PURE__ */ new Map();
|
|
280
|
+
this.trackers = /* @__PURE__ */ new Map();
|
|
281
|
+
this.families = /* @__PURE__ */ new Map();
|
|
282
|
+
this.timelines = /* @__PURE__ */ new Map();
|
|
283
|
+
this.transactions = /* @__PURE__ */ new Map();
|
|
284
|
+
this.atomsThatAreDefault = /* @__PURE__ */ new Set();
|
|
285
|
+
this.timelineAtoms = new Junction({
|
|
286
|
+
between: [`timelineKey`, `atomKey`],
|
|
287
|
+
cardinality: `1:n`
|
|
288
|
+
});
|
|
289
|
+
this.selectorAtoms = new Junction({
|
|
290
|
+
between: [`selectorKey`, `atomKey`],
|
|
291
|
+
cardinality: `n:n`
|
|
292
|
+
});
|
|
293
|
+
this.selectorGraph = new Junction(
|
|
294
|
+
{
|
|
295
|
+
between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
|
|
296
|
+
cardinality: `n:n`
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
this.subject = {
|
|
303
|
+
atomCreation: new Subject(),
|
|
304
|
+
selectorCreation: new Subject(),
|
|
305
|
+
transactionCreation: new Subject(),
|
|
306
|
+
timelineCreation: new Subject(),
|
|
307
|
+
operationStatus: new Subject()
|
|
308
|
+
};
|
|
309
|
+
this.operation = { open: false };
|
|
310
|
+
this.transactionStatus = { phase: `idle` };
|
|
311
|
+
this.config = {
|
|
312
|
+
name: `IMPLICIT_STORE`,
|
|
313
|
+
logger: __spreadProps(__spreadValues({}, console), { info: () => void 0 }),
|
|
314
|
+
logger__INTERNAL: console
|
|
315
|
+
};
|
|
316
|
+
var _a;
|
|
317
|
+
if (store !== null) {
|
|
318
|
+
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
319
|
+
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
320
|
+
this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
|
|
321
|
+
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
322
|
+
logger__INTERNAL: console,
|
|
323
|
+
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
324
|
+
info: () => void 0
|
|
325
|
+
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
326
|
+
name
|
|
327
|
+
});
|
|
328
|
+
for (const [, atom] of store.atoms) {
|
|
329
|
+
atom.install(this);
|
|
330
|
+
}
|
|
331
|
+
for (const [, selector] of store.readonlySelectors) {
|
|
332
|
+
selector.install(this);
|
|
333
|
+
}
|
|
334
|
+
for (const [, selector] of store.selectors) {
|
|
335
|
+
selector.install(this);
|
|
336
|
+
}
|
|
337
|
+
for (const [, tx] of store.transactions) {
|
|
338
|
+
tx.install(this);
|
|
339
|
+
}
|
|
340
|
+
for (const [, timeline] of store.timelines) {
|
|
341
|
+
timeline.install(this);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
var IMPLICIT = {
|
|
347
|
+
STORE_INTERNAL: void 0,
|
|
348
|
+
get STORE() {
|
|
349
|
+
var _a;
|
|
350
|
+
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
var clearStore = (store = IMPLICIT.STORE) => {
|
|
354
|
+
const { config } = store;
|
|
355
|
+
Object.assign(store, new Store(config.name));
|
|
356
|
+
store.config = config;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/transaction/abort-transaction.ts
|
|
360
|
+
var abortTransaction = (store) => {
|
|
361
|
+
var _a, _b;
|
|
362
|
+
if (store.transactionStatus.phase === `idle`) {
|
|
363
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
364
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
365
|
+
);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
store.transactionStatus = { phase: `idle` };
|
|
369
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(`\u{1FA82}`, `transaction fail`);
|
|
370
|
+
};
|
|
371
|
+
var applyTransaction = (output, store) => {
|
|
372
|
+
var _a, _b, _c, _d, _e;
|
|
373
|
+
if (store.transactionStatus.phase !== `building`) {
|
|
374
|
+
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
375
|
+
`abortTransaction called outside of a transaction. This is probably a bug.`
|
|
376
|
+
);
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
store.transactionStatus.phase = `applying`;
|
|
380
|
+
store.transactionStatus.output = output;
|
|
381
|
+
const { atomUpdates } = store.transactionStatus;
|
|
382
|
+
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
383
|
+
`\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
|
|
384
|
+
);
|
|
385
|
+
(_c = store.config.logger) == null ? void 0 : _c.info(`\u{1F6C3} the updates are:`, atomUpdates);
|
|
386
|
+
for (const { key, newValue } of atomUpdates) {
|
|
387
|
+
const token = { key, type: `atom` };
|
|
388
|
+
if (!store.valueMap.has(token.key)) {
|
|
389
|
+
if (token.family) {
|
|
390
|
+
const family = store.families.get(token.family.key);
|
|
391
|
+
if (family) {
|
|
392
|
+
family(token.family.subKey);
|
|
393
|
+
}
|
|
394
|
+
} else {
|
|
395
|
+
const newAtom = store.transactionStatus.core.atoms.get(token.key);
|
|
396
|
+
if (!newAtom) {
|
|
397
|
+
throw new Error(
|
|
398
|
+
`Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
store.atoms.set(newAtom.key, newAtom);
|
|
402
|
+
store.valueMap.set(newAtom.key, newAtom.default);
|
|
403
|
+
(_d = store.config.logger) == null ? void 0 : _d.info(`\u{1F527}`, `add atom "${newAtom.key}"`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
setState(token, newValue, store);
|
|
407
|
+
}
|
|
408
|
+
const myTransaction = withdraw(
|
|
409
|
+
{ key: store.transactionStatus.key, type: `transaction` },
|
|
410
|
+
store
|
|
411
|
+
);
|
|
412
|
+
if (myTransaction === void 0) {
|
|
413
|
+
throw new Error(
|
|
414
|
+
`Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
|
|
415
|
+
);
|
|
416
|
+
}
|
|
417
|
+
myTransaction.subject.next({
|
|
418
|
+
key: store.transactionStatus.key,
|
|
419
|
+
atomUpdates,
|
|
420
|
+
output,
|
|
421
|
+
params: store.transactionStatus.params
|
|
422
|
+
});
|
|
423
|
+
store.transactionStatus = { phase: `idle` };
|
|
424
|
+
(_e = store.config.logger) == null ? void 0 : _e.info(`\u{1F6EC}`, `transaction "${myTransaction.key}" applied`);
|
|
425
|
+
};
|
|
426
|
+
|
|
341
427
|
// src/transaction/build-transaction.ts
|
|
342
428
|
var buildTransaction = (key, params, store) => {
|
|
343
429
|
var _a;
|
|
@@ -441,107 +527,6 @@ var undoTransactionUpdate = (update, store) => {
|
|
|
441
527
|
// src/transaction/index.ts
|
|
442
528
|
var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
|
|
443
529
|
|
|
444
|
-
// src/store/lookup.ts
|
|
445
|
-
function lookup(key, store) {
|
|
446
|
-
var _a;
|
|
447
|
-
const core = target(store);
|
|
448
|
-
let type = core.atoms.has(key) ? `atom` : core.selectors.has(key) ? `selector` : core.readonlySelectors.has(key) ? `readonly_selector` : ``;
|
|
449
|
-
if (!type) {
|
|
450
|
-
const errorId = Math.random().toString(36);
|
|
451
|
-
type = `\u{1F6A8} This state could not be found by lookup! Check the console for "${errorId}"`;
|
|
452
|
-
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
453
|
-
`${errorId}: Key "${key}" does not exist in the store.`
|
|
454
|
-
);
|
|
455
|
-
}
|
|
456
|
-
return { key, type };
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
// src/store/store.ts
|
|
460
|
-
var Store = class {
|
|
461
|
-
constructor(name, store = null) {
|
|
462
|
-
this.valueMap = /* @__PURE__ */ new Map();
|
|
463
|
-
this.atoms = /* @__PURE__ */ new Map();
|
|
464
|
-
this.selectors = /* @__PURE__ */ new Map();
|
|
465
|
-
this.readonlySelectors = /* @__PURE__ */ new Map();
|
|
466
|
-
this.trackers = /* @__PURE__ */ new Map();
|
|
467
|
-
this.families = /* @__PURE__ */ new Map();
|
|
468
|
-
this.timelines = /* @__PURE__ */ new Map();
|
|
469
|
-
this.transactions = /* @__PURE__ */ new Map();
|
|
470
|
-
this.atomsThatAreDefault = /* @__PURE__ */ new Set();
|
|
471
|
-
this.timelineAtoms = new Junction({
|
|
472
|
-
between: [`timelineKey`, `atomKey`],
|
|
473
|
-
cardinality: `1:n`
|
|
474
|
-
});
|
|
475
|
-
this.selectorAtoms = new Junction({
|
|
476
|
-
between: [`selectorKey`, `atomKey`],
|
|
477
|
-
cardinality: `n:n`
|
|
478
|
-
});
|
|
479
|
-
this.selectorGraph = new Junction(
|
|
480
|
-
{
|
|
481
|
-
between: [`upstreamSelectorKey`, `downstreamSelectorKey`],
|
|
482
|
-
cardinality: `n:n`
|
|
483
|
-
},
|
|
484
|
-
{
|
|
485
|
-
makeContentKey: (...keys) => keys.sort().join(`:`)
|
|
486
|
-
}
|
|
487
|
-
);
|
|
488
|
-
this.subject = {
|
|
489
|
-
atomCreation: new Subject(),
|
|
490
|
-
selectorCreation: new Subject(),
|
|
491
|
-
transactionCreation: new Subject(),
|
|
492
|
-
timelineCreation: new Subject(),
|
|
493
|
-
operationStatus: new Subject()
|
|
494
|
-
};
|
|
495
|
-
this.operation = { open: false };
|
|
496
|
-
this.transactionStatus = { phase: `idle` };
|
|
497
|
-
this.config = {
|
|
498
|
-
name: `IMPLICIT_STORE`,
|
|
499
|
-
logger: __spreadProps(__spreadValues({}, console), { info: () => void 0 }),
|
|
500
|
-
logger__INTERNAL: console
|
|
501
|
-
};
|
|
502
|
-
var _a;
|
|
503
|
-
if (store !== null) {
|
|
504
|
-
this.valueMap = new Map(store == null ? void 0 : store.valueMap);
|
|
505
|
-
this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
|
|
506
|
-
this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
|
|
507
|
-
this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
|
|
508
|
-
logger__INTERNAL: console,
|
|
509
|
-
logger: __spreadValues(__spreadProps(__spreadValues({}, console), {
|
|
510
|
-
info: () => void 0
|
|
511
|
-
}), (_a = store == null ? void 0 : store.config) == null ? void 0 : _a.logger),
|
|
512
|
-
name
|
|
513
|
-
});
|
|
514
|
-
for (const [, atom] of store.atoms) {
|
|
515
|
-
atom.install(this);
|
|
516
|
-
}
|
|
517
|
-
for (const [, selector] of store.readonlySelectors) {
|
|
518
|
-
selector.install(this);
|
|
519
|
-
}
|
|
520
|
-
for (const [, selector] of store.selectors) {
|
|
521
|
-
selector.install(this);
|
|
522
|
-
}
|
|
523
|
-
for (const [, tx] of store.transactions) {
|
|
524
|
-
tx.install(this);
|
|
525
|
-
}
|
|
526
|
-
for (const [, timeline] of store.timelines) {
|
|
527
|
-
timeline.install(this);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
var IMPLICIT = {
|
|
533
|
-
STORE_INTERNAL: void 0,
|
|
534
|
-
get STORE() {
|
|
535
|
-
var _a;
|
|
536
|
-
return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
|
|
537
|
-
}
|
|
538
|
-
};
|
|
539
|
-
var clearStore = (store = IMPLICIT.STORE) => {
|
|
540
|
-
const { config } = store;
|
|
541
|
-
Object.assign(store, new Store(config.name));
|
|
542
|
-
store.config = config;
|
|
543
|
-
};
|
|
544
|
-
|
|
545
530
|
// src/timeline/add-atom-to-timeline.ts
|
|
546
531
|
var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
|
|
547
532
|
const atom = withdraw(atomToken, store);
|
|
@@ -934,10 +919,12 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
|
|
|
934
919
|
subject.next({ newValue: value2, oldValue: value2 });
|
|
935
920
|
}).catch((error) => {
|
|
936
921
|
var _a;
|
|
937
|
-
(
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
922
|
+
if (error !== `canceled`) {
|
|
923
|
+
(_a = store.config.logger) == null ? void 0 : _a.error(
|
|
924
|
+
`Promised value for "${key}" rejected:`,
|
|
925
|
+
error
|
|
926
|
+
);
|
|
927
|
+
}
|
|
941
928
|
});
|
|
942
929
|
} else {
|
|
943
930
|
target(store).valueMap.set(key, value);
|
|
@@ -1132,9 +1119,15 @@ function createAtomFamily(options, store = IMPLICIT.STORE) {
|
|
|
1132
1119
|
return atomFamily;
|
|
1133
1120
|
}
|
|
1134
1121
|
|
|
1135
|
-
// src/
|
|
1136
|
-
var
|
|
1137
|
-
|
|
1122
|
+
// src/keys.ts
|
|
1123
|
+
var isAtomKey = (key, store) => target(store).atoms.has(key);
|
|
1124
|
+
var isSelectorKey = (key, store) => target(store).selectors.has(key);
|
|
1125
|
+
var isReadonlySelectorKey = (key, store) => target(store).readonlySelectors.has(key);
|
|
1126
|
+
var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
|
|
1127
|
+
|
|
1128
|
+
// src/selector/get-selector-dependency-keys.ts
|
|
1129
|
+
var getSelectorDependencyKeys = (key, store) => {
|
|
1130
|
+
const sources = target(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
|
|
1138
1131
|
return sources;
|
|
1139
1132
|
};
|
|
1140
1133
|
|
|
@@ -1379,36 +1372,35 @@ var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
|
|
|
1379
1372
|
};
|
|
1380
1373
|
|
|
1381
1374
|
// src/selector/trace-selector-atoms.ts
|
|
1382
|
-
var traceSelectorAtoms = (selectorKey,
|
|
1383
|
-
|
|
1384
|
-
const
|
|
1385
|
-
|
|
1375
|
+
var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
|
|
1376
|
+
const rootKeys = [];
|
|
1377
|
+
const indirectDependencyKeys = getSelectorDependencyKeys(
|
|
1378
|
+
directDependencyKey,
|
|
1379
|
+
store
|
|
1380
|
+
);
|
|
1386
1381
|
let depth = 0;
|
|
1387
|
-
while (
|
|
1388
|
-
const
|
|
1382
|
+
while (indirectDependencyKeys.length > 0) {
|
|
1383
|
+
const indirectDependencyKey = indirectDependencyKeys.shift();
|
|
1389
1384
|
++depth;
|
|
1390
|
-
if (depth > 999) {
|
|
1391
|
-
(_a = store.config.logger) == null ? void 0 : _a.warn(
|
|
1392
|
-
`Maximum selector dependency depth exceeded 999 in selector "${selectorKey}".`
|
|
1393
|
-
);
|
|
1394
|
-
}
|
|
1395
1385
|
if (depth > 99999) {
|
|
1396
1386
|
throw new Error(
|
|
1397
|
-
`Maximum selector dependency depth exceeded in selector "${selectorKey}".`
|
|
1387
|
+
`Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
|
|
1398
1388
|
);
|
|
1399
1389
|
}
|
|
1400
|
-
if (
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1390
|
+
if (!isAtomKey(indirectDependencyKey, store)) {
|
|
1391
|
+
indirectDependencyKeys.push(
|
|
1392
|
+
...getSelectorDependencyKeys(indirectDependencyKey, store)
|
|
1393
|
+
);
|
|
1394
|
+
} else if (!rootKeys.includes(indirectDependencyKey)) {
|
|
1395
|
+
rootKeys.push(indirectDependencyKey);
|
|
1404
1396
|
}
|
|
1405
1397
|
}
|
|
1406
|
-
return
|
|
1398
|
+
return rootKeys;
|
|
1407
1399
|
};
|
|
1408
1400
|
var traceAllSelectorAtoms = (selectorKey, store) => {
|
|
1409
|
-
const
|
|
1410
|
-
return
|
|
1411
|
-
(
|
|
1401
|
+
const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
|
|
1402
|
+
return directDependencyKeys.flatMap(
|
|
1403
|
+
(depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
|
|
1412
1404
|
);
|
|
1413
1405
|
};
|
|
1414
1406
|
|
|
@@ -1426,15 +1418,15 @@ var updateSelectorAtoms = (selectorKey, dependency, store) => {
|
|
|
1426
1418
|
);
|
|
1427
1419
|
return;
|
|
1428
1420
|
}
|
|
1429
|
-
const
|
|
1421
|
+
const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
|
|
1430
1422
|
(_b = store.config.logger) == null ? void 0 : _b.info(
|
|
1431
1423
|
` || adding roots for "${selectorKey}":`,
|
|
1432
|
-
|
|
1424
|
+
rootKeys.map((r) => r)
|
|
1433
1425
|
);
|
|
1434
|
-
for (const
|
|
1426
|
+
for (const atomKey of rootKeys) {
|
|
1435
1427
|
core.selectorAtoms = core.selectorAtoms.set({
|
|
1436
1428
|
selectorKey,
|
|
1437
|
-
atomKey
|
|
1429
|
+
atomKey
|
|
1438
1430
|
});
|
|
1439
1431
|
}
|
|
1440
1432
|
};
|
|
@@ -1751,8 +1743,8 @@ var markAtomAsNotDefault = (key, store = IMPLICIT.STORE) => {
|
|
|
1751
1743
|
core.atomsThatAreDefault.delete(key);
|
|
1752
1744
|
};
|
|
1753
1745
|
var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
|
|
1754
|
-
const
|
|
1755
|
-
return
|
|
1746
|
+
const rootKeys = traceAllSelectorAtoms(key, store);
|
|
1747
|
+
return rootKeys.every((rootKey) => isAtomDefault(rootKey, store));
|
|
1756
1748
|
};
|
|
1757
1749
|
|
|
1758
1750
|
// src/atom/create-atom.ts
|
|
@@ -1825,11 +1817,11 @@ var recallState = (state, store = IMPLICIT.STORE) => {
|
|
|
1825
1817
|
|
|
1826
1818
|
// src/subscribe/subscribe-to-root-atoms.ts
|
|
1827
1819
|
var subscribeToRootAtoms = (state, store) => {
|
|
1828
|
-
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((
|
|
1829
|
-
const atom =
|
|
1820
|
+
const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
|
|
1821
|
+
const atom = store.atoms.get(atomKey);
|
|
1830
1822
|
if (atom === void 0) {
|
|
1831
1823
|
throw new Error(
|
|
1832
|
-
`Atom "${
|
|
1824
|
+
`Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
|
|
1833
1825
|
);
|
|
1834
1826
|
}
|
|
1835
1827
|
return atom.subject.subscribe(
|
|
@@ -1837,7 +1829,7 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1837
1829
|
(atomChange) => {
|
|
1838
1830
|
var _a, _b;
|
|
1839
1831
|
(_a = store.config.logger) == null ? void 0 : _a.info(
|
|
1840
|
-
`\u{1F4E2} selector "${state.key}" saw root "${
|
|
1832
|
+
`\u{1F4E2} selector "${state.key}" saw root "${atomKey}" go (`,
|
|
1841
1833
|
atomChange.oldValue,
|
|
1842
1834
|
`->`,
|
|
1843
1835
|
atomChange.newValue,
|
|
@@ -1859,6 +1851,6 @@ var subscribeToRootAtoms = (state, store) => {
|
|
|
1859
1851
|
return dependencySubscriptions;
|
|
1860
1852
|
};
|
|
1861
1853
|
|
|
1862
|
-
export { FamilyTracker, Future, IMPLICIT, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomMutable, isAtomTokenMutable, isDone, isSelectorDefault,
|
|
1854
|
+
export { FamilyTracker, Future, IMPLICIT, Store, Subject, TRANSACTION_PHASES, Tracker, abortTransaction, addAtomToTimeline, applyTransaction, become, buildTransaction, cacheValue, clearStore, closeOperation, createAtom, createAtomFamily, createMutableAtom, createMutableAtomFamily, createReadonlySelectorFamily, createSelector, createSelectorFamily, deleteAtom, deposit, evictCachedValue, getJsonToken, getSelectorDependencyKeys, getState__INTERNAL, getUpdateToken, isAtomDefault, isAtomKey, isAtomMutable, isAtomTokenMutable, isDone, isReadonlySelectorKey, isSelectorDefault, isSelectorKey, isStateKey, isTransceiver, isValueCached, markAtomAsDefault, markAtomAsNotDefault, markDone, openOperation, readCachedValue, redoTransactionUpdate, redo__INTERNAL, registerSelector, setState__INTERNAL, subscribeToRootAtoms, target, timeline__INTERNAL, traceAllSelectorAtoms, traceSelectorAtoms, transaction__INTERNAL, undoTransactionUpdate, undo__INTERNAL, updateSelectorAtoms, withdraw, withdrawNewFamilyMember };
|
|
1863
1855
|
//# sourceMappingURL=out.js.map
|
|
1864
1856
|
//# sourceMappingURL=index.mjs.map
|