atom.io 0.27.5 → 0.28.1

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 (73) hide show
  1. package/data/dist/index.d.ts +31 -29
  2. package/data/dist/index.js +16 -17
  3. package/data/src/join.ts +17 -19
  4. package/dist/{chunk-6ABWLAGY.js → chunk-6WL4RQMQ.js} +314 -249
  5. package/dist/chunk-D52JNVER.js +721 -0
  6. package/dist/chunk-YQ46F5O2.js +95 -0
  7. package/dist/index.d.ts +1 -0
  8. package/dist/index.js +3 -1
  9. package/internal/dist/index.d.ts +72 -36
  10. package/internal/dist/index.js +1 -1
  11. package/internal/src/atom/dispose-atom.ts +2 -9
  12. package/internal/src/families/dispose-from-store.ts +29 -18
  13. package/internal/src/families/find-in-store.ts +17 -7
  14. package/internal/src/get-state/get-from-store.ts +41 -32
  15. package/internal/src/ingest-updates/ingest-creation-disposal.ts +10 -1
  16. package/internal/src/molecule/dispose-molecule.ts +6 -17
  17. package/internal/src/pretty-print.ts +1 -16
  18. package/internal/src/selector/dispose-selector.ts +2 -9
  19. package/internal/src/set-state/set-into-store.ts +17 -19
  20. package/internal/src/store/circular-buffer.ts +34 -0
  21. package/internal/src/store/counterfeit.ts +109 -0
  22. package/internal/src/store/deposit.ts +14 -0
  23. package/internal/src/store/index.ts +1 -0
  24. package/internal/src/store/store.ts +3 -0
  25. package/internal/src/store/withdraw.ts +15 -10
  26. package/internal/src/transaction/build-transaction.ts +1 -0
  27. package/introspection/dist/index.d.ts +84 -4
  28. package/introspection/dist/index.js +1 -392
  29. package/introspection/src/attach-introspection-states.ts +7 -4
  30. package/introspection/src/attach-type-selectors.ts +26 -0
  31. package/introspection/src/differ.ts +167 -0
  32. package/introspection/src/index.ts +2 -0
  33. package/introspection/src/refinery.ts +100 -0
  34. package/json/dist/index.d.ts +31 -30
  35. package/json/dist/index.js +2 -77
  36. package/json/src/entries.ts +6 -0
  37. package/json/src/index.ts +53 -6
  38. package/package.json +18 -9
  39. package/react-devtools/dist/index.d.ts +1 -91
  40. package/react-devtools/dist/index.js +285 -414
  41. package/react-devtools/src/AtomIODevtools.tsx +2 -2
  42. package/react-devtools/src/StateEditor.tsx +20 -12
  43. package/react-devtools/src/StateIndex.tsx +10 -27
  44. package/react-devtools/src/TimelineIndex.tsx +3 -3
  45. package/react-devtools/src/TransactionIndex.tsx +6 -6
  46. package/react-devtools/src/Updates.tsx +2 -3
  47. package/react-devtools/src/index.ts +0 -71
  48. package/react-devtools/src/store.ts +51 -0
  49. package/realtime/dist/index.d.ts +7 -7
  50. package/realtime/dist/index.js +18 -22
  51. package/realtime/src/realtime-continuity.ts +30 -37
  52. package/realtime-client/dist/index.js +24 -10
  53. package/realtime-client/src/pull-atom-family-member.ts +2 -0
  54. package/realtime-client/src/pull-mutable-atom-family-member.ts +2 -0
  55. package/realtime-client/src/pull-selector-family-member.ts +2 -0
  56. package/realtime-client/src/realtime-client-stores/client-main-store.ts +6 -6
  57. package/realtime-client/src/sync-continuity.ts +28 -6
  58. package/realtime-server/dist/index.js +41 -5
  59. package/realtime-server/src/ipc-sockets/child-socket.ts +2 -0
  60. package/realtime-server/src/realtime-continuity-synchronizer.ts +42 -78
  61. package/realtime-testing/dist/index.d.ts +2 -0
  62. package/realtime-testing/dist/index.js +50 -8
  63. package/realtime-testing/src/setup-realtime-test.tsx +61 -9
  64. package/src/logger.ts +1 -0
  65. package/src/silo.ts +7 -3
  66. package/transceivers/set-rtx/src/set-rtx.ts +1 -0
  67. package/web/dist/index.d.ts +9 -0
  68. package/{dist/chunk-H6EDLPKH.js → web/dist/index.js} +5 -4
  69. package/web/package.json +13 -0
  70. package/web/src/index.ts +1 -0
  71. package/web/src/persist-sync.ts +25 -0
  72. package/dist/chunk-AK23DRMD.js +0 -21
  73. package/dist/chunk-IW6WYRS7.js +0 -140
