atom.io 0.32.1 → 0.32.3

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 (47) hide show
  1. package/README.md +17 -37
  2. package/data/dist/index.js +1 -1
  3. package/dist/{chunk-X7SD2NXU.js → chunk-2XDFCXGB.js} +5 -4
  4. package/dist/{chunk-UQEYZ3OI.js → chunk-35NB2XZU.js} +108 -110
  5. package/dist/{chunk-3ZFTRSNG.js → chunk-EF4S7H42.js} +6 -3
  6. package/dist/{chunk-KVI5OBF2.js → chunk-LTLDKXDN.js} +3 -3
  7. package/dist/{chunk-3PQTWLQQ.js → chunk-MENOYVPP.js} +1 -1
  8. package/dist/{chunk-VRJP2PCU.js → chunk-RGUNRT72.js} +43 -40
  9. package/dist/{chunk-UYYKOGZQ.js → chunk-TS76LQVD.js} +8 -7
  10. package/dist/index.d.ts +2 -2
  11. package/dist/index.js +1 -1
  12. package/internal/dist/index.d.ts +8 -5
  13. package/internal/dist/index.js +1 -1
  14. package/internal/src/get-state/read-or-compute-value.ts +23 -13
  15. package/internal/src/index.ts +2 -1
  16. package/internal/src/ingest-updates/ingest-creation-disposal.ts +0 -12
  17. package/internal/src/lazy-map.ts +3 -1
  18. package/internal/src/reserved-keys.ts +7 -0
  19. package/internal/src/set-state/copy-mutable-if-needed.ts +12 -11
  20. package/internal/src/set-state/set-atom-or-selector.ts +1 -1
  21. package/internal/src/set-state/set-atom.ts +43 -21
  22. package/internal/src/store/store.ts +2 -1
  23. package/internal/src/transaction/get-epoch-number.ts +15 -19
  24. package/internal/src/transaction/set-epoch-number.ts +2 -2
  25. package/introspection/dist/index.js +2 -2
  26. package/introspection/src/attach-atom-index.ts +16 -14
  27. package/introspection/src/attach-selector-index.ts +16 -14
  28. package/introspection/src/auditor.ts +3 -3
  29. package/json/dist/index.js +1 -1
  30. package/package.json +19 -17
  31. package/react/dist/index.js +2 -2
  32. package/react-devtools/dist/index.js +78 -66
  33. package/react-devtools/src/AtomIODevtools.tsx +10 -2
  34. package/react-devtools/src/error-boundary/ReactErrorBoundary.tsx +1 -1
  35. package/realtime/dist/index.d.ts +1 -1
  36. package/realtime/dist/index.js +2 -2
  37. package/realtime/src/realtime-continuity.ts +4 -1
  38. package/realtime-client/dist/index.js +2 -2
  39. package/realtime-client/src/continuity/register-and-attempt-confirmed-update.ts +5 -2
  40. package/realtime-react/dist/index.js +4 -4
  41. package/realtime-server/dist/index.d.ts +1 -1
  42. package/realtime-server/dist/index.js +3 -3
  43. package/realtime-server/src/ipc-sockets/custom-socket.ts +6 -1
  44. package/realtime-testing/dist/index.js +6 -6
  45. package/src/logger.ts +12 -4
  46. package/transceivers/set-rtx/dist/index.js +1 -1
  47. package/internal/src/set-state/stow-update.ts +0 -60
@@ -1,7 +1,7 @@
1
1
  import { persistSync } from '../../dist/chunk-4LWKCEW3.js';
2
- import { attachIntrospectionStates, jsonRefinery, primitiveRefinery, discoverType, prettyJson } from '../../dist/chunk-VRJP2PCU.js';
3
- import { StoreContext, useI, useO } from '../../dist/chunk-3PQTWLQQ.js';
4
- import { IMPLICIT, createStandaloneAtom, createAtomFamily, fromEntries, become, isJson, toEntries, JSON_DEFAULTS, findInStore, undo, redo, getState, stringifyJson } from '../../dist/chunk-UQEYZ3OI.js';
2
+ import { attachIntrospectionStates, jsonRefinery, primitiveRefinery, discoverType, prettyJson } from '../../dist/chunk-RGUNRT72.js';
3
+ import { StoreContext, useI, useO } from '../../dist/chunk-MENOYVPP.js';
4
+ import { IMPLICIT, createStandaloneAtom, createAtomFamily, fromEntries, become, isJson, toEntries, JSON_DEFAULTS, findInStore, undo, redo, getState, stringifyJson } from '../../dist/chunk-35NB2XZU.js';
5
5
  import '../../dist/chunk-XWL6SNVU.js';
