atom.io 0.27.5 → 0.28.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.
- package/data/dist/index.d.ts +31 -29
- package/data/dist/index.js +16 -17
- package/data/src/join.ts +17 -19
- package/dist/{chunk-6ABWLAGY.js → chunk-BX3MTH2Z.js} +320 -249
- package/dist/chunk-D52JNVER.js +721 -0
- package/dist/chunk-EUVKUTW3.js +89 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/internal/dist/index.d.ts +72 -36
- package/internal/dist/index.js +1 -1
- package/internal/src/atom/dispose-atom.ts +2 -9
- package/internal/src/families/dispose-from-store.ts +35 -18
- package/internal/src/families/find-in-store.ts +17 -7
- package/internal/src/get-state/get-from-store.ts +41 -32
- package/internal/src/ingest-updates/ingest-creation-disposal.ts +10 -1
- package/internal/src/molecule/dispose-molecule.ts +6 -17
- package/internal/src/pretty-print.ts +1 -16
- package/internal/src/selector/dispose-selector.ts +2 -9
- package/internal/src/set-state/set-into-store.ts +17 -19
- package/internal/src/store/circular-buffer.ts +34 -0
- package/internal/src/store/counterfeit.ts +109 -0
- package/internal/src/store/deposit.ts +14 -0
- package/internal/src/store/index.ts +1 -0
- package/internal/src/store/store.ts +3 -0
- package/internal/src/store/withdraw.ts +15 -10
- package/internal/src/transaction/build-transaction.ts +1 -0
- package/introspection/dist/index.d.ts +84 -4
- package/introspection/dist/index.js +1 -392
- package/introspection/src/attach-introspection-states.ts +7 -4
- package/introspection/src/attach-type-selectors.ts +26 -0
- package/introspection/src/differ.ts +167 -0
- package/introspection/src/index.ts +2 -0
- package/introspection/src/refinery.ts +100 -0
- package/json/dist/index.d.ts +31 -30
- package/json/dist/index.js +2 -77
- package/json/src/entries.ts +6 -0
- package/json/src/index.ts +47 -6
- package/package.json +17 -8
- package/react-devtools/dist/index.d.ts +1 -91
- package/react-devtools/dist/index.js +285 -414
- package/react-devtools/src/AtomIODevtools.tsx +2 -2
- package/react-devtools/src/StateEditor.tsx +20 -12
- package/react-devtools/src/StateIndex.tsx +8 -26
- package/react-devtools/src/TimelineIndex.tsx +3 -3
- package/react-devtools/src/TransactionIndex.tsx +6 -6
- package/react-devtools/src/Updates.tsx +1 -4
- package/react-devtools/src/index.ts +0 -71
- package/react-devtools/src/store.ts +51 -0
- package/realtime/dist/index.d.ts +7 -7
- package/realtime/dist/index.js +18 -22
- package/realtime/src/realtime-continuity.ts +27 -35
- package/realtime-client/dist/index.js +24 -10
- package/realtime-client/src/realtime-client-stores/client-main-store.ts +6 -6
- package/realtime-client/src/sync-continuity.ts +28 -6
- package/realtime-server/dist/index.js +41 -5
- package/realtime-server/src/realtime-continuity-synchronizer.ts +42 -78
- package/realtime-testing/dist/index.d.ts +2 -0
- package/realtime-testing/dist/index.js +50 -8
- package/realtime-testing/src/setup-realtime-test.tsx +59 -9
- package/src/silo.ts +7 -3
- package/web/dist/index.d.ts +9 -0
- package/{dist/chunk-H6EDLPKH.js → web/dist/index.js} +5 -4
- package/web/package.json +13 -0
- package/web/src/index.ts +1 -0
- package/web/src/persist-sync.ts +25 -0
- package/dist/chunk-AK23DRMD.js +0 -21
- 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
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
/>
|
|
@@ -6,32 +6,14 @@ import type {
|
|
|
6
6
|
import { getState, selectorFamily } from "atom.io"
|
|
7
7
|
import { findState } from "atom.io/ephemeral"
|
|
8
8
|
import type { FamilyNode, WritableTokenIndex } from "atom.io/introspection"
|
|
9
|
+
import { primitiveRefinery } from "atom.io/introspection"
|
|
9
10
|
import type { Canonical } from "atom.io/json"
|
|
10
11
|
import { useI, useO } from "atom.io/react"
|
|
11
12
|
import type { FC } from "react"
|
|
12
13
|
|
|
13
|
-
import { isJson, refineJsonType } from "~/packages/anvl/src/refinement"
|
|
14
|
-
|
|
15
|
-
import { findViewIsOpenState, primitiveRefinery } from "."
|
|
16
14
|
import { button } from "./Button"
|
|
17
15
|
import { StoreEditor } from "./StateEditor"
|
|
18
|
-
|
|
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
|
-
})
|
|
16
|
+
import { typeSelectors, viewIsOpenAtoms } from "./store"
|
|
35
17
|
|
|
36
18
|
export const StateIndexLeafNode: FC<{
|
|
37
19
|
node: ReadableToken<unknown>
|
|
@@ -83,8 +65,8 @@ export const StateIndexTreeNode: FC<{
|
|
|
83
65
|
const setIsOpen = useI(isOpenState)
|
|
84
66
|
const isOpen = useO(isOpenState)
|
|
85
67
|
for (const [key, childNode] of node.familyMembers) {
|
|
86
|
-
findState(
|
|
87
|
-
findState(
|
|
68
|
+
findState(viewIsOpenAtoms, key)
|
|
69
|
+
findState(typeSelectors, childNode.key)
|
|
88
70
|
}
|
|
89
71
|
return (
|
|
90
72
|
<>
|
|
@@ -104,8 +86,8 @@ export const StateIndexTreeNode: FC<{
|
|
|
104
86
|
<StateIndexNode
|
|
105
87
|
key={key}
|
|
106
88
|
node={childNode}
|
|
107
|
-
isOpenState={findState(
|
|
108
|
-
typeState={findState(
|
|
89
|
+
isOpenState={findState(viewIsOpenAtoms, childNode.key)}
|
|
90
|
+
typeState={findState(typeSelectors, childNode.key)}
|
|
109
91
|
/>
|
|
110
92
|
))
|
|
111
93
|
: null}
|
|
@@ -147,8 +129,8 @@ export const StateIndex: FC<{
|
|
|
147
129
|
<StateIndexNode
|
|
148
130
|
key={key}
|
|
149
131
|
node={node}
|
|
150
|
-
isOpenState={findState(
|
|
151
|
-
typeState={findState(
|
|
132
|
+
isOpenState={findState(viewIsOpenAtoms, node.key)}
|
|
133
|
+
typeState={findState(typeSelectors, node.key)}
|
|
152
134
|
/>
|
|
153
135
|
)
|
|
154
136
|
})}
|
|
@@ -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(
|
|
100
|
-
timelineState={findState(
|
|
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
|
-
|
|
17
|
-
|
|
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(
|
|
72
|
-
logState={findState(
|
|
71
|
+
isOpenState={findState(viewIsOpenAtoms, token.key)}
|
|
72
|
+
logState={findState(transactionLogSelectors, token.key)}
|
|
73
73
|
/>
|
|
74
74
|
)
|
|
75
75
|
})}
|
|
@@ -4,12 +4,9 @@ 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 "."
|
|
12
|
-
|
|
13
10
|
const AtomUpdateFC: React.FC<{
|
|
14
11
|
serialNumber: number
|
|
15
12
|
atomUpdate: KeyedStateUpdate<unknown>
|
|
@@ -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
|
+
})
|
package/realtime/dist/index.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
11
|
+
type PerspectiveToken<F extends AtomFamilyToken<any>> = {
|
|
12
12
|
type: `realtime_perspective`;
|
|
13
13
|
resourceAtoms: F;
|
|
14
|
-
viewAtoms: ReadableFamilyToken<ReadableToken<
|
|
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
|
|
21
|
+
readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[];
|
|
22
22
|
};
|
|
23
23
|
declare class SyncGroup {
|
|
24
24
|
protected readonly key: string;
|
|
25
|
-
|
|
25
|
+
type: "continuity";
|
|
26
26
|
protected globals: AtomToken<any>[];
|
|
27
27
|
protected actions: TransactionToken<any>[];
|
|
28
|
-
protected perspectives: PerspectiveToken<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;
|
package/realtime/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '../../dist/chunk-XWL6SNVU.js';
|
|
2
|
-
import {
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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,6 +3,7 @@ import type {
|
|
|
3
3
|
AtomToken,
|
|
4
4
|
ReadableFamilyToken,
|
|
5
5
|
ReadableToken,
|
|
6
|
+
TokenType,
|
|
6
7
|
TransactionToken,
|
|
7
8
|
} from "atom.io"
|
|
8
9
|
import {
|
|
@@ -30,13 +31,10 @@ export class InvariantMap<K, V> extends Map<K, V> {
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export type PerspectiveToken<
|
|
34
|
-
F extends AtomFamilyToken<any>,
|
|
35
|
-
T extends F extends AtomFamilyToken<infer U, any> ? U : never,
|
|
36
|
-
> = {
|
|
34
|
+
export type PerspectiveToken<F extends AtomFamilyToken<any>> = {
|
|
37
35
|
type: `realtime_perspective`
|
|
38
36
|
resourceAtoms: F
|
|
39
|
-
viewAtoms: ReadableFamilyToken<ReadableToken<
|
|
37
|
+
viewAtoms: ReadableFamilyToken<ReadableToken<TokenType<F>>[], string>
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
export type ContinuityToken = {
|
|
@@ -44,18 +42,15 @@ export type ContinuityToken = {
|
|
|
44
42
|
readonly key: string
|
|
45
43
|
readonly globals: AtomToken<any>[]
|
|
46
44
|
readonly actions: TransactionToken<any>[]
|
|
47
|
-
readonly perspectives: PerspectiveToken<
|
|
48
|
-
AtomFamilyToken<any, Canonical>,
|
|
49
|
-
Json.Serializable
|
|
50
|
-
>[]
|
|
45
|
+
readonly perspectives: PerspectiveToken<AtomFamilyToken<any, Canonical>>[]
|
|
51
46
|
}
|
|
52
47
|
|
|
53
48
|
export class SyncGroup {
|
|
54
|
-
|
|
49
|
+
public type = `continuity` as const
|
|
55
50
|
|
|
56
51
|
protected globals: AtomToken<any>[] = []
|
|
57
52
|
protected actions: TransactionToken<any>[] = []
|
|
58
|
-
protected perspectives: PerspectiveToken<any
|
|
53
|
+
protected perspectives: PerspectiveToken<any>[] = []
|
|
59
54
|
|
|
60
55
|
protected constructor(protected readonly key: string) {}
|
|
61
56
|
|
|
@@ -88,32 +83,29 @@ export class SyncGroup {
|
|
|
88
83
|
| [AtomFamilyToken<any, any>, ReadableFamilyToken<Iterable<any>, string>]
|
|
89
84
|
): this {
|
|
90
85
|
const zeroth = args[0]
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
switch (zeroth.type) {
|
|
87
|
+
case `atom`:
|
|
88
|
+
case `mutable_atom`:
|
|
89
|
+
this.globals.push(...(args as AtomToken<any>[]))
|
|
90
|
+
break
|
|
91
|
+
case `transaction`:
|
|
92
|
+
this.actions.push(...(args as TransactionToken<any>[]))
|
|
93
|
+
break
|
|
94
|
+
case `atom_family`:
|
|
95
|
+
{
|
|
96
|
+
const [family, index] = args as [
|
|
97
|
+
AtomFamilyToken<any, any>,
|
|
98
|
+
ReadableFamilyToken<ReadableToken<any>[], string>,
|
|
99
|
+
]
|
|
100
|
+
this.perspectives.push({
|
|
101
|
+
type: `realtime_perspective`,
|
|
102
|
+
resourceAtoms: family,
|
|
103
|
+
viewAtoms: index,
|
|
104
|
+
})
|
|
101
105
|
}
|
|
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
|
-
})
|
|
106
|
+
break
|
|
116
107
|
}
|
|
108
|
+
|
|
117
109
|
return this
|
|
118
110
|
}
|
|
119
111
|
}
|
|
@@ -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: `
|
|
168
|
+
key: `myName`,
|
|
170
169
|
default: null,
|
|
171
|
-
effects:
|
|
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
|
|
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
|
|
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
|
-
|
|
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 };
|
|
@@ -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: `
|
|
14
|
+
key: `myName`,
|
|
18
15
|
default: null,
|
|
19
|
-
effects:
|
|
16
|
+
effects:
|
|
17
|
+
typeof window === `undefined`
|
|
18
|
+
? []
|
|
19
|
+
: [persistSync(window.localStorage, JSON, `myUsername`)],
|
|
20
20
|
})
|