@@ -4,14 +4,14 @@ import { useI, useO } from "atom.io/react"
4
4
  import { LayoutGroup, motion, spring } from "framer-motion"
5
5
  import { useRef } from "react"
6
6
 
7
+ import { StateIndex } from "./StateIndex"
7
8
  import {
8
9
  atomIndex,
9
10
  devtoolsAreOpenState,
10
11
  devtoolsViewOptionsState,
11
12
  devtoolsViewSelectionState,
12
13
  selectorIndex,
13
- } from "."
14
- import { StateIndex } from "./StateIndex"
14
+ } from "./store"
15
15
  import { TimelineIndex } from "./TimelineIndex"
16
16
  import { TransactionIndex } from "./TransactionIndex"
17
17
 
@@ -1,12 +1,19 @@
1
1
  import type { ReadonlySelectorToken, WritableToken } from "atom.io"
2
+ import { isJson } from "atom.io/json"
2
3
  import { useI, useO } from "atom.io/react"
3
4
  import type { FC } from "react"
4
5
 
5
- import { fallback } from "~/packages/anvl/src/function"
6
- import { isJson } from "~/packages/anvl/src/refinement"
7
6
  import { ElasticInput } from "~/packages/hamr/react-elastic-input/src"
8
7
  import { JsonEditor } from "~/packages/hamr/react-json-editor/src"
9
8
 