6
6
  import { motion, spring, LayoutGroup } from 'motion/react';
7
7
  import { forwardRef, useRef, useState, useImperativeHandle, useLayoutEffect, createContext, useId, Component, useContext, Fragment as Fragment$1 } from 'react';
@@ -1396,74 +1396,86 @@ var AtomIODevtoolsInternal = () => {
1396
1396
  const devtoolsView = useO(devtoolsViewSelectionState);
1397
1397
  const devtoolsViewOptions = useO(devtoolsViewOptionsState);
1398
1398
  const mouseHasMoved = useRef(false);
1399
- return /* @__PURE__ */ jsxs(Fragment, { children: [
1400
- /* @__PURE__ */ jsx(
1401
- motion.span,
1402
- {
1403
- ref: constraintsRef,
1404
- "data-css": "atom_io_devtools_zone",
1405
- style: {
1406
- position: `fixed`,
1407
- top: 0,
1408
- left: 0,
1409
- right: 0,
1410
- bottom: 0,
1411
- pointerEvents: `none`
1412
- }
1413
- }
1414
- ),
1415
- /* @__PURE__ */ jsxs(
1416
- motion.main,
1417
- {
1418
- drag: true,
1419
- dragConstraints: constraintsRef,
1420
- "data-css": "atom_io_devtools",
1421
- transition: spring,
1422
- style: devtoolsAreOpen ? {} : {
1423
- backgroundColor: `#0000`,
1424
- borderColor: `#0000`,
1425
- maxHeight: 28,
1426
- maxWidth: 33
1427
- },
1428
- children: [
1429
- devtoolsAreOpen ? /* @__PURE__ */ jsxs(Fragment, { children: [
1430
- /* @__PURE__ */ jsxs(motion.header, { children: [
1431
- /* @__PURE__ */ jsx("h1", { children: "atom.io" }),
1432
- /* @__PURE__ */ jsx("nav", { children: devtoolsViewOptions.map((viewOption) => /* @__PURE__ */ jsx(
1399
+ return /* @__PURE__ */ jsxs(
1400
+ "span",
1401
+ {
1402
+ style: {
1403
+ position: `fixed`,
1404
+ top: 0,
1405
+ left: 0,
1406
+ right: 0,
1407
+ bottom: 0
1408
+ },
1409
+ children: [
1410
+ /* @__PURE__ */ jsx(
1411
+ motion.span,
1412
+ {
1413
+ ref: constraintsRef,
1414
+ "data-css": "atom_io_devtools_zone",
1415
+ style: {
1416
+ position: `fixed`,
1417
+ top: 0,
1418
+ left: 0,
1419
+ right: 0,
1420
+ bottom: 0,
1421
+ pointerEvents: `none`
1422
+ }
1423
+ }
1424
+ ),
1425
+ /* @__PURE__ */ jsxs(
1426
+ motion.main,
1427
+ {
1428
+ drag: true,
1429
+ dragConstraints: constraintsRef,
1430
+ "data-css": "atom_io_devtools",
1431
+ transition: spring,
1432
+ style: devtoolsAreOpen ? {} : {
1433
+ backgroundColor: `#0000`,
1434
+ borderColor: `#0000`,
1435
+ maxHeight: 28,
1436
+ maxWidth: 33
1437
+ },
1438
+ children: [
1439
+ devtoolsAreOpen ? /* @__PURE__ */ jsxs(Fragment, { children: [
1440
+ /* @__PURE__ */ jsxs(motion.header, { children: [
1441
+ /* @__PURE__ */ jsx("h1", { children: "atom.io" }),
1442
+ /* @__PURE__ */ jsx("nav", { children: devtoolsViewOptions.map((viewOption) => /* @__PURE__ */ jsx(
1443
+ "button",
1444
+ {
1445
+ type: "button",
1446
+ "data-testid": `view-${viewOption}`,
1447
+ className: viewOption === devtoolsView ? `active` : ``,
1448
+ onClick: () => {
1449
+ setDevtoolsView(viewOption);
1450
+ },
1451
+ disabled: viewOption === devtoolsView,
1452
+ children: viewOption
1453
+ },
1454
+ viewOption
1455
+ )) })
1456
+ ] }),
1457
+ /* @__PURE__ */ jsx(motion.main, { children: /* @__PURE__ */ jsx(LayoutGroup, { children: devtoolsView === `atoms` ? /* @__PURE__ */ jsx(StateIndex, { tokenIndex: atomIndex }) : devtoolsView === `selectors` ? /* @__PURE__ */ jsx(StateIndex, { tokenIndex: selectorIndex }) : devtoolsView === `transactions` ? /* @__PURE__ */ jsx(TransactionIndex, {}) : /* @__PURE__ */ jsx(TimelineIndex, {}) }) })
1458
+ ] }) : null,
1459
+ /* @__PURE__ */ jsx("footer", { children: /* @__PURE__ */ jsx(
1433
1460
  "button",
1434
1461
  {
1435
1462
  type: "button",
1436
- "data-testid": `view-${viewOption}`,
1437
- className: viewOption === devtoolsView ? `active` : ``,
1438
- onClick: () => {
1439
- setDevtoolsView(viewOption);
1463
+ onMouseDown: () => mouseHasMoved.current = false,
1464
+ onMouseMove: () => mouseHasMoved.current = true,
1465
+ onMouseUp: () => {
1466
+ if (!mouseHasMoved.current) {
1467
+ setDevtoolsAreOpen((open) => !open);
1468
+ }
1440
1469
  },
1441
- disabled: viewOption === devtoolsView,
1442
- children: viewOption
1443
- },
1444
- viewOption
1445
- )) })
1446
- ] }),
1447
- /* @__PURE__ */ jsx(motion.main, { children: /* @__PURE__ */ jsx(LayoutGroup, { children: devtoolsView === `atoms` ? /* @__PURE__ */ jsx(StateIndex, { tokenIndex: atomIndex }) : devtoolsView === `selectors` ? /* @__PURE__ */ jsx(StateIndex, { tokenIndex: selectorIndex }) : devtoolsView === `transactions` ? /* @__PURE__ */ jsx(TransactionIndex, {}) : /* @__PURE__ */ jsx(TimelineIndex, {}) }) })
1448
- ] }) : null,
1449
- /* @__PURE__ */ jsx("footer", { children: /* @__PURE__ */ jsx(
1450
- "button",
1451
- {
1452
- type: "button",
1453
- onMouseDown: () => mouseHasMoved.current = false,
1454
- onMouseMove: () => mouseHasMoved.current = true,
1455
- onMouseUp: () => {
1456
- if (!mouseHasMoved.current) {
1457
- setDevtoolsAreOpen((open) => !open);
1470
+ children: "\u{1F50D}"
1458
1471
  }
1459
- },
1460
- children: "\u{1F50D}"
1461
- }
1462
- ) })
1463
- ]
1464
- }
1465
- )
1466
- ] });
1472
+ ) })
1473
+ ]
1474
+ }
1475
+ )
1476
+ ]
1477
+ }
1478
+ );
1467
1479
  };
1468
1480
 
1469
1481
  export { AtomIODevtools, DEFAULT_JSON_EDITOR_COMPONENTS, DEFAULT_NUMBER_CONSTRAINTS, DefaultFallback, ElasticInput, ErrorBoundary, JsonEditor, NumberInput, SubEditors, TextInput, VALID_NON_NUMBERS, VALID_NON_NUMBER_INTERPRETATIONS, castToJson, clampInto, isDecimalInProgress, isValidNonNumber };
@@ -38,7 +38,15 @@ const AtomIODevtoolsInternal = (): React.ReactNode => {
38
38
  const mouseHasMoved = useRef(false)
39
39
 
40
40
  return (
41
- <>
41
+ <span
42
+ style={{
43
+ position: `fixed`,
44
+ top: 0,
45
+ left: 0,
46
+ right: 0,
47
+ bottom: 0,
48
+ }}
49
+ >
42
50
  <motion.span
43
51
  ref={constraintsRef}
44
52
  data-css="atom_io_devtools_zone"
@@ -118,6 +126,6 @@ const AtomIODevtoolsInternal = (): React.ReactNode => {
118
126
  </button>
119
127
  </footer>
120
128
  </motion.main>
121
- </>
129
+ </span>
122
130
  )
123
131
  }
@@ -1,5 +1,5 @@
1
1
  import type { ErrorInfo, FC, ReactNode } from "react"
2
- import { Component, useState } from "react"
2
+ import { Component } from "react"
3
3
 
4
4
  import type { FallbackProps } from "./DefaultFallback"
5
5
  import { DefaultFallback } from "./DefaultFallback"
@@ -21,11 +21,11 @@ type ContinuityToken = {
21
21
  readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[];
22
22
  };
23
23
  declare class SyncGroup {
24
- protected readonly key: string;
25
24
  type: "continuity";
26
25
  protected globals: AtomToken<any>[];
27
26
  protected actions: TransactionToken<any>[];
28
27
  protected perspectives: PerspectiveToken<any>[];
28
+ protected readonly key: string;
29
29
  protected constructor(key: string);
30
30
  static existing: InvariantMap<string, ContinuityToken>;
31
31
  static create(key: string, builder: (group: SyncGroup) => SyncGroup): ContinuityToken;
@@ -1,3 +1,3 @@
1
- export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex } from '../../dist/chunk-X7SD2NXU.js';
2
- import '../../dist/chunk-UQEYZ3OI.js';
1
+ export { DEFAULT_USER_IN_ROOM_META, InvariantMap, SyncGroup, continuity, roomIndex, usersInMyRoomView, usersInRooms, usersInThisRoomIndex } from '../../dist/chunk-2XDFCXGB.js';
2
+ import '../../dist/chunk-35NB2XZU.js';
3
3
  import '../../dist/chunk-XWL6SNVU.js';
@@ -53,8 +53,11 @@ export class SyncGroup {
53
53
  protected globals: AtomToken<any>[] = []
54
54
  protected actions: TransactionToken<any>[] = []
55
55
  protected perspectives: PerspectiveToken<any>[] = []
56
+ protected readonly key: string
56
57
 
57
- protected constructor(protected readonly key: string) {}
58
+ protected constructor(key: string) {
59
+ this.key = key
60
+ }
58
61
 
59
62
  public static existing: InvariantMap<string, ContinuityToken> =
60
63
  new InvariantMap()
@@ -1,4 +1,4 @@
1
- export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState } from '../../dist/chunk-3ZFTRSNG.js';
1
+ export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity, useConcealState, useRegisterAndAttemptConfirmedUpdate, useRevealState } from '../../dist/chunk-EF4S7H42.js';
2
2
  import '../../dist/chunk-4LWKCEW3.js';
3
- import '../../dist/chunk-UQEYZ3OI.js';
3
+ import '../../dist/chunk-35NB2XZU.js';
4
4
  import '../../dist/chunk-XWL6SNVU.js';
@@ -177,10 +177,13 @@ export const useRegisterAndAttemptConfirmedUpdate =
177
177
  continuityKey,
178
178
  `has no optimistic updates to deal with`,
179
179
  )
