atom.io 0.9.9 → 0.10.0

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.
Files changed (64) hide show
  1. package/dist/index.d.mts +11 -4
  2. package/dist/index.d.ts +11 -4
  3. package/dist/index.js +36 -56
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +34 -55
  6. package/dist/index.mjs.map +1 -1
  7. package/internal/dist/index.d.mts +52 -25
  8. package/internal/dist/index.d.ts +52 -25
  9. package/internal/dist/index.js +352 -385
  10. package/internal/dist/index.js.map +1 -1
  11. package/internal/dist/index.mjs +349 -385
  12. package/internal/dist/index.mjs.map +1 -1
  13. package/internal/src/atom/create-atom.ts +5 -5
  14. package/internal/src/atom/delete-atom.ts +9 -2
  15. package/internal/src/atom/is-default.ts +2 -2
  16. package/internal/src/caching.ts +7 -5
  17. package/internal/src/get-state-internal.ts +4 -4
  18. package/internal/src/index.ts +1 -0
  19. package/internal/src/keys.ts +30 -0
  20. package/internal/src/mutable/create-mutable-atom.ts +2 -2
  21. package/internal/src/mutable/tracker.ts +1 -1
  22. package/internal/src/operation.ts +7 -7
  23. package/internal/src/selector/create-read-write-selector.ts +2 -8
  24. package/internal/src/selector/create-readonly-selector.ts +1 -1
  25. package/internal/src/selector/create-selector.ts +5 -3
  26. package/internal/src/selector/get-selector-dependency-keys.ts +20 -0
  27. package/internal/src/selector/index.ts +1 -1
  28. package/internal/src/selector/register-selector.ts +4 -11
  29. package/internal/src/selector/trace-selector-atoms.ts +26 -26
  30. package/internal/src/selector/update-selector-atoms.ts +14 -14
  31. package/internal/src/set-state/copy-mutable-if-needed.ts +1 -1
  32. package/internal/src/set-state/copy-mutable-in-transaction.ts +1 -1
  33. package/internal/src/set-state/emit-update.ts +1 -1
  34. package/internal/src/set-state/evict-downstream.ts +5 -6
  35. package/internal/src/set-state/set-atom.ts +1 -4
  36. package/internal/src/set-state/stow-update.ts +10 -4
  37. package/internal/src/store/index.ts +0 -1
  38. package/internal/src/store/store.ts +27 -10
  39. package/internal/src/store/withdraw-new-family-member.ts +1 -1
  40. package/internal/src/store/withdraw.ts +1 -1
  41. package/internal/src/subscribe/recall-state.ts +2 -2
  42. package/internal/src/subscribe/subscribe-to-root-atoms.ts +7 -8
  43. package/internal/src/timeline/add-atom-to-timeline.ts +8 -8
  44. package/internal/src/timeline/time-travel-internal.ts +12 -12
  45. package/internal/src/timeline/timeline-internal.ts +2 -2
  46. package/internal/src/transaction/abort-transaction.ts +3 -3
  47. package/internal/src/transaction/apply-transaction.ts +6 -6
  48. package/internal/src/transaction/build-transaction.ts +2 -3
  49. package/internal/src/transaction/redo-transaction.ts +1 -1
  50. package/internal/src/transaction/transaction-internal.ts +2 -2
  51. package/internal/src/transaction/undo-transaction.ts +1 -1
  52. package/package.json +3 -3
  53. package/react-devtools/dist/index.d.mts +3 -3
  54. package/react-devtools/dist/index.d.ts +3 -3
  55. package/realtime-client/dist/index.js +6 -9
  56. package/realtime-client/dist/index.js.map +1 -1
  57. package/realtime-client/dist/index.mjs +6 -9
  58. package/realtime-client/dist/index.mjs.map +1 -1
  59. package/realtime-client/src/use-server-action.ts +6 -8
  60. package/src/atom.ts +3 -0
  61. package/src/logger.ts +25 -36
  62. package/src/subscribe.ts +7 -7
  63. package/internal/src/selector/lookup-selector-sources.ts +0 -20
  64. package/internal/src/store/lookup.ts +0 -26
@@ -1,4 +1,4 @@
1
- import { setState, getState, subscribe, subscribeToTimeline } from 'atom.io';
1
+ import { AtomIOLogger, setState, getState, subscribe, subscribeToTimeline } from 'atom.io';
2
2
  import { selectJson, stringifyJson, parseJson, selectJsonFamily } from 'atom.io/json';
3
3
 
4
4
  var __defProp = Object.defineProperty;
@@ -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,9 +250,197 @@ 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
+ };
314
+ this.loggers = [
315
+ new AtomIOLogger(
316
+ __spreadValues({}, console),
317
+ `warn`,
318
+ (message) => !message.includes(`\u{1F441}\u200D\u{1F5E8}`)
319
+ )
320
+ ];
321
+ this.logger = {
322
+ error: (message) => {
323
+ for (const logger of this.loggers) {
324
+ logger.error(message);
325
+ }
326
+ },
327
+ info: (message) => {
328
+ for (const logger of this.loggers) {
329
+ logger.info(message);
330
+ }
331
+ },
332
+ warn: (message) => {
333
+ for (const logger of this.loggers) {
334
+ logger.warn(message);
335
+ }
336
+ }
337
+ };
338
+ if (store !== null) {
339
+ this.valueMap = new Map(store == null ? void 0 : store.valueMap);
340
+ this.operation = __spreadValues({}, store == null ? void 0 : store.operation);
341
+ this.transactionStatus = __spreadValues({}, store == null ? void 0 : store.transactionStatus);
342
+ this.config = __spreadProps(__spreadValues({}, store == null ? void 0 : store.config), {
343
+ name
344
+ });
345
+ for (const [, atom] of store.atoms) {
346
+ atom.install(this);
347
+ }
348
+ for (const [, selector] of store.readonlySelectors) {
349
+ selector.install(this);
350
+ }
351
+ for (const [, selector] of store.selectors) {
352
+ selector.install(this);
353
+ }
354
+ for (const [, tx] of store.transactions) {
355
+ tx.install(this);
356
+ }
357
+ for (const [, timeline] of store.timelines) {
358
+ timeline.install(this);
359
+ }
360
+ }
361
+ }
362
+ };
363
+ var IMPLICIT = {
364
+ STORE_INTERNAL: void 0,
365
+ get STORE() {
366
+ var _a;
367
+ return (_a = this.STORE_INTERNAL) != null ? _a : this.STORE_INTERNAL = new Store(`IMPLICIT_STORE`);
368
+ }
369
+ };
370
+ var clearStore = (store = IMPLICIT.STORE) => {
371
+ const { config } = store;
372
+ Object.assign(store, new Store(config.name));
373
+ store.config = config;
374
+ };
375
+
376
+ // src/transaction/abort-transaction.ts
377
+ var abortTransaction = (store) => {
378
+ if (store.transactionStatus.phase === `idle`) {
379
+ store.logger.warn(
380
+ `\u{1F41E} abortTransaction called outside of a transaction. This is probably a bug.`
381
+ );
382
+ return;
383
+ }
384
+ store.transactionStatus = { phase: `idle` };
385
+ store.logger.info(`\u{1FA82}`, `transaction fail`);
386
+ };
387
+ var applyTransaction = (output, store) => {
388
+ if (store.transactionStatus.phase !== `building`) {
389
+ store.logger.warn(
390
+ `\u{1F41E} applyTransaction called outside of a transaction. This is probably a bug.`
391
+ );
392
+ return;
393
+ }
394
+ store.transactionStatus.phase = `applying`;
395
+ store.transactionStatus.output = output;
396
+ const { atomUpdates } = store.transactionStatus;
397
+ store.logger.info(
398
+ `\u{1F6C3} applying transaction "${store.transactionStatus.key}" with ${atomUpdates.length} updates.`
399
+ );
400
+ store.logger.info(`\u{1F6C3} the updates are:`, atomUpdates);
401
+ for (const { key, newValue } of atomUpdates) {
402
+ const token = { key, type: `atom` };
403
+ if (!store.valueMap.has(token.key)) {
404
+ if (token.family) {
405
+ const family = store.families.get(token.family.key);
406
+ if (family) {
407
+ family(token.family.subKey);
408
+ }
409
+ } else {
410
+ const newAtom = store.transactionStatus.core.atoms.get(token.key);
411
+ if (!newAtom) {
412
+ throw new Error(
413
+ `Absurd Error: Atom "${token.key}" not found while copying updates from transaction "${store.transactionStatus.key}" to store "${store.config.name}"`
414
+ );
415
+ }
416
+ store.atoms.set(newAtom.key, newAtom);
417
+ store.valueMap.set(newAtom.key, newAtom.default);
418
+ store.logger.info(`\u{1F527} add atom "${newAtom.key}"`);
419
+ }
420
+ }
421
+ setState(token, newValue, store);
422
+ }
423
+ const myTransaction = withdraw(
424
+ { key: store.transactionStatus.key, type: `transaction` },
425
+ store
426
+ );
427
+ if (myTransaction === void 0) {
428
+ throw new Error(
429
+ `Transaction "${store.transactionStatus.key}" not found. Absurd. How is this running?`
430
+ );
431
+ }
432
+ myTransaction.subject.next({
433
+ key: store.transactionStatus.key,
434
+ atomUpdates,
435
+ output,
436
+ params: store.transactionStatus.params
437
+ });
438
+ store.transactionStatus = { phase: `idle` };
439
+ store.logger.info(`\u{1F6EC} transaction "${myTransaction.key}" applied`);
440
+ };
441
+
341
442
  // src/transaction/build-transaction.ts