9
+ export const fallback = <T,>(fn: () => T, fallbackValue: T): T => {
10
+ try {
11
+ return fn()
12
+ } catch (_) {
13
+ return fallbackValue
14
+ }
15
+ }
16
+
10
17
  export const StateEditor: FC<{
11
18
  token: WritableToken<unknown>
12
19
  }> = ({ token }) => {
@@ -18,16 +25,17 @@ export const StateEditor: FC<{
18
25
  <div className="json_editor">
19
26
  <ElasticInput
20
27
  value={
21
- data !== null &&
22
- typeof data === `object` &&
23
- `toJson` in data &&
24
- typeof data.toJson === `function`
25
- ? JSON.stringify(data.toJson())
26
- : data instanceof Set
27
- ? `Set { ${JSON.stringify([...data]).slice(1, -1)} }`
28
- : Object.getPrototypeOf(data).constructor.name +
29
- ` ` +
30
- fallback(() => JSON.stringify(data), `?`)
28
+ data === undefined || data === null
29
+ ? ``
30
+ : typeof data === `object` &&
31
+ `toJson` in data &&
32
+ typeof data.toJson === `function`
33
+ ? JSON.stringify(data.toJson())
34
+ : data instanceof Set
35
+ ? `Set { ${JSON.stringify([...data]).slice(1, -1)} }`
36
+ : Object.getPrototypeOf(data).constructor.name +
37
+ ` ` +
38
+ fallback(() => JSON.stringify(data), `?`)
31
39
  }
32
40
  disabled={true}
33
41
  />
@@ -3,35 +3,18 @@ import type {
3
3
  ReadonlySelectorToken,
4
4
  RegularAtomToken,
5
5
  } from "atom.io"
6
- import { getState, selectorFamily } from "atom.io"
6
+ import { getState } from "atom.io"
7
7
  import { findState } from "atom.io/ephemeral"
8
8
  import type { FamilyNode, WritableTokenIndex } from "atom.io/introspection"
9
- import type { Canonical } from "atom.io/json"
9
+ import { primitiveRefinery } from "atom.io/introspection"
10
10
  import { useI, useO } from "atom.io/react"
11
11
  import type { FC } from "react"
12
12
 
13
- import { isJson, refineJsonType } from "~/packages/anvl/src/refinement"
14
-
15
- import { findViewIsOpenState, primitiveRefinery } from "."
16
13
  import { button } from "./Button"
17
14
  import { StoreEditor } from "./StateEditor"
15
+ import { typeSelectors, viewIsOpenAtoms } from "./store"
18
16
 
19
- const findStateTypeState = selectorFamily<string, Canonical>({
20
- key: `👁‍🗨 State Type`,
21
- get:
22
- (token) =>
23
- ({ get }) => {
24
- let state: unknown
25
- try {
26
- state = get(token as any)
27
- } catch (error) {
28
- return `error`
29
- }
30
- if (state === undefined) return `undefined`
31
- if (isJson(state)) return refineJsonType(state).type
32
- return Object.getPrototypeOf(state).constructor.name
33
- },
34
- })
17
+ /* eslint-disable no-console */
35
18
 
36
19
  export const StateIndexLeafNode: FC<{
37
20
  node: ReadableToken<unknown>
@@ -83,8 +66,8 @@ export const StateIndexTreeNode: FC<{
83
66
  const setIsOpen = useI(isOpenState)
84
67
  const isOpen = useO(isOpenState)
85
68
  for (const [key, childNode] of node.familyMembers) {
86
- findState(findViewIsOpenState, key)
87
- findState(findStateTypeState, childNode.key)
69
+ findState(viewIsOpenAtoms, key)
70
+ findState(typeSelectors, childNode.key)
88
71
  }
89
72
  return (
90
73
  <>
@@ -104,8 +87,8 @@ export const StateIndexTreeNode: FC<{
104
87
  <StateIndexNode
105
88
  key={key}
106
89
  node={childNode}
107
- isOpenState={findState(findViewIsOpenState, childNode.key)}
108
- typeState={findState(findStateTypeState, childNode.key)}
90
+ isOpenState={findState(viewIsOpenAtoms, childNode.key)}
91
+ typeState={findState(typeSelectors, childNode.key)}
109
92
  />
110
93
  ))
111
94
  : null}
@@ -147,8 +130,8 @@ export const StateIndex: FC<{
147
130
  <StateIndexNode
148
131
  key={key}
149
132
  node={node}
150
- isOpenState={findState(findViewIsOpenState, node.key)}
151
- typeState={findState(findStateTypeState, node.key)}
133
+ isOpenState={findState(viewIsOpenAtoms, node.key)}
134
+ typeState={findState(typeSelectors, node.key)}
152
135
  />
153
136
  )
154
137
  })}
@@ -9,8 +9,8 @@ import type { Timeline } from "atom.io/internal"
9
9
  import { useI, useO } from "atom.io/react"
10
10
  import { type FC, Fragment } from "react"
11
11
 
12
- import { findTimelineState, findViewIsOpenState, timelineIndex } from "."
13
12
  import { button } from "./Button"
13
+ import { timelineIndex, timelineSelectors, viewIsOpenAtoms } from "./store"
14
14
  import { article } from "./Updates"
15
15
 
16
16
  export const YouAreHere: FC = () => {
@@ -96,8 +96,8 @@ export const TimelineIndex: FC = () => {
96
96
  <TimelineLog
97
97
  key={token.key}
98
98
  token={token}
99
- isOpenState={findState(findViewIsOpenState, token.key)}
100
- timelineState={findState(findTimelineState, token.key)}
99
+ isOpenState={findState(viewIsOpenAtoms, token.key)}
100
+ timelineState={findState(timelineSelectors, token.key)}
101
101
  />
102
102
  )
103
103
  })}
@@ -9,12 +9,12 @@ import type { Func } from "atom.io/internal"
9
9
  import { useI, useO } from "atom.io/react"
10
10
  import type { FC } from "react"
11
11
 
12
+ import { button } from "./Button"
12
13
  import {
13
- findTransactionLogState,
14
- findViewIsOpenState,
15
14
  transactionIndex,
16
- } from "."
17
- import { button } from "./Button"
15
+ transactionLogSelectors,
16
+ viewIsOpenAtoms,
17
+ } from "./store"
18
18
  import { article } from "./Updates"
19
19
 