180
- const continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
181
180
  const isRoot = isRootStore(store)
181
+ let continuityEpoch: number | undefined
182
+ if (isRoot) {
183
+ continuityEpoch = getEpochNumberOfContinuity(store, continuityKey)
184
+ }
182
185
 
183
- if (isRoot && continuityEpoch === confirmed.epoch - 1) {
186
+ if (continuityEpoch === confirmed.epoch - 1) {
184
187
  store.logger.info(
185
188
  `✅`,
186
189
  `continuity`,
@@ -1,6 +1,6 @@
1
- export { RealtimeContext, RealtimeProvider, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity } from '../../dist/chunk-KVI5OBF2.js';
2
- import '../../dist/chunk-3ZFTRSNG.js';
1
+ export { RealtimeContext, RealtimeProvider, usePullAtom, usePullAtomFamilyMember, usePullMutable, usePullMutableAtomFamilyMember, usePullSelector, usePullSelectorFamilyMember, usePush, useServerAction, useSyncContinuity } from '../../dist/chunk-LTLDKXDN.js';
2
+ import '../../dist/chunk-EF4S7H42.js';
3
3
  import '../../dist/chunk-4LWKCEW3.js';
4
- import '../../dist/chunk-3PQTWLQQ.js';
5
- import '../../dist/chunk-UQEYZ3OI.js';
4
+ import '../../dist/chunk-MENOYVPP.js';
5
+ import '../../dist/chunk-35NB2XZU.js';
6
6
  import '../../dist/chunk-XWL6SNVU.js';
@@ -15,11 +15,11 @@ interface EventBuffer<Key extends string, Params extends Json.Serializable[]> ex
15
15
  toString(): StringifiedEvent<Key, Params>;
16
16
  }
17
17
  declare class CustomSocket<I extends Events, O extends Events> implements Socket {
18
- emit: <Event extends keyof I>(event: Event, ...args: I[Event]) => CustomSocket<I, O>;
19
18
  protected listeners: Map<keyof O, Set<(...args: Json.Array) => void>>;
20
19
  protected globalListeners: Set<(event: string, ...args: Json.Array) => void>;
21
20
  protected handleEvent<Event extends keyof I>(event: string, ...args: I[Event]): void;
22
21
  id: string;
22
+ emit: <Event extends keyof I>(event: Event, ...args: I[Event]) => CustomSocket<I, O>;
23
23
  constructor(emit: <Event extends keyof I>(event: Event, ...args: I[Event]) => CustomSocket<I, O>);
24
24
  on<Event extends keyof O>(event: Event, listener: (...args: O[Event]) => void): this;
25
25
  onAny(listener: (event: string, ...args: Json.Array) => void): this;
@@ -1,4 +1,4 @@
1
- export { ChildSocket, CustomSocket, ParentSocket, SubjectSocket, createRoomTX, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToExposeRealtimeContinuity, realtimeActionReceiver, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, redactTransactionUpdateContent, redactorAtoms, roomArgumentsAtoms, roomSelectors, socketAtoms, socketIndex, userIndex, userUnacknowledgedQueues, usersOfSockets } from '../../dist/chunk-UYYKOGZQ.js';
2
- import '../../dist/chunk-X7SD2NXU.js';
3
- import '../../dist/chunk-UQEYZ3OI.js';
1
+ export { ChildSocket, CustomSocket, ParentSocket, SubjectSocket, createRoomTX, destroyRoomTX, joinRoomTX, leaveRoomTX, prepareToExposeRealtimeContinuity, realtimeActionReceiver, realtimeAtomFamilyProvider, realtimeMutableFamilyProvider, realtimeMutableProvider, realtimeStateProvider, realtimeStateReceiver, redactTransactionUpdateContent, redactorAtoms, roomArgumentsAtoms, roomSelectors, socketAtoms, socketIndex, userIndex, userUnacknowledgedQueues, usersOfSockets } from '../../dist/chunk-TS76LQVD.js';
2
+ import '../../dist/chunk-2XDFCXGB.js';
3
+ import '../../dist/chunk-35NB2XZU.js';
4
4
  import '../../dist/chunk-XWL6SNVU.js';
@@ -35,13 +35,18 @@ export class CustomSocket<I extends Events, O extends Events> implements Socket
35
35
  }
36
36
 
37
37
  public id = `no_id_retrieved`
38
+ public emit: <Event extends keyof I>(
39
+ event: Event,
40
+ ...args: I[Event]
41
+ ) => CustomSocket<I, O>
38
42
 
39
43
  public constructor(
40
- public emit: <Event extends keyof I>(
44
+ emit: <Event extends keyof I>(
41
45
  event: Event,
42
46
  ...args: I[Event]
43
47
  ) => CustomSocket<I, O>,
44
48
  ) {
49
+ this.emit = emit
45
50
  this.listeners = new Map()
46
51
  this.globalListeners = new Set()
47
52
  }
@@ -1,10 +1,10 @@
1
- import { RealtimeProvider } from '../../dist/chunk-KVI5OBF2.js';
2
- import { myUsernameState } from '../../dist/chunk-3ZFTRSNG.js';
3
- import { socketAtoms, usersOfSockets, userIndex, socketIndex, roomSelectors } from '../../dist/chunk-UYYKOGZQ.js';
4
- import { roomIndex } from '../../dist/chunk-X7SD2NXU.js';
1
+ import { RealtimeProvider } from '../../dist/chunk-LTLDKXDN.js';
2
+ import { myUsernameState } from '../../dist/chunk-EF4S7H42.js';
3
+ import { socketAtoms, usersOfSockets, userIndex, socketIndex, roomSelectors } from '../../dist/chunk-TS76LQVD.js';
4
+ import { roomIndex } from '../../dist/chunk-2XDFCXGB.js';
5
5
  import '../../dist/chunk-4LWKCEW3.js';
6
- import { StoreProvider } from '../../dist/chunk-3PQTWLQQ.js';
7
- import { Silo, IMPLICIT, Realm, findInStore, setIntoStore, editRelationsInStore, toEntries, findRelationsInStore, getFromStore, clearStore, AtomIOLogger } from '../../dist/chunk-UQEYZ3OI.js';
6
+ import { StoreProvider } from '../../dist/chunk-MENOYVPP.js';
7
+ import { Silo, IMPLICIT, Realm, findInStore, setIntoStore, editRelationsInStore, toEntries, findRelationsInStore, getFromStore, clearStore, AtomIOLogger } from '../../dist/chunk-35NB2XZU.js';
8
8
  import '../../dist/chunk-XWL6SNVU.js';
9
9
  import * as http from 'node:http';
10
10
  import { render, prettyDOM } from '@testing-library/react';
package/src/logger.ts CHANGED
@@ -98,11 +98,19 @@ export const simpleLogger: Logger = {
98
98
  }
99
99
 
100
100
  export class AtomIOLogger implements Logger {
101
+ public logLevel: `error` | `info` | `warn` | null
102
+ private readonly filter: LogFilter | undefined
103
+ private readonly logger: Logger
104
+
101
105
  public constructor(
102
- public logLevel: `error` | `info` | `warn` | null,
103
- private readonly filter?: LogFilter,
104
- private readonly logger: Logger = simpleLogger,
105
- ) {}
106
+ logLevel: `error` | `info` | `warn` | null,
107
+ filter?: LogFilter,
108
+ logger: Logger = simpleLogger,
109
+ ) {
110
+ this.logLevel = logLevel
111
+ this.filter = filter
112
+ this.logger = logger
113
+ }
106
114
 
107
115
  public error: LogFn = (...args) => {
108
116
  if ((this.filter?.(...args) ?? true) && this.logLevel !== null) {
@@ -1,2 +1,2 @@
1
- export { SetRTX } from '../../../dist/chunk-UQEYZ3OI.js';
1
+ export { SetRTX } from '../../../dist/chunk-35NB2XZU.js';
2
2
  import '../../../dist/chunk-XWL6SNVU.js';
@@ -1,60 +0,0 @@
1
- import type { KeyedStateUpdate, StateUpdate } from "atom.io"
2
-
3
- import type { Atom } from ".."
4
- import { newest } from "../lineage"
5
- import { isTransceiver } from "../mutable"
6
- import type { Store } from "../store"
7
- import { isChildStore } from "../transaction/is-root-store"
8
-
9
- function shouldUpdateBeStowed(key: string, update: StateUpdate<any>): boolean {
10
- // do not stow updates that aren't json
11
- if (isTransceiver(update.newValue)) {
12
- return false
13
- }
14
- // do not stow updates where the key contains 🔍
15
- if (key.includes(`🔍`)) {
16
- return false
17
- }
18
- return true
19
- }
20
-
21
- export const stowUpdate = <T>(
22
- store: Store,
23
- state: Atom<T>,
24
- update: StateUpdate<T>,
25
- ): void => {
26
- const { key } = state
27
- const target = newest(store)
28
- if (!isChildStore(target) || target.transactionMeta.phase !== `building`) {
29
- store.logger.error(
30
- `🐞`,
31
- `atom`,
32
- key,
33
- `stowUpdate called outside of a transaction. This is probably a bug.`,
34
- )
35
- return
36
- }
37
- const shouldStow = shouldUpdateBeStowed(key, update)
38
- if (!shouldStow) {
39
- return
40
- }
41
- const atomUpdate: KeyedStateUpdate<T> = {
42
- type: `atom_update`,
43
- key,
44
- ...update,
45
- }
46
- if (state.family) {
47
- atomUpdate.family = state.family
48
- }
49
- target.transactionMeta.update.updates.push(atomUpdate)
50
- store.logger.info(
51
- `📁`,
52
- `atom`,
53
- key,
54
- `stowed (`,
55
- update.oldValue,
56
- `->`,
57
- update.newValue,
58
- `)`,
59
- )
60
- }