342
443
  var buildTransaction = (key, params, store) => {
343
- var _a;
344
444
  store.transactionStatus = {
345
445
  key,
346
446
  phase: `building`,
@@ -366,9 +466,8 @@ var buildTransaction = (key, params, store) => {
366
466
  params,
367
467
  output: void 0
368
468
  };
369
- (_a = store.config.logger) == null ? void 0 : _a.info(
370
- `\u{1F6EB}`,
371
- `transaction "${key}" building in store "${store.config.name}"`
469
+ store.logger.info(
470
+ `\u{1F6EB} transaction "${key}" building in store "${store.config.name}"`
372
471
  );
373
472
  };
374
473
 
@@ -378,7 +477,6 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
378
477
  key: options.key,
379
478
  type: `transaction`,
380
479
  run: (...params) => {
381
- var _a;
382
480
  buildTransaction(options.key, params, store);
383
481
  try {
384
482
  const output = options.do(
@@ -392,8 +490,8 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
392
490
  return output;
393
491
  } catch (thrown) {
394
492
  abortTransaction(store);
395
- (_a = store.config.logger) == null ? void 0 : _a.error(
396
- `Transaction "${options.key}" failed in store "${store.config.name}":`,
493
+ store.logger.error(
494
+ `\u2757 Transaction "${options.key}" failed in store "${store.config.name}":`,
397
495
  thrown
398
496
  );
399
497
  throw thrown;
@@ -410,8 +508,7 @@ function transaction__INTERNAL(options, store = IMPLICIT.STORE) {
410
508
  }
411
509
  var target = (store = IMPLICIT.STORE) => store.transactionStatus.phase === `building` ? store.transactionStatus.core : store;
412
510
  var redoTransactionUpdate = (update, store) => {
413
- var _a;
414
- (_a = store.config.logger) == null ? void 0 : _a.info(` \u23ED redo transaction "${update.key}" (redo)`);
511
+ store.logger.info(` \u23ED redo transaction "${update.key}" (redo)`);
415
512
  for (const { key, newValue } of update.atomUpdates) {
416
513
  const token = { key, type: `atom` };
417
514
  const state = withdraw(token, store);
@@ -424,8 +521,7 @@ var redoTransactionUpdate = (update, store) => {
424
521
  }
425
522
  };
426
523
  var undoTransactionUpdate = (update, store) => {
427
- var _a;
428
- (_a = store.config.logger) == null ? void 0 : _a.info(` \u23EE undo transaction "${update.key}" (undo)`);
524
+ store.logger.info(` \u23EE undo transaction "${update.key}" (undo)`);
429
525
  for (const { key, oldValue } of update.atomUpdates) {
430
526
  const token = { key, type: `atom` };
431
527
  const state = withdraw(token, store);
@@ -441,107 +537,6 @@ var undoTransactionUpdate = (update, store) => {
441
537
  // src/transaction/index.ts
442
538
  var TRANSACTION_PHASES = [`idle`, `building`, `applying`];
443
539
 
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
540
  // src/timeline/add-atom-to-timeline.ts
546
541
  var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
547
542
  const atom = withdraw(atomToken, store);
@@ -551,12 +546,12 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
551
546
  );
552
547
  }
553
548
  atom.subject.subscribe(`timeline`, (update) => {
554
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
549
+ var _a, _b, _c, _d;
555
550
  const currentSelectorKey = store.operation.open && store.operation.token.type === `selector` ? store.operation.token.key : null;
556
551
  const currentSelectorTime = store.operation.open && store.operation.token.type === `selector` ? store.operation.time : null;
557
552
  const currentTransactionKey = store.transactionStatus.phase === `applying` ? store.transactionStatus.key : null;
558
553
  const currentTransactionTime = store.transactionStatus.phase === `applying` ? store.transactionStatus.time : null;
559
- (_a = store.config.logger) == null ? void 0 : _a.info(
554
+ store.logger.info(
560
555
  `\u23F3 timeline "${tl.key}" saw atom "${atomToken.key}" go (`,
561
556
  update.oldValue,
562
557
  `->`,
@@ -584,15 +579,15 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
584
579
  }
585
580
  if (tl.transactionKey !== currentTransactionKey) {
586
581
  if (tl.transactionKey) {
587
- (_b = store.config.logger) == null ? void 0 : _b.error(
588
- `Timeline "${tl.key}" was unable to resolve transaction "${tl.transactionKey}. This is probably a bug.`
582
+ store.logger.error(
583
+ `\u{1F41E} Timeline "${tl.key}" was unable to resolve transaction "${tl.transactionKey}. This is probably a bug.`
589
584
  );
590
585
  }
591
586
  tl.transactionKey = currentTransactionKey;
592
587
  const unsubscribe = currentTransaction.subject.subscribe(
593
588
  `timeline:${tl.key}`,
594
589
  (update2) => {
595
- var _a2, _b2, _c2;
590
+ var _a2, _b2;
596
591
  unsubscribe();
597
592
  if (tl.timeTraveling === null && currentTransactionTime) {
598
593
  if (tl.at !== tl.history.length) {
@@ -624,7 +619,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
624
619
  }
625
620
  }
626
621
  tl.transactionKey = null;
627
- (_c2 = store.config.logger) == null ? void 0 : _c2.info(
622
+ store.logger.info(
628
623
  `\u231B timeline "${tl.key}" got a transaction_update "${update2.key}"`
629
624
  );
630
625
  }
@@ -647,7 +642,7 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
647
642
  tl.history.splice(tl.at);
648
643
  }
649
644
  tl.history.push(latestUpdate);
650
- (_c = store.config.logger) == null ? void 0 : _c.info(
645
+ store.logger.info(
651
646
  `\u231B timeline "${tl.key}" got a selector_update "${currentSelectorKey}" with`,
652
647
  latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
653
648
  );
@@ -659,14 +654,14 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
659
654
  key: atom.key,
660
655
  type: `atom_update`
661
656
  }, update));
662
- (_d = store.config.logger) == null ? void 0 : _d.info(
663
- ` \u231B timeline "${tl.key}" set selector_update "${currentSelectorKey}" to`,
657
+ store.logger.info(
658
+ `\u231B timeline "${tl.key}" set selector_update "${currentSelectorKey}" to`,
664
659
  latestUpdate == null ? void 0 : latestUpdate.atomUpdates.map((atomUpdate) => atomUpdate.key)
665
660
  );
666
661
  }
667
662
  }
668
663
  if (latestUpdate) {
669
- const willCaptureSelectorUpdate = (_f = (_e = tl.shouldCapture) == null ? void 0 : _e.call(tl, latestUpdate, tl)) != null ? _f : true;
664
+ const willCaptureSelectorUpdate = (_b = (_a = tl.shouldCapture) == null ? void 0 : _a.call(tl, latestUpdate, tl)) != null ? _b : true;
670
665
  if (willCaptureSelectorUpdate) {
671
666
  tl.subject.next(latestUpdate);
672
667
  } else {
@@ -690,8 +685,8 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
690
685
  if (atom.family) {
691
686
  atomUpdate.family = atom.family;
692
687
  }
693
- const willCapture = (_h = (_g = tl.shouldCapture) == null ? void 0 : _g.call(tl, atomUpdate, tl)) != null ? _h : true;
694
- (_i = store.config.logger) == null ? void 0 : _i.info(
688
+ const willCapture = (_d = (_c = tl.shouldCapture) == null ? void 0 : _c.call(tl, atomUpdate, tl)) != null ? _d : true;
689
+ store.logger.info(
695
690
  `\u231B timeline "${tl.key}" got an atom_update to "${atom.key}"`
696
691
  );
697
692
  if (willCapture) {
@@ -704,18 +699,17 @@ var addAtomToTimeline = (atomToken, tl, store = IMPLICIT.STORE) => {
704
699
  });
705
700
  };
706
701
  var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
707
- var _a, _b, _c, _d;
708
- (_a = store.config.logger) == null ? void 0 : _a.info(`\u23E9 redo "${token.key}"`);
702
+ store.logger.info(`\u23E9 redo "${token.key}"`);
709
703
  const timelineData = store.timelines.get(token.key);
710
704
  if (!timelineData) {
711
- (_b = store.config.logger) == null ? void 0 : _b.error(
712
- `Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
705
+ store.logger.error(
706
+ `\u{1F41E} Failed to redo on timeline "${token.key}". This timeline has not been initialized.`
713
707
  );
714
708
  return;
715
709
  }
716
710
  if (timelineData.at === timelineData.history.length) {
717
- (_c = store.config.logger) == null ? void 0 : _c.warn(
718
- `Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
711
+ store.logger.warn(
712
+ `\u261D\uFE0F Failed to redo at the end of timeline "${token.key}". There is nothing to redo.`
719
713
  );
720
714
  return;
721
715
  }
@@ -739,23 +733,22 @@ var redo__INTERNAL = (token, store = IMPLICIT.STORE) => {
739
733
  ++timelineData.at;
740
734
  timelineData.subject.next(`redo`);
741
735
  timelineData.timeTraveling = null;
742
- (_d = store.config.logger) == null ? void 0 : _d.info(
736
+ store.logger.info(
743
737
  `\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
744
738
  );
745
739
  };
746
740
  var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
747
- var _a, _b, _c, _d;
748
- (_a = store.config.logger) == null ? void 0 : _a.info(`\u23EA undo "${token.key}"`);
741
+ store.logger.info(`\u23EA undo "${token.key}"`);
749
742
  const timelineData = store.timelines.get(token.key);
750
743
  if (!timelineData) {
751
- (_b = store.config.logger) == null ? void 0 : _b.error(
752
- `Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
744
+ store.logger.error(
745
+ `\u{1F41E} Failed to undo on timeline "${token.key}". This timeline has not been initialized.`
753
746
  );
754
747
  return;
755
748
  }
756
749
  if (timelineData.at === 0) {
757
- (_c = store.config.logger) == null ? void 0 : _c.warn(
758
- `Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
750
+ store.logger.warn(
751
+ `\u261D\uFE0F Failed to undo at the beginning of timeline "${token.key}". There is nothing to undo.`
759
752
  );
760
753
  return;
761
754
  }
@@ -779,14 +772,14 @@ var undo__INTERNAL = (token, store = IMPLICIT.STORE) => {
779
772
  }
780
773
  timelineData.subject.next(`undo`);
781
774
  timelineData.timeTraveling = null;
782
- (_d = store.config.logger) == null ? void 0 : _d.info(
775
+ store.logger.info(
783
776
  `\u23F9\uFE0F "${token.key}" is now at ${timelineData.at} / ${timelineData.history.length}`
784
777
  );
785
778
  };
786
779
 
787
780
  // src/timeline/timeline-internal.ts
788
781
  function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
789
- var _a, _b, _c, _d;
782
+ var _a, _b;
790
783
  const tl = __spreadProps(__spreadValues({
791
784
  type: `timeline`,
792
785
  key: options.key,
@@ -806,7 +799,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
806
799
  for (const tokenOrFamily of options.atoms) {
807
800
  const timelineKey = core.timelineAtoms.getRelatedKey(tokenOrFamily.key);
808
801
  if (timelineKey) {
809
- (_b = store.config.logger) == null ? void 0 : _b.error(
802
+ store.logger.error(
810
803
  `\u274C Failed to add atom "${tokenOrFamily.key}" to timeline "${options.key}" because it belongs to timeline "${timelineKey}"`
811
804
  );
812
805
  continue;
@@ -817,7 +810,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
817
810
  addAtomToTimeline(token2, tl, store);
818
811
  });
819
812
  for (const atom of core.atoms.values()) {
820
- if (((_c = atom.family) == null ? void 0 : _c.key) === family.key) {
813
+ if (((_b = atom.family) == null ? void 0 : _b.key) === family.key) {
821
814
  addAtomToTimeline(atom, tl, store);
822
815
  }
823
816
  }
@@ -828,7 +821,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
828
821
  token2.family.key
829
822
  );
830
823
  if (familyTimelineKey) {
831
- (_d = store.config.logger) == null ? void 0 : _d.error(
824
+ store.logger.error(
832
825
  `\u274C Failed to add atom "${token2.key}" to timeline "${options.key}" because its family "${token2.family.key}" belongs to timeline "${familyTimelineKey}"`
833
826
  );
834
827
  continue;
@@ -852,7 +845,7 @@ function timeline__INTERNAL(options, store = IMPLICIT.STORE, data = null) {
852
845
 
853
846
  // src/store/withdraw.ts
854
847
  function withdraw(token, store) {
855
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
848
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
856
849
  let core = target(store);
857
850
  let state = (_d = (_c = (_b = (_a = core.atoms.get(token.key)) != null ? _a : core.selectors.get(token.key)) != null ? _b : core.readonlySelectors.get(token.key)) != null ? _c : core.transactions.get(token.key)) != null ? _d : core.timelines.get(token.key);
858
851
  if (state) {
@@ -862,13 +855,13 @@ function withdraw(token, store) {
862
855
  core = store.transactionStatus.core;
863
856
  state = (_h = (_g = (_f = (_e = core.atoms.get(token.key)) != null ? _e : core.selectors.get(token.key)) != null ? _f : core.readonlySelectors.get(token.key)) != null ? _g : core.transactions.get(token.key)) != null ? _h : core.timelines.get(token.key);
864
857
  if (state) {
865
- (_i = store.config.logger) == null ? void 0 : _i.info(`\u{1F6E0}\uFE0F add ${token.type} "${token.key}"`);
858
+ store.logger.info(`\u{1F6E0}\uFE0F add ${token.type} "${token.key}"`);
866
859
  switch (state.type) {
867
860
  case `atom`: {
868
861
  store.atoms.set(token.key, state);
869
862
  store.valueMap.set(token.key, state.default);
870
863
  const stateKey = state.key;
871
- const familyKey = (_j = state.family) == null ? void 0 : _j.key;
864
+ const familyKey = (_i = state.family) == null ? void 0 : _i.key;
872
865
  let timelineKey = core.timelineAtoms.getRelatedKey(stateKey);
873
866
  if (timelineKey === void 0 && typeof familyKey === `string`) {
874
867
  timelineKey = core.timelineAtoms.getRelatedKey(familyKey);
@@ -900,8 +893,7 @@ function withdraw(token, store) {
900
893
 
901
894
  // src/store/withdraw-new-family-member.ts
902
895
  function withdrawNewFamilyMember(token, store) {
903
- var _a;
904
- (_a = store.config.logger) == null ? void 0 : _a.info(
896
+ store.logger.info(
905
897
  `\u{1F46A} creating new family member "${token.key}" in store "${store.config.name}"`
906
898
  );
907
899
  if (token.family) {
@@ -933,11 +925,9 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
933
925
  cacheValue(key, value2, subject, store);
934
926
  subject.next({ newValue: value2, oldValue: value2 });
935
927
  }).catch((error) => {
936
- var _a;
937
- (_a = store.config.logger) == null ? void 0 : _a.error(
938
- `Promised value for "${key}" rejected:`,
939
- error
940
- );
928
+ if (error !== `canceled`) {
929
+ store.logger.error(`\u{1F645}\u200D\u2642\uFE0F Promised value for "${key}" rejected:`, error);
930
+ }
941
931
  });
942
932
  } else {
943
933
  target(store).valueMap.set(key, value);
@@ -946,14 +936,16 @@ var cacheValue = (key, value, subject, store = IMPLICIT.STORE) => {
946
936
  var readCachedValue = (key, store = IMPLICIT.STORE) => target(store).valueMap.get(key);
947
937
  var isValueCached = (key, store = IMPLICIT.STORE) => target(store).valueMap.has(key);
948
938
  var evictCachedValue = (key, store = IMPLICIT.STORE) => {
949
- var _a;
950
939
  const core = target(store);
951
940
  const currentValue = core.valueMap.get(key);
952
941
  if (currentValue instanceof Future) {
953
942
  currentValue.cancel();
954
943
  }
944
+ if (core.operation.open) {
945
+ core.operation.prev.set(key, currentValue);
946
+ }
955
947
  core.valueMap.delete(key);
956
- (_a = store.config.logger) == null ? void 0 : _a.info(` xx evicted "${key}"`);
948
+ store.logger.info(`\u{1F5D1} evicted "${key}"`);
957
949
  };
958
950
  var Tracker = class {
959
951
  constructor(mutableState, store = IMPLICIT.STORE) {
@@ -967,7 +959,7 @@ var Tracker = class {
967
959
  }
968
960
  initializeState(mutableState, store = IMPLICIT.STORE) {
969
961
  const latestUpdateStateKey = `*${mutableState.key}`;
970
- deleteAtom(latestUpdateStateKey, target(store));
962
+ deleteAtom({ type: `atom`, key: latestUpdateStateKey }, store);
971
963
  const familyMetaData = mutableState.family ? {
972
964
  key: `*${mutableState.family.key}`,
973
965
  subKey: mutableState.family.subKey
@@ -1073,8 +1065,7 @@ var Tracker = class {
1073
1065
 
1074
1066
  // src/mutable/create-mutable-atom.ts
1075
1067
  function createMutableAtom(options, store = IMPLICIT.STORE) {
1076
- var _a;
1077
- (_a = store.config.logger) == null ? void 0 : _a.info(
1068
+ store.logger.info(
1078
1069
  `\u{1F527} creating mutable atom "${options.key}" in store "${store.config.name}"`
1079
1070
  );
1080
1071
  const coreState = createAtom(options, void 0, store);
@@ -1083,8 +1074,7 @@ function createMutableAtom(options, store = IMPLICIT.STORE) {
1083
1074
  subscribe(
1084
1075
  jsonState,
1085
1076
  () => {
1086
- var _a2;
1087
- (_a2 = store.config.logger) == null ? void 0 : _a2.info(
1077
+ store.logger.info(
1088
1078
  `\u{1F50D} tracker-initializer:${store == null ? void 0 : store.config.name}:${store.transactionStatus.phase === `idle` ? `main` : store.transactionStatus.key}`,
1089
1079
  `Initializing tracker for ${coreState.key}`
1090
1080
  );
@@ -1132,25 +1122,30 @@ function createAtomFamily(options, store = IMPLICIT.STORE) {
1132
1122
  return atomFamily;
1133
1123
  }
1134
1124
 
1135
- // src/selector/lookup-selector-sources.ts
1136
- var lookupSelectorSources = (key, store) => {
1137
- const sources = target(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => lookup(source, store));
1125
+ // src/keys.ts
1126
+ var isAtomKey = (key, store) => target(store).atoms.has(key);
1127
+ var isSelectorKey = (key, store) => target(store).selectors.has(key);
1128
+ var isReadonlySelectorKey = (key, store) => target(store).readonlySelectors.has(key);
1129
+ var isStateKey = (key, store) => isAtomKey(key, store) || isSelectorKey(key, store) || isReadonlySelectorKey(key, store);
1130
+
1131
+ // src/selector/get-selector-dependency-keys.ts
1132
+ var getSelectorDependencyKeys = (key, store) => {
1133
+ const sources = target(store).selectorGraph.getRelationEntries({ downstreamSelectorKey: key }).filter(([_, { source }]) => source !== key).map(([_, { source }]) => source).filter((source) => isStateKey(source, store));
1138
1134
  return sources;
1139
1135
  };
1140
1136
 
1141
1137
  // src/get-state-internal.ts
1142
1138
  var getState__INTERNAL = (state, store = IMPLICIT.STORE) => {
1143
- var _a, _b, _c;
1144
1139
  if (isValueCached(state.key, store)) {
1145
- (_a = store.config.logger) == null ? void 0 : _a.info(`>> read "${state.key}"`);
1140
+ store.logger.info(`\u{1F4D6} reading "${state.key}"`);
1146
1141
  return readCachedValue(state.key, store);
1147
1142
  }
1148
1143
  if (state.type !== `atom`) {
1149
- (_b = store.config.logger) == null ? void 0 : _b.info(`-> calc "${state.key}"`);
1144
+ store.logger.info(`\u{1F9EE} calculating "${state.key}"`);
1150
1145
  return state.get();
1151
1146
  }
1152
- (_c = store.config.logger) == null ? void 0 : _c.error(
1153
- `Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
1147
+ store.logger.error(
1148
+ `\u{1F41E} Attempted to get atom "${state.key}", which was never initialized in store "${store.config.name}".`
1154
1149
  );
1155
1150
  return state.default;
1156
1151
  };
@@ -1162,10 +1157,9 @@ var become = (nextVersionOfThing) => (originalThing) => nextVersionOfThing insta
1162
1157
 
1163
1158
  // src/operation.ts
1164
1159
  var openOperation = (token, store) => {
1165
- var _a, _b;
1166
1160
  const core = target(store);
1167
1161
  if (core.operation.open) {
1168
- (_a = store.config.logger) == null ? void 0 : _a.error(
1162
+ store.logger.error(
1169
1163
  `\u274C failed to setState to "${token.key}" during a setState for "${core.operation.token.key}"`
1170
1164
  );
1171
1165
  return `rejection`;
@@ -1173,26 +1167,24 @@ var openOperation = (token, store) => {
1173
1167
  core.operation = {
1174
1168
  open: true,
1175
1169
  done: /* @__PURE__ */ new Set(),
1176
- prev: new Map(store.valueMap),
1170
+ prev: /* @__PURE__ */ new Map(),
1177
1171
  time: Date.now(),
1178
1172
  token
1179
1173
  };
1180
- (_b = store.config.logger) == null ? void 0 : _b.info(
1174
+ store.logger.info(
1181
1175
  `\u2B55 operation start from "${token.key}" in store "${store.config.name}"${store.transactionStatus.phase === `idle` ? `` : ` ${store.transactionStatus.phase} "${store.transactionStatus.key}"`}`
1182
1176
  );
1183
1177
  };
1184
1178
  var closeOperation = (store) => {
1185
- var _a;
1186
1179
  const core = target(store);
1187
1180
  core.operation = { open: false };
1188
- (_a = store.config.logger) == null ? void 0 : _a.info(`\u{1F534} operation done`);
1181
+ store.logger.info(`\u{1F534} operation done`);
1189
1182
  store.subject.operationStatus.next(core.operation);
1190
1183
  };
1191
1184
  var isDone = (key, store = IMPLICIT.STORE) => {
1192
- var _a;
1193
1185
  const core = target(store);
1194
1186
  if (!core.operation.open) {
1195
- (_a = store.config.logger) == null ? void 0 : _a.warn(
1187
+ store.logger.warn(
1196
1188
  `isDone called outside of an operation. This is probably a bug.`
1197
1189
  );
1198
1190
  return true;
@@ -1200,11 +1192,10 @@ var isDone = (key, store = IMPLICIT.STORE) => {
1200
1192
  return core.operation.done.has(key);
1201
1193
  };
1202
1194
  var markDone = (key, store = IMPLICIT.STORE) => {
1203
- var _a;
1204
1195
  const core = target(store);
1205
1196
  if (!core.operation.open) {
1206
- (_a = store.config.logger) == null ? void 0 : _a.warn(
1207
- `markDone called outside of an operation. This is probably a bug.`
1197
+ store.logger.warn(
1198
+ `\u{1F41E} markDone called outside of an operation. This is probably a bug.`
1208
1199
  );
1209
1200
  return;
1210
1201
  }
@@ -1212,14 +1203,13 @@ var markDone = (key, store = IMPLICIT.STORE) => {
1212
1203
  };
1213
1204
 
1214
1205
  // src/set-state/copy-mutable-if-needed.ts
1215
- function copyMutableIfNeeded(atom, transform, origin, target3) {
1216
- var _a;
1206
+ function copyMutableIfNeeded(atom, transform, origin, target2) {
1217
1207
  const originValue = origin.valueMap.get(atom.key);
1218
- const targetValue = target3.valueMap.get(atom.key);
1208
+ const targetValue = target2.valueMap.get(atom.key);
1219
1209
  if (originValue === targetValue) {
1220
- (_a = origin.config.logger) == null ? void 0 : _a.info(`\u{1F4C3} copying`, `${atom.key}`);
1210
+ origin.logger.info(`\u{1F4C3} copying`, `${atom.key}`);
1221
1211
  const copiedValue = transform.fromJson(transform.toJson(originValue));
1222
- target3.valueMap.set(atom.key, copiedValue);
1212
+ target2.valueMap.set(atom.key, copiedValue);
1223
1213
  new Tracker(atom, origin);
1224
1214
  return copiedValue;
1225
1215
  }
@@ -1228,10 +1218,9 @@ function copyMutableIfNeeded(atom, transform, origin, target3) {
1228
1218
 
1229
1219
  // src/set-state/copy-mutable-in-transaction.ts
1230
1220
  function copyMutableIfWithinTransaction(atom, store) {
1231
- var _a;
1232
1221
  if (store.transactionStatus.phase === `building` || store.transactionStatus.phase === `applying`) {
1233
1222
  if (`toJson` in atom && `fromJson` in atom) {
1234
- (_a = store.config.logger) == null ? void 0 : _a.info(
1223
+ store.logger.info(
1235
1224
  `\u{1F4C4} copyMutableIfWithinTransaction: ${atom.key} is mutable`
1236
1225
  );
1237
1226
  const copiedValue = copyMutableIfNeeded(
@@ -1259,9 +1248,9 @@ function copyMutableIfWithinTransaction(atom, store) {
1259
1248
  }
1260
1249
  return getState__INTERNAL(atom, store);
1261
1250
  }
1262
- function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target3) {
1251
+ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target2) {
1263
1252
  if (`toJson` in family && `fromJson` in family) {
1264
- const copyCreated = copyMutableIfNeeded(atom, family, origin, target3);
1253
+ const copyCreated = copyMutableIfNeeded(atom, family, origin, target2);
1265
1254
  return copyCreated;
1266
1255
  }
1267
1256
  return null;
@@ -1270,7 +1259,7 @@ function copyMutableFamilyMemberWithinTransaction(atom, family, origin, target3)
1270
1259
  // src/set-state/emit-update.ts
1271
1260
  var emitUpdate = (state, update, store) => {
1272
1261
  const { key } = state;
1273
- const { logger } = store.config;
1262
+ const { logger } = store;
1274
1263
  logger == null ? void 0 : logger.info(
1275
1264
  `\u{1F4E2} ${state.type} "${key}" went (`,
1276
1265
  update.oldValue,
@@ -1284,26 +1273,25 @@ var emitUpdate = (state, update, store) => {
1284
1273
 
1285
1274
  // src/set-state/evict-downstream.ts
1286
1275
  var evictDownStream = (state, store = IMPLICIT.STORE) => {
1287
- var _a, _b, _c, _d, _e, _f;
1276
+ var _a;
1288
1277
  const core = target(store);
1289
1278
  const downstreamKeys = core.selectorAtoms.getRelatedKeys(state.key);
1290
- (_b = store.config.logger) == null ? void 0 : _b.info(
1291
- ` || ${(_a = downstreamKeys == null ? void 0 : downstreamKeys.size) != null ? _a : `none`} downstream:`,
1279
+ store.logger.info(
1280
+ `\u{1F9F9} evicting ${downstreamKeys == null ? void 0 : downstreamKeys.size} states downstream from ${state.type} "${state.key}":`,
1292
1281
  downstreamKeys
1293
1282
  );
1294
1283
  if (core.operation.open) {
1295
- (_c = store.config.logger) == null ? void 0 : _c.info(` ||`, [...core.operation.done], `already done`);
1284
+ store.logger.info(`\u{1F9F9}`, [...core.operation.done], `already done`);
1296
1285
  }
1297
1286
  if (downstreamKeys) {
1298
1287
  for (const key of downstreamKeys) {
1299
1288
  if (isDone(key, store)) {
1300
- (_d = store.config.logger) == null ? void 0 : _d.info(` || ${key} already done`);
1301
1289
  continue;
1302
1290
  }
1303
- const state2 = (_e = core.selectors.get(key)) != null ? _e : core.readonlySelectors.get(key);
1291
+ const state2 = (_a = core.selectors.get(key)) != null ? _a : core.readonlySelectors.get(key);
1304
1292
  if (!state2) {
1305
- (_f = store.config.logger) == null ? void 0 : _f.info(
1306
- ` || ${key} was not found in selectors or readonlySelectors`
1293
+ store.logger.error(
1294
+ `\u{1F41E} "${key}" was not found in selectors or readonlySelectors`
1307
1295
  );
1308
1296
  return;
1309
1297
  }
@@ -1324,12 +1312,10 @@ function shouldUpdateBeStowed(key, update) {
1324
1312
  return true;
1325
1313
  }
1326
1314
  var stowUpdate = (state, update, store) => {
1327
- var _a;
1328
1315
  const { key } = state;
1329
- const { logger } = store.config;
1330
1316
  if (store.transactionStatus.phase !== `building`) {
1331
- (_a = store.config.logger) == null ? void 0 : _a.warn(
1332
- `stowUpdate called outside of a transaction. This is probably a bug.`
1317
+ store.logger.warn(
1318
+ `\u{1F41E} stowUpdate called outside of a transaction. This is probably a bug.`
1333
1319
  );
1334
1320
  return;
1335
1321
  }
@@ -1342,24 +1328,26 @@ var stowUpdate = (state, update, store) => {
1342
1328
  atomUpdate.family = state.family;
1343
1329
  }
1344
1330
  store.transactionStatus.atomUpdates.push(atomUpdate);
1345
- logger == null ? void 0 : logger.info(`\u{1F4DD} ${key} stowed (`, update.oldValue, `->`, update.newValue, `)`);
1331
+ store.logger.info(
1332
+ `\u{1F4C1} ${key} stowed (`,
1333
+ update.oldValue,
1334
+ `->`,
1335
+ update.newValue,
1336
+ `)`
1337
+ );
1346
1338
  };
1347
1339
 
1348
1340
  // src/set-state/set-atom.ts
1349
1341
  var setAtom = (atom, next, store = IMPLICIT.STORE) => {
1350
- var _a, _b;
1351
1342
  const oldValue = getState__INTERNAL(atom, store);
1352
1343
  let newValue = copyMutableIfWithinTransaction(atom, store);
1353
1344
  newValue = become(next)(newValue);
1354
- (_a = store.config.logger) == null ? void 0 : _a.info(`<< setting atom "${atom.key}" to`, newValue);
1345
+ store.logger.info(`\u{1F4DD} setting atom "${atom.key}" to`, newValue);
1355
1346
  cacheValue(atom.key, newValue, atom.subject, store);
1356
1347
  if (isAtomDefault(atom.key, store)) {
1357
1348
  markAtomAsNotDefault(atom.key, store);
1358
1349
  }
1359
1350
  markDone(atom.key, store);
1360
- (_b = store.config.logger) == null ? void 0 : _b.info(
1361
- ` || evicting caches downstream from "${atom.key}"`
1362
- );
1363
1351
  evictDownStream(atom, store);
1364
1352
  const update = { oldValue, newValue };
1365
1353
  if (store.transactionStatus.phase !== `building`) {
@@ -1379,70 +1367,67 @@ var setState__INTERNAL = (state, value, store = IMPLICIT.STORE) => {
1379
1367
  };
1380
1368
 
1381
1369
  // src/selector/trace-selector-atoms.ts
1382
- var traceSelectorAtoms = (selectorKey, dependency, store) => {
1383
- var _a;
1384
- const roots = [];
1385
- const sources = lookupSelectorSources(dependency.key, store);
1370
+ var traceSelectorAtoms = (selectorKey, directDependencyKey, store) => {
1371
+ const rootKeys = [];
1372
+ const indirectDependencyKeys = getSelectorDependencyKeys(
1373
+ directDependencyKey,
1374
+ store
1375
+ );
1386
1376
  let depth = 0;
1387
- while (sources.length > 0) {
1388
- const source = sources.shift();
1377
+ while (indirectDependencyKeys.length > 0) {
1378
+ const indirectDependencyKey = indirectDependencyKeys.shift();
1389
1379
  ++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
1380
  if (depth > 99999) {
1396
1381
  throw new Error(
1397
- `Maximum selector dependency depth exceeded in selector "${selectorKey}".`
1382
+ `Maximum selector dependency depth exceeded (> 99999) in selector "${selectorKey}". This is likely due to a circular dependency.`
1398
1383
  );
1399
1384
  }
1400
- if (source.type !== `atom`) {
1401
- sources.push(...lookupSelectorSources(source.key, store));
1402
- } else {
1403
- roots.push(source);
1385
+ if (!isAtomKey(indirectDependencyKey, store)) {
1386
+ indirectDependencyKeys.push(
1387
+ ...getSelectorDependencyKeys(indirectDependencyKey, store)
1388
+ );
1389
+ } else if (!rootKeys.includes(indirectDependencyKey)) {
1390
+ rootKeys.push(indirectDependencyKey);
1404
1391
  }
1405
1392
  }
1406
- return roots;
1393
+ return rootKeys;
1407
1394
  };
1408
1395
  var traceAllSelectorAtoms = (selectorKey, store) => {
1409
- const sources = lookupSelectorSources(selectorKey, store);
1410
- return sources.flatMap(
1411
- (source) => source.type === `atom` ? source : traceSelectorAtoms(selectorKey, source, store)
1396
+ const directDependencyKeys = getSelectorDependencyKeys(selectorKey, store);
1397
+ return directDependencyKeys.flatMap(
1398
+ (depKey) => isAtomKey(depKey, store) ? depKey : traceSelectorAtoms(selectorKey, depKey, store)
1412
1399
  );
1413
1400
  };
1414
1401
 
1415
1402
  // src/selector/update-selector-atoms.ts
1416
1403
  var updateSelectorAtoms = (selectorKey, dependency, store) => {
1417
- var _a, _b;
1418
1404
  const core = target(store);
1419
1405
  if (dependency.type === `atom`) {
1420
1406
  core.selectorAtoms = core.selectorAtoms.set({
1421
1407
  selectorKey,
1422
1408
  atomKey: dependency.key
1423
1409
  });
1424
- (_a = store.config.logger) == null ? void 0 : _a.info(
1425
- ` || adding root for "${selectorKey}": ${dependency.key}`
1410
+ store.logger.info(
1411
+ `\u{1F50D} selector "${selectorKey}" discovers root atom "${dependency.key}"`
1426
1412
  );
1427
- return;
1428
- }
1429
- const roots = traceSelectorAtoms(selectorKey, dependency, store);
1430
- (_b = store.config.logger) == null ? void 0 : _b.info(
1431
- ` || adding roots for "${selectorKey}":`,
1432
- roots.map((r) => r.key)
1433
- );
1434
- for (const root of roots) {
1435
- core.selectorAtoms = core.selectorAtoms.set({
1436
- selectorKey,
1437
- atomKey: root.key
1438
- });
1413
+ } else {
1414
+ const rootKeys = traceSelectorAtoms(selectorKey, dependency.key, store);
1415
+ store.logger.info(
1416
+ `\u{1F50D} selector "${selectorKey}" discovers root atoms:`,
1417
+ rootKeys.map((r) => r)
1418
+ );
1419
+ for (const atomKey of rootKeys) {
1420
+ core.selectorAtoms = core.selectorAtoms.set({
1421
+ selectorKey,
1422
+ atomKey
1423
+ });
1424
+ }
1439
1425
  }
1440
1426
  };
1441
1427
 
1442
1428
  // src/selector/register-selector.ts
1443
1429
  var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1444
1430
  get: (dependency) => {
1445
- var _a, _b;
1446
1431
  const core = target(store);
1447
1432
  const alreadyRegistered = core.selectorGraph.getRelationEntries({ downstreamSelectorKey: selectorKey }).some(([_, { source }]) => source === dependency.key);
1448
1433
  const dependencyState = withdraw(dependency, store);
@@ -1452,17 +1437,10 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1452
1437
  );
1453
1438
  }
1454
1439
  const dependencyValue = getState__INTERNAL(dependencyState, store);
1455
- if (alreadyRegistered) {
1456
- (_a = store.config.logger) == null ? void 0 : _a.info(
1457
- ` || ${selectorKey} <- ${dependency.key} =`,
1458
- dependencyValue
1459
- );
1460
- } else {
1461
- (_b = store.config.logger) == null ? void 0 : _b.info(
1462
- `\u{1F50C} registerSelector "${selectorKey}" <- ( "${dependency.key}" =`,
1463
- dependencyValue,
1464
- `)`
1465
- );
1440
+ store.logger.info(
1441
+ `\u{1F50C} selector "${selectorKey}" registers dependency ( "${dependency.key}" = ${dependencyValue} )`
1442
+ );
1443
+ if (!alreadyRegistered) {
1466
1444
  core.selectorGraph = core.selectorGraph.set(
1467
1445
  {
1468
1446
  upstreamSelectorKey: dependency.key,
@@ -1489,7 +1467,6 @@ var registerSelector = (selectorKey, store = IMPLICIT.STORE) => ({
1489
1467
 
1490
1468
  // src/selector/create-read-write-selector.ts
1491
1469
  var createReadWriteSelector = (options, family, store, core) => {
1492
- var _a;
1493
1470
  const subject = new Subject();
1494
1471
  const { get, set } = registerSelector(options.key, store);
1495
1472
  const getSelf = () => {
@@ -1498,16 +1475,9 @@ var createReadWriteSelector = (options, family, store, core) => {
1498
1475
  return value;
1499
1476
  };
1500
1477
  const setSelf = (next) => {
1501
- var _a2;
1502
1478
  const oldValue = getSelf();
1503
1479
  const newValue = become(next)(oldValue);
1504
- (_a2 = store.config.logger) == null ? void 0 : _a2.info(
1505
- ` <- "${options.key}" went (`,
1506
- oldValue,
1507
- `->`,
1508
- newValue,
1509
- `)`
1510
- );
1480
+ store.logger.info(`\u{1F4DD} set "${options.key}" (`, oldValue, `->`, newValue, `)`);
1511
1481
  cacheValue(options.key, newValue, subject, store);
1512
1482
  markDone(options.key, store);
1513
1483
  if (store.transactionStatus.phase === `idle`) {
@@ -1524,7 +1494,7 @@ var createReadWriteSelector = (options, family, store, core) => {
1524
1494
  }), family && { family });
1525
1495
  core.selectors.set(options.key, mySelector);
1526
1496
  const initialValue = getSelf();
1527
- (_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
1497
+ store.logger.info(`\u2728 "${options.key}" =`, initialValue);
1528
1498
  const token = {
1529
1499
  key: options.key,
1530
1500
  type: `selector`
@@ -1538,7 +1508,6 @@ var createReadWriteSelector = (options, family, store, core) => {
1538
1508
 
1539
1509
  // src/selector/create-readonly-selector.ts
1540
1510
  var createReadonlySelector = (options, family, store, core) => {
1541
- var _a;
1542
1511
  const subject = new Subject();
1543
1512
  const { get } = registerSelector(options.key, store);
1544
1513
  const getSelf = () => {
@@ -1554,7 +1523,7 @@ var createReadonlySelector = (options, family, store, core) => {
1554
1523
  }), family && { family });
1555
1524
  core.readonlySelectors.set(options.key, readonlySelector);
1556
1525
  const initialValue = getSelf();
1557
- (_a = store.config.logger) == null ? void 0 : _a.info(` \u2728 "${options.key}" =`, initialValue);
1526
+ store.logger.info(`\u2728 "${options.key}" =`, initialValue);
1558
1527
  const token = {
1559
1528
  key: options.key,
1560
1529
  type: `readonly_selector`
@@ -1568,16 +1537,14 @@ var createReadonlySelector = (options, family, store, core) => {
1568
1537
 
1569
1538
  // src/selector/create-selector.ts
1570
1539
  function createSelector(options, family, store = IMPLICIT.STORE) {
1571
- var _a, _b;
1572
1540
  const core = target(store);
1573
1541
  const existingWritable = core.selectors.get(options.key);
1574
1542
  const existingReadonly = core.readonlySelectors.get(options.key);
1575
1543
  if (existingWritable || existingReadonly) {
1576
- (_b = (_a = store.config.logger) == null ? void 0 : _a.error) == null ? void 0 : _b.call(
1577
- _a,
1578
- `Tried to create ${existingReadonly ? `readonly selector` : `selector`}`,
1544
+ store.logger.error(
1545
+ `\u2753 Tried to create ${existingReadonly ? `readonly selector` : `selector`}`,
1579
1546
  `"${options.key}", but it already exists in the store.`,
1580
- `(Ignore if you are using hot module replacement.)`
1547
+ `(Ignore if you are in development using hot module replacement.)`
1581
1548
  );
1582
1549
  }
1583
1550
  if (`set` in options) {
@@ -1751,25 +1718,23 @@ var markAtomAsNotDefault = (key, store = IMPLICIT.STORE) => {
1751
1718
  core.atomsThatAreDefault.delete(key);
1752
1719
  };
1753
1720
  var isSelectorDefault = (key, store = IMPLICIT.STORE) => {
1754
- const roots = traceAllSelectorAtoms(key, store);
1755
- return roots.every((root) => isAtomDefault(root.key, store));
1721
+ const rootKeys = traceAllSelectorAtoms(key, store);
1722
+ return rootKeys.every((rootKey) => isAtomDefault(rootKey, store));
1756
1723
  };
1757
1724
 
1758
1725
  // src/atom/create-atom.ts
1759
1726
  function createAtom(options, family, store = IMPLICIT.STORE) {
1760
- var _a, _b, _c, _d, _e;
1761
- (_b = (_a = store.config.logger) == null ? void 0 : _a.info) == null ? void 0 : _b.call(
1762
- _a,
1727
+ var _a;
1728
+ store.logger.info(
1763
1729
  `\u{1F528} creating atom "${options.key}" in store "${store.config.name}"`
1764
1730
  );
1765
1731
  const core = target(store);
1766
1732
  const existing = core.atoms.get(options.key);
1767
1733
  if (existing) {
1768
- (_d = (_c = store.config.logger) == null ? void 0 : _c.error) == null ? void 0 : _d.call(
1769
- _c,
1770
- `Tried to create atom "${options.key}",`,
1734
+ store.logger.error(
1735
+ `\u2753 Tried to create atom "${options.key}",`,
1771
1736
  `but it already exists in the store.`,
1772
- `(Ignore if you are using hot module replacement.)`
1737
+ `(Ignore if you are in development using hot module replacement.)`
1773
1738
  );
1774
1739
  return deposit(existing);
1775
1740
  }
@@ -1777,9 +1742,7 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
1777
1742
  const newAtom = __spreadValues(__spreadProps(__spreadValues({}, options), {
1778
1743
  type: `atom`,
1779
1744
  install: (store2) => {
1780
- var _a2, _b2;
1781
- (_b2 = (_a2 = store2.config.logger) == null ? void 0 : _a2.info) == null ? void 0 : _b2.call(
1782
- _a2,
1745
+ store2.logger.info(
1783
1746
  `\u{1F6E0}\uFE0F installing atom "${options.key}" in store "${store2.config.name}"`
1784
1747
  );
1785
1748
  return `mutable` in options ? createMutableAtom(options, store2) : createAtom(options, void 0, store2);
@@ -1791,7 +1754,7 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
1791
1754
  markAtomAsDefault(options.key, store);
1792
1755
  cacheValue(options.key, initialValue, subject, store);
1793
1756
  const token = deposit(newAtom);
1794
- for (const effect of (_e = options.effects) != null ? _e : []) {
1757
+ for (const effect of (_a = options.effects) != null ? _a : []) {
1795
1758
  effect({
1796
1759
  setSelf: (next) => setState(token, next, store),
1797
1760
  onSet: (handle) => subscribe(token, handle, `effect[${subject.subscribers.size}]`, store)
@@ -1802,21 +1765,23 @@ function createAtom(options, family, store = IMPLICIT.STORE) {
1802
1765
  }
1803
1766
 
1804
1767
  // src/atom/delete-atom.ts
1805
- function deleteAtom(key, core = IMPLICIT.STORE) {
1768
+ function deleteAtom(atomToken, store = IMPLICIT.STORE) {
1769
+ const core = target(store);
1770
+ const { key } = atomToken;
1806
1771
  core.atoms.delete(key);
1807
1772
  core.valueMap.delete(key);
1808
1773
  core.selectorAtoms.delete(key);
1809
1774
  core.atomsThatAreDefault.delete(key);
1810
1775
  core.timelineAtoms.delete(key);
1776
+ store.logger.info(`\u{1F525} Atom "${key}" deleted`);
1811
1777
  }
1812
1778
 
1813
1779
  // src/subscribe/recall-state.ts
1814
1780
  var recallState = (state, store = IMPLICIT.STORE) => {
1815
- var _a;
1816
1781
  const core = target(store);
1817
1782
  if (!core.operation.open) {
1818
- (_a = store.config.logger) == null ? void 0 : _a.warn(
1819
- `recall called outside of an operation. This is probably a bug.`
1783
+ store.logger.warn(
1784
+ `\u{1F41E}recall called outside of an operation. This is probably a bug.`
1820
1785
  );
1821
1786
  return core.valueMap.get(state.key);
1822
1787
  }
@@ -1825,19 +1790,18 @@ var recallState = (state, store = IMPLICIT.STORE) => {
1825
1790
 
1826
1791
  // src/subscribe/subscribe-to-root-atoms.ts
1827
1792
  var subscribeToRootAtoms = (state, store) => {
1828
- const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomToken) => {
1829
- const atom = withdraw(atomToken, store);
1793
+ const dependencySubscriptions = `default` in state ? null : traceAllSelectorAtoms(state.key, store).map((atomKey) => {
1794
+ const atom = store.atoms.get(atomKey);
1830
1795
  if (atom === void 0) {
1831
1796
  throw new Error(
1832
- `Atom "${atomToken.key}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1797
+ `Atom "${atomKey}", a dependency of selector "${state.key}", not found in store "${store.config.name}".`
1833
1798
  );
1834
1799
  }
1835
1800
  return atom.subject.subscribe(
1836
1801
  `${state.type}:${state.key}`,
1837
1802
  (atomChange) => {
1838
- var _a, _b;
1839
- (_a = store.config.logger) == null ? void 0 : _a.info(
1840
- `\u{1F4E2} selector "${state.key}" saw root "${atomToken.key}" go (`,
1803
+ store.logger.info(
1804
+ `\u{1F4E2} selector "${state.key}" saw root "${atomKey}" go (`,
1841
1805
  atomChange.oldValue,
1842
1806
  `->`,
1843
1807
  atomChange.newValue,
@@ -1845,8 +1809,8 @@ var subscribeToRootAtoms = (state, store) => {
1845
1809
  );
1846
1810
  const oldValue = recallState(state, store);
1847
1811
  const newValue = getState__INTERNAL(state, store);
1848
- (_b = store.config.logger) == null ? void 0 : _b.info(
1849
- ` <- "${state.key}" went (`,
1812
+ store.logger.info(
1813
+ `\u2728 "${state.key}" went (`,
1850
1814
  oldValue,
1851
1815
  `->`,
1852
1816
  newValue,
@@ -1859,6 +1823,6 @@ var subscribeToRootAtoms = (state, store) => {
1859
1823
  return dependencySubscriptions;
1860
1824
  };
1861
1825
 
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, isTransceiver, isValueCached, lookup, lookupSelectorSources, 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 };
1826
+ 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
1827
  //# sourceMappingURL=out.js.map
1864
1828
  //# sourceMappingURL=index.mjs.map