20
20
  export const TransactionLog: FC<{
@@ -68,8 +68,8 @@ export const TransactionIndex: FC = () => {
68
68
  <TransactionLog
69
69
  key={token.key}
70
70
  token={token}
71
- isOpenState={findState(findViewIsOpenState, token.key)}
72
- logState={findState(findTransactionLogState, token.key)}
71
+ isOpenState={findState(viewIsOpenAtoms, token.key)}
72
+ logState={findState(transactionLogSelectors, token.key)}
73
73
  />
74
74
  )
75
75
  })}
@@ -4,11 +4,10 @@ import type {
4
4
  TransactionUpdate,
5
5
  } from "atom.io"
6
6
  import type { Func } from "atom.io/internal"
7
+ import { discoverType, prettyJson } from "atom.io/introspection"
7
8
  import * as React from "react"
8
9
 
9
- import { discoverType } from "~/packages/anvl/src/refinement/refinery"
10
-
11
- import { prettyJson } from "."
10
+ /* eslint-disable no-console */
12
11
 
13
12
  const AtomUpdateFC: React.FC<{
14
13
  serialNumber: number
@@ -1,72 +1 @@
1
- import { atom, atomFamily } from "atom.io"
2
- import { attachIntrospectionStates } from "atom.io/introspection"
3
-
4
- import { isPlainObject } from "~/packages/anvl/src/object"
5
- import { Refinery } from "~/packages/anvl/src/refinement"
6
- import {
7
- diffArray,
8
- diffBoolean,
9
- Differ,
10
- diffNumber,
11
- diffObject,
12
- diffString,
13
- } from "~/packages/anvl/src/tree/differ"
14
- import { lazyLocalStorageEffect } from "~/packages/atom.io/__unstable__/web-effects/src"
15
-
16
1
  export * from "./AtomIODevtools"
17
-
18
- export const {
19
- atomIndex,
20
- selectorIndex,
21
- transactionIndex,
22
- findTransactionLogState,
23
- timelineIndex,
24
- findTimelineState,
25
- } = attachIntrospectionStates()
26
-
27
- export const devtoolsAreOpenState = atom<boolean>({
28
- key: `👁‍🗨 Devtools Are Open`,
29
- default: true,
30
- effects: [lazyLocalStorageEffect(`👁‍🗨 Devtools Are Open`)],
31
- })
32
-
33
- type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`
34
-
35
- export const devtoolsViewSelectionState = atom<DevtoolsView>({
36
- key: `👁‍🗨 Devtools View Selection`,
37
- default: `atoms`,
38
- effects: [lazyLocalStorageEffect(`👁‍🗨 Devtools View`)],
39
- })
40
-
41
- export const devtoolsViewOptionsState = atom<DevtoolsView[]>({
42
- key: `👁‍🗨 Devtools View Options`,
43
- default: [`atoms`, `selectors`, `transactions`, `timelines`],
44
- effects: [lazyLocalStorageEffect(`👁‍🗨 Devtools View Options`)],
45
- })
46
-
47
- export const findViewIsOpenState = atomFamily<boolean, string>({
48
- key: `👁‍🗨 Devtools View Is Open`,
49
- default: false,
50
- effects: (key) => [lazyLocalStorageEffect(key + `:view-is-open`)],
51
- })
52
-
53
- export const primitiveRefinery = new Refinery({
54
- number: (input: unknown): input is number => typeof input === `number`,
55
- string: (input: unknown): input is string => typeof input === `string`,
56
- boolean: (input: unknown): input is boolean => typeof input === `boolean`,
57
- null: (input: unknown): input is null => input === null,
58
- })
59
-
60
- export const jsonTreeRefinery = new Refinery({
61
- object: isPlainObject,
62
- array: (input: unknown): input is unknown[] => Array.isArray(input),
63
- })
64
-
65
- export const prettyJson = new Differ(primitiveRefinery, jsonTreeRefinery, {
66
- number: diffNumber,
67
- string: diffString,
68
- boolean: diffBoolean,
69
- null: () => ({ summary: `No Change` }),
70
- object: diffObject,
71
- array: diffArray,
72
- })
@@ -0,0 +1,51 @@
1
+ import { atom, atomFamily } from "atom.io"
2
+ import { attachIntrospectionStates } from "atom.io/introspection"
3
+ import { persistSync } from "atom.io/web"
4
+
5
+ export const {
6
+ atomIndex,
7
+ selectorIndex,
8
+ transactionIndex,
9
+ transactionLogSelectors,
10
+ timelineIndex,
11
+ timelineSelectors,
12
+ typeSelectors,
13
+ } = attachIntrospectionStates()
14
+
15
+ export const devtoolsAreOpenState = atom<boolean>({
16
+ key: `👁‍🗨 Devtools Are Open`,
17
+ default: true,
18
+ effects:
19
+ typeof window === `undefined`
20
+ ? []
21
+ : [persistSync(window.localStorage, JSON, `👁‍🗨 Devtools Are Open`)],
22
+ })
23
+
24
+ type DevtoolsView = `atoms` | `selectors` | `timelines` | `transactions`
25
+
26
+ export const devtoolsViewSelectionState = atom<DevtoolsView>({
27
+ key: `👁‍🗨 Devtools View Selection`,
28
+ default: `atoms`,
29
+ effects:
30
+ typeof window === `undefined`
31
+ ? []
32
+ : [persistSync(window.localStorage, JSON, `👁‍🗨 Devtools View`)],
33
+ })
34
+
35
+ export const devtoolsViewOptionsState = atom<DevtoolsView[]>({
36
+ key: `👁‍🗨 Devtools View Options`,
37
+ default: [`atoms`, `selectors`, `transactions`, `timelines`],
38
+ effects:
39
+ typeof window === `undefined`
40
+ ? []
41
+ : [persistSync(window.localStorage, JSON, `👁‍🗨 Devtools View Options`)],
42
+ })
43
+
44
+ export const viewIsOpenAtoms = atomFamily<boolean, string>({
45
+ key: `👁‍🗨 Devtools View Is Open`,
46
+ default: false,
47
+ effects: (key) =>
48
+ typeof window === `undefined`
49
+ ? []
50
+ : [persistSync(window.localStorage, JSON, key + `:view-is-open`)],
51
+ })
@@ -1,6 +1,6 @@
1
1
  import * as atom_io from 'atom.io';
2
- import { AtomFamilyToken, ReadableFamilyToken, ReadableToken, AtomToken, TransactionToken, MutableAtomToken } from 'atom.io';
3
- import { Canonical, Json } from 'atom.io/json';
2
+ import { AtomFamilyToken, ReadableFamilyToken, ReadableToken, TokenType, AtomToken, TransactionToken, MutableAtomToken } from 'atom.io';
3
+ import { Canonical } from 'atom.io/json';
4
4
  import * as atom_io_data from 'atom.io/data';
5
5
  import { SetRTX, SetRTXJson } from 'atom.io/transceivers/set-rtx';
6
6
 
@@ -8,24 +8,24 @@ declare class InvariantMap<K, V> extends Map<K, V> {
8
8
  set(key: K, value: V): this;
9
9
  clear(): void;
10
10
  }
11
- type PerspectiveToken<F extends AtomFamilyToken<any>, T extends F extends AtomFamilyToken<infer U, any> ? U : never> = {
11
+ type PerspectiveToken<F extends AtomFamilyToken<any>> = {
12
12
  type: `realtime_perspective`;
13
13
  resourceAtoms: F;
14
- viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>;
14
+ viewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], string>;
15
15
  };
16
16
  type ContinuityToken = {
17
17
  readonly type: `continuity`;
18
18
  readonly key: string;
19
19
  readonly globals: AtomToken<any>[];
20
20
  readonly actions: TransactionToken<any>[];
21
- readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>, Json.Serializable>[];
21
+ readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[];
22
22
  };
23
23
  declare class SyncGroup {
24
24
  protected readonly key: string;
25
- protected type: "continuity";
25
+ type: "continuity";
26
26
  protected globals: AtomToken<any>[];
27
27
  protected actions: TransactionToken<any>[];
28
- protected perspectives: PerspectiveToken<any, any>[];
28
+ protected perspectives: PerspectiveToken<any>[];
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,5 +1,5 @@
1
1
  import '../../dist/chunk-XWL6SNVU.js';
2
- import { getUpdateToken, assignTransactionToContinuity, IMPLICIT, setEpochNumberOfContinuity } from 'atom.io/internal';
2
+ import { assignTransactionToContinuity, IMPLICIT, setEpochNumberOfContinuity } from 'atom.io/internal';
3
3
  import { atom, selectorFamily } from 'atom.io';
4
4
  import { join, getInternalRelations } from 'atom.io/data';
5
5
  import { SetRTX } from 'atom.io/transceivers/set-rtx';
@@ -37,28 +37,24 @@ var SyncGroup = class _SyncGroup {
37
37
  }
38
38
  add(...args) {
39
39
  const zeroth = args[0];
40
- if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
41
- const globals = args;
42
- for (const global of globals) {
43
- switch (global.type) {
44
- case `atom`:
45
- this.globals.push(global);
46
- break;
47
- case `mutable_atom`:
48
- this.globals.push(getUpdateToken(global));
49
- break;
40
+ switch (zeroth.type) {
41
+ case `atom`:
42
+ case `mutable_atom`:
43
+ this.globals.push(...args);
44
+ break;
45
+ case `transaction`:
46
+ this.actions.push(...args);
47
+ break;
48
+ case `atom_family`:
49
+ {
50
+ const [family, index] = args;
51
+ this.perspectives.push({
52
+ type: `realtime_perspective`,
53
+ resourceAtoms: family,
54
+ viewAtoms: index
55
+ });
50
56
  }
51
- }
52
- } else if (zeroth.type === `transaction`) {
53
- const actions = args;
54
- this.actions.push(...actions);
55
- } else {
56
- const [family, index] = args;
57
- this.perspectives.push({
58
- type: `realtime_perspective`,
59
- resourceAtoms: family,
60
- viewAtoms: index
61
- });
57
+ break;
62
58
  }
63
59
  return this;
64
60
  }
@@ -3,15 +3,17 @@ import type {
3
3
  AtomToken,
4
4
  ReadableFamilyToken,
5
5
  ReadableToken,
6
+ TokenType,
6
7
  TransactionToken,
7
8
  } from "atom.io"
8
9
  import {
9
10
  assignTransactionToContinuity,
10
- getUpdateToken,
11
11
  IMPLICIT,
12
12
  setEpochNumberOfContinuity,
13
13
  } from "atom.io/internal"
14
- import type { Canonical, Json } from "atom.io/json"
14
+ import type { Canonical } from "atom.io/json"
15
+
16
+ /* eslint-disable no-console */
15
17
 
16
18
  export class InvariantMap<K, V> extends Map<K, V> {
17
19
  public set(key: K, value: V): this {
@@ -30,13 +32,10 @@ export class InvariantMap<K, V> extends Map<K, V> {
30
32
  }
31
33
  }
32
34
 
33
- export type PerspectiveToken<
34
- F extends AtomFamilyToken<any>,
35
- T extends F extends AtomFamilyToken<infer U, any> ? U : never,
36
- > = {
35
+ export type PerspectiveToken<F extends AtomFamilyToken<any>> = {
37
36
  type: `realtime_perspective`
38
37
  resourceAtoms: F
39
- viewAtoms: ReadableFamilyToken<ReadableToken<T>[], string>
38
+ viewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], string>
40
39
  }
41
40
 
42
41
  export type ContinuityToken = {
@@ -44,18 +43,15 @@ export type ContinuityToken = {
44
43
  readonly key: string
45
44
  readonly globals: AtomToken<any>[]
46
45
  readonly actions: TransactionToken<any>[]
47
- readonly perspectives: PerspectiveToken<
48
- AtomFamilyToken<any, Canonical>,
49
- Json.Serializable
50
- >[]
46
+ readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[]
51
47
  }
52
48
 
53
49
  export class SyncGroup {
54
- protected type = `continuity` as const
50
+ public type = `continuity` as const
55
51
 
56
52
  protected globals: AtomToken<any>[] = []
57
53
  protected actions: TransactionToken<any>[] = []
58
- protected perspectives: PerspectiveToken<any, any>[] = []
54
+ protected perspectives: PerspectiveToken<any>[] = []
59
55
 
60
56
  protected constructor(protected readonly key: string) {}
61
57
 
@@ -88,32 +84,29 @@ export class SyncGroup {
88
84
  | [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]
89
85
  ): this {
90
86
  const zeroth = args[0]
91
- if (zeroth.type === `atom` || zeroth.type === `mutable_atom`) {
92
- const globals = args as AtomToken<any>[]
93
- for (const global of globals) {
94
- switch (global.type) {
95
- case `atom`:
96
- this.globals.push(global)
97
- break
98
- case `mutable_atom`:
99
- this.globals.push(getUpdateToken(global))
100
- break
87
+ switch (zeroth.type) {
88
+ case `atom`:
89
+ case `mutable_atom`:
90
+ this.globals.push(...(args as AtomToken<any>[]))
91
+ break
92
+ case `transaction`:
93
+ this.actions.push(...(args as TransactionToken<any>[]))
94
+ break
95
+ case `atom_family`:
96
+ {
97
+ const [family, index] = args as [
98
+ AtomFamilyToken<any, any>,
99
+ ReadableFamilyToken<ReadableToken<any>[], string>,
100
+ ]
101
+ this.perspectives.push({
102
+ type: `realtime_perspective`,
103
+ resourceAtoms: family,
104
+ viewAtoms: index,
105
+ })
101
106
  }
102
- }
103
- } else if (zeroth.type === `transaction`) {
104
- const actions = args as TransactionToken<any>[]
105
- this.actions.push(...actions)
106
- } else {
107
- const [family, index] = args as [
108
- AtomFamilyToken<any, any>,
109
- ReadableFamilyToken<ReadableToken<any>[], string>,
110
- ]
111
- this.perspectives.push({
112
- type: `realtime_perspective`,
113
- resourceAtoms: family,
114
- viewAtoms: index,
115
- })
107
+ break
116
108
  }
109
+
117
110
  return this
118
111
  }
119
112
  }
@@ -1,9 +1,9 @@
1
- import { lazyLocalStorageEffect } from '../../dist/chunk-H6EDLPKH.js';
2
1
  import '../../dist/chunk-XWL6SNVU.js';
3
2
  import * as Internal from 'atom.io/internal';
4
- import { setIntoStore, getJsonToken, getUpdateToken, getFromStore, assignTransactionToContinuity, subscribeToTransaction, disposeAtom, setEpochNumberOfContinuity, getEpochNumberOfContinuity, isRootStore, ingestTransactionUpdate, actUponStore } from 'atom.io/internal';
3
+ import { setIntoStore, getJsonToken, getUpdateToken, getFromStore, assignTransactionToContinuity, subscribeToTransaction, disposeAtom, setEpochNumberOfContinuity, getEpochNumberOfContinuity, isRootStore, ingestTransactionUpdate, growMoleculeInStore, initFamilyMemberInStore, actUponStore } from 'atom.io/internal';
5
4
  import { parseJson } from 'atom.io/json';
6
5
  import * as AtomIO from 'atom.io';
6
+ import { persistSync } from 'atom.io/web';
7
7
  import { optimisticUpdateQueue as optimisticUpdateQueue$1, confirmedUpdateQueue as confirmedUpdateQueue$1 } from 'atom.io/realtime-client';
8
8
 
9
9
  function pullAtom(token, socket, store) {
@@ -164,11 +164,10 @@ var myIdState = AtomIO.selector({
164
164
  key: `mySocketId`,
165
165
  get: ({ get }) => get(myIdState__INTERNAL)
166
166
  });
167
- var usernameEffects = typeof window === `undefined` ? [] : [lazyLocalStorageEffect(`myUsername`)];
168
167
  var myUsernameState = AtomIO.atom({
169
- key: `myUsername`,
168
+ key: `myName`,
170
169
  default: null,
171
- effects: usernameEffects
170
+ effects: typeof window === `undefined` ? [] : [persistSync(window.localStorage, JSON, `myUsername`)]
172
171
  });
173
172
  var optimisticUpdateQueue = AtomIO.atom({
174
173
  key: `updateQueue`,
@@ -200,8 +199,8 @@ function syncContinuity(continuity, socket, store) {
200
199
  const initializeContinuity = (epoch, payload) => {
201
200
  socket.off(`continuity-init:${continuityKey}`, initializeContinuity);
202
201
  let i = 0;
203
- let k = ``;
204
- let v = null;
202
+ let k;
203
+ let v;
205
204
  for (const x of payload) {
206
205
  if (i % 2 === 0) {
207
206
  k = x;
@@ -468,14 +467,14 @@ function syncContinuity(continuity, socket, store) {
468
467
  });
469
468
  socket.on(`reveal:${continuityKey}`, (revealed) => {
470
469
  let i = 0;
471
- let k = ``;
472
- let v = null;
470
+ let k;
471
+ let v;
473
472
  for (const x of revealed) {
474
473
  if (i % 2 === 0) {
475
474
  k = x;
476
475
  } else {
477
476
  v = x;
478
- setIntoStore(k, v, store);
477
+ upsertState(k, v, store);
479
478
  }
480
479
  i++;
481
480
  }
@@ -495,5 +494,20 @@ function syncContinuity(continuity, socket, store) {
495
494
  for (const unsubscribe of unsubscribeFunctions) unsubscribe();
496
495
  };
497
496
  }
497
+ function upsertState(store, token, value) {
498
+ if (token.family) {
499
+ const family = store.families.get(token.family.key);
500
+ if (family) {
501
+ const molecule = store.molecules.get(token.family.subKey);
502
+ if (molecule) {
503
+ growMoleculeInStore(molecule, family, store);
504
+ } else if (store.config.lifespan === `immortal`) {
505
+ throw new Error(`No molecule found for key "${token.family.subKey}"`);
506
+ }
507
+ initFamilyMemberInStore(store, family, parseJson(token.family.subKey));
508
+ }
509
+ }
510
+ setIntoStore(store, token, value);
511
+ }
498
512
 
499
513
  export { confirmedUpdateQueue, myIdState, myIdState__INTERNAL, myUsernameState, optimisticUpdateQueue, pullAtom, pullAtomFamilyMember, pullMutableAtom, pullMutableAtomFamilyMember, pullSelector, pullSelectorFamilyMember, pushState, serverAction, syncContinuity };
@@ -4,6 +4,8 @@ import type { Json } from "atom.io/json"
4
4
  import { parseJson } from "atom.io/json"
5
5
  import type { Socket } from "socket.io-client"
6
6
 
7
+ /* eslint-disable no-console */
8
+
7
9
  export function pullAtomFamilyMember<J extends Json.Serializable>(
8
10
  token: AtomIO.RegularAtomToken<J>,
9
11
  socket: Socket,
@@ -5,6 +5,8 @@ import type { Json } from "atom.io/json"
5
5
  import { parseJson } from "atom.io/json"
6
6
  import type { Socket } from "socket.io-client"
7
7
 
8
+ /* eslint-disable no-console */
9
+
8
10
  export function pullMutableAtomFamilyMember<
9
11
  T extends Transceiver<any>,
10
12
  J extends Json.Serializable,
@@ -5,6 +5,8 @@ import type { Socket } from "socket.io-client"
5
5
  import { pullAtomFamilyMember } from "./pull-atom-family-member"
6
6
  import { pullMutableAtomFamilyMember } from "./pull-mutable-atom-family-member"
7
7
 
8
+ /* eslint-disable no-console */
9
+
8
10
  export function pullSelectorFamilyMember<T>(
9
11
  token: AtomIO.SelectorToken<T>,
10
12
  socket: Socket,
@@ -1,6 +1,5 @@
1
1
  import * as AtomIO from "atom.io"
2
-
3
- import { lazyLocalStorageEffect } from "~/packages/atom.io/__unstable__/web-effects/src/storage"
2
+ import { persistSync } from "atom.io/web"
4
3
 
5
4
  export const myIdState__INTERNAL = AtomIO.atom<string | undefined>({
6
5
  key: `mySocketId__INTERNAL`,
@@ -11,10 +10,11 @@ export const myIdState = AtomIO.selector<string | undefined>({
11
10
  get: ({ get }) => get(myIdState__INTERNAL),
12
11
  })
13
12
 
14
- const usernameEffects =
15
- typeof window === `undefined` ? [] : [lazyLocalStorageEffect(`myUsername`)]
16
13
  export const myUsernameState = AtomIO.atom<string | null>({
17
- key: `myUsername`,
14
+ key: `myName`,
18
15
  default: null,
19
- effects: usernameEffects,
16
+ effects:
17
+ typeof window === `undefined`
18
+ ? []
19
+ : [persistSync(window.localStorage, JSON, `myUsername`)],
20
20
  })