atom.io 0.16.3 → 0.17.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/dist/index.cjs +35 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -26
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +48 -17
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +7 -3
- package/internal/dist/index.js +47 -18
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +2 -3
- package/internal/src/get-state/get-from-store.ts +14 -0
- package/internal/src/get-state/index.ts +2 -0
- package/internal/src/{read-or-compute-value.ts → get-state/read-or-compute-value.ts} +3 -3
- package/internal/src/index.ts +1 -1
- package/internal/src/ingest-updates/ingest-atom-update.ts +2 -2
- package/internal/src/mutable/create-mutable-atom.ts +3 -4
- package/internal/src/mutable/tracker.ts +18 -13
- package/internal/src/selector/register-selector.ts +1 -1
- package/internal/src/set-state/index.ts +1 -0
- package/internal/src/set-state/set-atom.ts +1 -1
- package/internal/src/set-state/set-into-store.ts +24 -0
- package/internal/src/subscribe/subscribe-to-root-atoms.ts +1 -1
- package/internal/src/transaction/build-transaction.ts +5 -3
- package/package.json +1 -1
- package/react/dist/index.cjs +3 -3
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.js +5 -5
- package/react/dist/index.js.map +1 -1
- package/react/src/use-i.ts +2 -3
- package/react/src/use-o.ts +3 -4
- package/realtime-client/dist/index.cjs +24 -21
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.js +24 -21
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/pull-family-member.ts +3 -3
- package/realtime-client/src/pull-mutable-family-member.ts +4 -4
- package/realtime-client/src/pull-mutable.ts +4 -4
- package/realtime-client/src/pull-state.ts +3 -3
- package/realtime-client/src/sync-server-action.ts +9 -6
- package/realtime-client/src/sync-state.ts +3 -3
- package/realtime-server/dist/index.cjs +32 -32
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.js +24 -24
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/realtime-action-synchronizer.ts +15 -9
- package/realtime-server/src/realtime-family-provider.ts +10 -5
- package/realtime-server/src/realtime-mutable-family-provider.ts +6 -5
- package/realtime-server/src/realtime-mutable-provider.ts +3 -2
- package/realtime-server/src/realtime-state-provider.ts +3 -3
- package/realtime-server/src/realtime-state-receiver.ts +2 -2
- package/realtime-server/src/realtime-state-synchronizer.ts +3 -3
- package/realtime-testing/dist/index.cjs +2 -2
- package/realtime-testing/dist/index.cjs.map +1 -1
- package/realtime-testing/dist/index.js +2 -2
- package/realtime-testing/dist/index.js.map +1 -1
- package/realtime-testing/src/setup-realtime-test.tsx +2 -2
- package/src/get-state.ts +2 -11
- package/src/set-state.ts +1 -13
- package/src/silo.ts +7 -3
|
@@ -5,9 +5,8 @@ import type {
|
|
|
5
5
|
RegularAtomToken,
|
|
6
6
|
UpdateHandler,
|
|
7
7
|
} from "atom.io"
|
|
8
|
-
import { setState } from "atom.io"
|
|
9
8
|
|
|
10
|
-
import type
|
|
9
|
+
import { type RegularAtom, setIntoStore } from ".."
|
|
11
10
|
import { cacheValue } from "../caching"
|
|
12
11
|
import { newest } from "../lineage"
|
|
13
12
|
import type { Store } from "../store"
|
|
@@ -69,7 +68,7 @@ export function createRegularAtom<T>(
|
|
|
69
68
|
const cleanupFunctions: (() => void)[] = []
|
|
70
69
|
for (const effect of options.effects) {
|
|
71
70
|
const cleanup = effect({
|
|
72
|
-
setSelf: (next) =>
|
|
71
|
+
setSelf: (next) => setIntoStore(token, next, store),
|
|
73
72
|
onSet: (handle: UpdateHandler<T>) =>
|
|
74
73
|
subscribeToState(token, handle, `effect[${effectIndex}]`, store),
|
|
75
74
|
})
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReadableToken } from "atom.io"
|
|
2
|
+
|
|
3
|
+
import { NotFoundError } from "../not-found-error"
|
|
4
|
+
import type { Store } from "../store"
|
|
5
|
+
import { withdraw, withdrawNewFamilyMember } from "../store"
|
|
6
|
+
import { readOrComputeValue } from "./read-or-compute-value"
|
|
7
|
+
|
|
8
|
+
export function getFromStore<T>(token: ReadableToken<T>, store: Store): T {
|
|
9
|
+
const state = withdraw(token, store) ?? withdrawNewFamilyMember(token, store)
|
|
10
|
+
if (state === undefined) {
|
|
11
|
+
throw new NotFoundError(token, store)
|
|
12
|
+
}
|
|
13
|
+
return readOrComputeValue(state, store)
|
|
14
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ReadableState } from "
|
|
2
|
-
import { readCachedValue } from "
|
|
3
|
-
import type { Store } from "
|
|
1
|
+
import type { ReadableState } from ".."
|
|
2
|
+
import { readCachedValue } from "../caching"
|
|
3
|
+
import type { Store } from "../store"
|
|
4
4
|
|
|
5
5
|
export const readOrComputeValue = <T>(
|
|
6
6
|
state: ReadableState<T>,
|
package/internal/src/index.ts
CHANGED
|
@@ -11,13 +11,13 @@ export * from "./lineage"
|
|
|
11
11
|
export * from "./families"
|
|
12
12
|
export * from "./future"
|
|
13
13
|
export * from "./get-environment-data"
|
|
14
|
+
export * from "./get-state"
|
|
14
15
|
export * from "./ingest-updates"
|
|
15
16
|
export * from "./keys"
|
|
16
17
|
export * from "./lazy-map"
|
|
17
18
|
export * from "./mutable"
|
|
18
19
|
export * from "./not-found-error"
|
|
19
20
|
export * from "./operation"
|
|
20
|
-
export * from "./read-or-compute-value"
|
|
21
21
|
export * from "./selector"
|
|
22
22
|
export * from "./set-state"
|
|
23
23
|
export * from "./store"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { KeyedStateUpdate } from "atom.io"
|
|
2
|
-
import { setState } from "atom.io"
|
|
3
2
|
|
|
3
|
+
import { setIntoStore } from "../set-state"
|
|
4
4
|
import type { Store } from "../store"
|
|
5
5
|
|
|
6
6
|
export function ingestAtomUpdate(
|
|
@@ -10,5 +10,5 @@ export function ingestAtomUpdate(
|
|
|
10
10
|
): void {
|
|
11
11
|
const { key, newValue, oldValue } = atomUpdate
|
|
12
12
|
const value = applying === `newValue` ? newValue : oldValue
|
|
13
|
-
|
|
13
|
+
setIntoStore({ key, type: `atom` }, value, store)
|
|
14
14
|
}
|
|
@@ -4,12 +4,11 @@ import type {
|
|
|
4
4
|
MutableAtomOptions,
|
|
5
5
|
MutableAtomToken,
|
|
6
6
|
} from "atom.io"
|
|
7
|
-
import { setState } from "atom.io"
|
|
8
7
|
import type { Json } from "atom.io/json"
|
|
9
8
|
import { selectJson } from "atom.io/json"
|
|
10
9
|
|
|
11
|
-
import { type MutableAtom, cacheValue } from ".."
|
|
12
|
-
import {
|
|
10
|
+
import { type MutableAtom, cacheValue, setIntoStore } from ".."
|
|
11
|
+
import { markAtomAsDefault } from "../atom"
|
|
13
12
|
import { newest } from "../lineage"
|
|
14
13
|
import { type Store, deposit } from "../store"
|
|
15
14
|
import { Subject } from "../subject"
|
|
@@ -70,7 +69,7 @@ export function createMutableAtom<
|
|
|
70
69
|
const cleanupFunctions: (() => void)[] = []
|
|
71
70
|
for (const effect of options.effects) {
|
|
72
71
|
const cleanup = effect({
|
|
73
|
-
setSelf: (next) =>
|
|
72
|
+
setSelf: (next) => setIntoStore(token, next, store),
|
|
74
73
|
onSet: (handle: UpdateHandler<T>) =>
|
|
75
74
|
subscribeToState(token, handle, `effect[${effectIndex}]`, store),
|
|
76
75
|
})
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { FamilyMetadata, MutableAtomToken, RegularAtomToken } from "atom.io"
|
|
2
|
-
import { getState, setState } from "atom.io"
|
|
3
2
|
import type { Json } from "atom.io/json"
|
|
4
3
|
|
|
5
4
|
import type { Store } from ".."
|
|
6
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
getFromStore,
|
|
7
|
+
newest,
|
|
8
|
+
setIntoStore,
|
|
9
|
+
subscribeToState,
|
|
10
|
+
subscribeToTimeline,
|
|
11
|
+
} from ".."
|
|
7
12
|
import { createRegularAtom } from "../atom"
|
|
8
|
-
import { isChildStore
|
|
13
|
+
import { isChildStore } from "../transaction/is-root-store"
|
|
9
14
|
import type { Transceiver } from "./transceiver"
|
|
10
15
|
|
|
11
16
|
/**
|
|
@@ -57,7 +62,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
57
62
|
const subscriptionKey = `tracker:${target.config.name}:${
|
|
58
63
|
isChildStore(target) ? target.transactionMeta.update.key : `main`
|
|
59
64
|
}:${mutableState.key}`
|
|
60
|
-
const originalInnerValue =
|
|
65
|
+
const originalInnerValue = getFromStore(mutableState, target)
|
|
61
66
|
this.unsubscribeFromInnerValue = originalInnerValue.subscribe(
|
|
62
67
|
subscriptionKey,
|
|
63
68
|
(update) => {
|
|
@@ -66,12 +71,12 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
66
71
|
subscriptionKey,
|
|
67
72
|
() => {
|
|
68
73
|
unsubscribe()
|
|
69
|
-
|
|
74
|
+
setIntoStore(latestUpdateState, update, target)
|
|
70
75
|
},
|
|
71
76
|
)
|
|
72
77
|
} else {
|
|
73
|
-
|
|
74
|
-
|
|
78
|
+
setIntoStore(mutableState, (current) => current, target)
|
|
79
|
+
setIntoStore(latestUpdateState, update, target)
|
|
75
80
|
}
|
|
76
81
|
},
|
|
77
82
|
)
|
|
@@ -88,12 +93,12 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
88
93
|
subscriptionKey,
|
|
89
94
|
() => {
|
|
90
95
|
unsubscribe()
|
|
91
|
-
|
|
96
|
+
setIntoStore(latestUpdateState, update, target)
|
|
92
97
|
},
|
|
93
98
|
)
|
|
94
99
|
} else {
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
setIntoStore(mutableState, (current) => current, target)
|
|
101
|
+
setIntoStore(latestUpdateState, update, target)
|
|
97
102
|
}
|
|
98
103
|
},
|
|
99
104
|
)
|
|
@@ -126,7 +131,7 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
126
131
|
{ key: timelineId, type: `timeline` },
|
|
127
132
|
(update) => {
|
|
128
133
|
unsubscribe()
|
|
129
|
-
|
|
134
|
+
setIntoStore(
|
|
130
135
|
mutableState,
|
|
131
136
|
(transceiver) => {
|
|
132
137
|
if (update === `redo` && newValue) {
|
|
@@ -150,12 +155,12 @@ export class Tracker<Mutable extends Transceiver<any>> {
|
|
|
150
155
|
subscriptionKey,
|
|
151
156
|
() => {
|
|
152
157
|
unsubscribe()
|
|
153
|
-
const mutable =
|
|
158
|
+
const mutable = getFromStore(mutableState, target)
|
|
154
159
|
const updateNumber =
|
|
155
160
|
newValue === null ? -1 : mutable.getUpdateNumber(newValue)
|
|
156
161
|
const eventOffset = updateNumber - mutable.cacheUpdateNumber
|
|
157
162
|
if (newValue && eventOffset === 1) {
|
|
158
|
-
|
|
163
|
+
setIntoStore(
|
|
159
164
|
mutableState,
|
|
160
165
|
(transceiver) => (transceiver.do(newValue), transceiver),
|
|
161
166
|
target,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Transactors, findState } from "atom.io"
|
|
2
2
|
|
|
3
3
|
import { findInStore } from "../families"
|
|
4
|
+
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
4
5
|
import { newest } from "../lineage"
|
|
5
|
-
import { readOrComputeValue } from "../read-or-compute-value"
|
|
6
6
|
import { setAtomOrSelector } from "../set-state"
|
|
7
7
|
import type { Store } from "../store"
|
|
8
8
|
import { withdraw, withdrawNewFamilyMember } from "../store"
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Atom } from ".."
|
|
2
2
|
import { isAtomDefault, markAtomAsNotDefault } from "../atom"
|
|
3
3
|
import { cacheValue } from "../caching"
|
|
4
|
+
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
4
5
|
import type { Transceiver } from "../mutable"
|
|
5
6
|
import { markDone } from "../operation"
|
|
6
|
-
import { readOrComputeValue } from "../read-or-compute-value"
|
|
7
7
|
import type { Store } from "../store"
|
|
8
8
|
import { isRootStore } from "../transaction/is-root-store"
|
|
9
9
|
import { become } from "./become"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { WritableToken } from "atom.io"
|
|
2
|
+
|
|
3
|
+
import { NotFoundError } from "../not-found-error"
|
|
4
|
+
import { closeOperation, openOperation } from "../operation"
|
|
5
|
+
import type { Store } from "../store"
|
|
6
|
+
import { withdraw, withdrawNewFamilyMember } from "../store"
|
|
7
|
+
import { setAtomOrSelector } from "./set-atom-or-selector"
|
|
8
|
+
|
|
9
|
+
export function setIntoStore<T, New extends T>(
|
|
10
|
+
token: WritableToken<T>,
|
|
11
|
+
value: New | ((oldValue: T) => New),
|
|
12
|
+
store: Store,
|
|
13
|
+
): void {
|
|
14
|
+
const rejection = openOperation(token, store)
|
|
15
|
+
if (rejection) {
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
const state = withdraw(token, store) ?? withdrawNewFamilyMember(token, store)
|
|
19
|
+
if (state === undefined) {
|
|
20
|
+
throw new NotFoundError(token, store)
|
|
21
|
+
}
|
|
22
|
+
setAtomOrSelector(state, value, store)
|
|
23
|
+
closeOperation(store)
|
|
24
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Selector } from ".."
|
|
2
|
+
import { readOrComputeValue } from "../get-state/read-or-compute-value"
|
|
2
3
|
import { newest } from "../lineage"
|
|
3
|
-
import { readOrComputeValue } from "../read-or-compute-value"
|
|
4
4
|
import { traceAllSelectorAtoms } from "../selector"
|
|
5
5
|
import type { Store } from "../store"
|
|
6
6
|
import { recallState } from "./recall-state"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { runTransaction } from "atom.io"
|
|
2
2
|
import type { findState, ƒn } from "atom.io"
|
|
3
3
|
|
|
4
4
|
import { Junction } from "~/packages/rel8/junction/src"
|
|
@@ -6,8 +6,10 @@ import { Junction } from "~/packages/rel8/junction/src"
|
|
|
6
6
|
import type { TransactionProgress } from "."
|
|
7
7
|
import { findInStore } from "../families"
|
|
8
8
|
import { getEnvironmentData } from "../get-environment-data"
|
|
9
|
+
import { getFromStore } from "../get-state"
|
|
9
10
|
import { LazyMap } from "../lazy-map"
|
|
10
11
|
import { newest } from "../lineage"
|
|
12
|
+
import { setIntoStore } from "../set-state"
|
|
11
13
|
import type { Store } from "../store"
|
|
12
14
|
import type { ChildStore, RootStore } from "./is-root-store"
|
|
13
15
|
import { isRootStore } from "./is-root-store"
|
|
@@ -53,8 +55,8 @@ export const buildTransaction = (
|
|
|
53
55
|
output: undefined,
|
|
54
56
|
},
|
|
55
57
|
transactors: {
|
|
56
|
-
get: (token) =>
|
|
57
|
-
set: (token, value) =>
|
|
58
|
+
get: (token) => getFromStore(token, child),
|
|
59
|
+
set: (token, value) => setIntoStore(token, value, child),
|
|
58
60
|
run: (token, id) => runTransaction(token, id, child),
|
|
59
61
|
find: ((token, key) => findInStore(token, key, child)) as typeof findState,
|
|
60
62
|
env: () => getEnvironmentData(child),
|
package/package.json
CHANGED
package/react/dist/index.cjs
CHANGED
|
@@ -33,7 +33,7 @@ function useI(token, key) {
|
|
|
33
33
|
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` ? internal.findInStore(token, key, store) : token;
|
|
34
34
|
const setter = React5__namespace.useRef(null);
|
|
35
35
|
if (setter.current === null) {
|
|
36
|
-
setter.current = (next) =>
|
|
36
|
+
setter.current = (next) => internal.setIntoStore(stateToken, next, store);
|
|
37
37
|
}
|
|
38
38
|
return setter.current;
|
|
39
39
|
}
|
|
@@ -43,8 +43,8 @@ function useO(token, key) {
|
|
|
43
43
|
const id = React5__namespace.useId();
|
|
44
44
|
return React5__namespace.useSyncExternalStore(
|
|
45
45
|
(dispatch) => internal.subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
|
46
|
-
() =>
|
|
47
|
-
() =>
|
|
46
|
+
() => internal.getFromStore(stateToken, store),
|
|
47
|
+
() => internal.getFromStore(stateToken, store)
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
50
|
|
package/react/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;AAnB3B;AAoBE,WAAO;AAAA,MACN,KAAI,0CAAU,OAAV,YAAgB;AAAA,MACpB,SAAQ,0CAAU,QAAQ,WAAlB,YAA4B;AAAA,MACpC,MAAM,MAAM,KAAK,KAAK;AAAA,MACtB,MAAM,MAAM,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AACA,QAAM,OAAa,cAAqB,YAAY,CAAC;AACrD,QAAM,WAAW,MAAM;AACtB,QACC,KAAK,QAAQ,QAAO,qCAAU,OAC9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type { ReadableToken, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { findInStore, setIntoStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K> | WritableToken<T>,\n\tkey?: K,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setIntoStore(stateToken, next, store)\n\t}\n\treturn setter.current\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableToken,\n} from \"atom.io\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(\n\ttoken:\n\t\t| MutableAtomFamilyToken<any, Serializable, Key>\n\t\t| MutableAtomToken<any, Serializable>,\n\tkey?: Key,\n): Serializable {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `mutable_atom_family`\n\t\t\t? findInStore(token, key as Key, store)\n\t\t\t: token\n\tconst jsonToken = getJsonToken(stateToken)\n\treturn useO(jsonToken)\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { findInStore, getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K> | ReadableToken<T>,\n\tkey?: K,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family` ||\n\t\ttoken.type === `readonly_selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),\n\t\t() => getFromStore(stateToken, store),\n\t\t() => getFromStore(stateToken, store),\n\t)\n}\n","import { redo, undo } from \"atom.io\"\nimport type { TimelineToken } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline?.at ?? NaN,\n\t\t\tlength: timeline?.history.length ?? NaN,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import '../../dist/chunk-PZLG2HP3.js';
|
|
2
|
-
import { IMPLICIT, findInStore, subscribeToState, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
|
|
2
|
+
import { IMPLICIT, findInStore, setIntoStore, subscribeToState, getFromStore, getJsonToken, withdraw, subscribeToTimeline } from 'atom.io/internal';
|
|
3
3
|
import * as React5 from 'react';
|
|
4
4
|
import { jsx } from 'react/jsx-runtime';
|
|
5
|
-
import {
|
|
5
|
+
import { undo, redo } from 'atom.io';
|
|
6
6
|
|
|
7
7
|
var StoreContext = React5.createContext(IMPLICIT.STORE);
|
|
8
8
|
var StoreProvider = ({ children, store = IMPLICIT.STORE }) => /* @__PURE__ */ jsx(StoreContext.Provider, { value: store, children });
|
|
@@ -11,7 +11,7 @@ function useI(token, key) {
|
|
|
11
11
|
const stateToken = token.type === `atom_family` || token.type === `mutable_atom_family` || token.type === `selector_family` ? findInStore(token, key, store) : token;
|
|
12
12
|
const setter = React5.useRef(null);
|
|
13
13
|
if (setter.current === null) {
|
|
14
|
-
setter.current = (next) =>
|
|
14
|
+
setter.current = (next) => setIntoStore(stateToken, next, store);
|
|
15
15
|
}
|
|
16
16
|
return setter.current;
|
|
17
17
|
}
|
|
@@ -21,8 +21,8 @@ function useO(token, key) {
|
|
|
21
21
|
const id = React5.useId();
|
|
22
22
|
return React5.useSyncExternalStore(
|
|
23
23
|
(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
|
24
|
-
() =>
|
|
25
|
-
() =>
|
|
24
|
+
() => getFromStore(stateToken, store),
|
|
25
|
+
() => getFromStore(stateToken, store)
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
28
|
|
package/react/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;
|
|
1
|
+
{"version":3,"sources":["../src/store-context.tsx","../src/use-i.ts","../src/use-json.ts","../src/use-o.ts","../src/use-tl.ts"],"names":["React","findInStore"],"mappings":";;;AACA,SAAS,gBAAgB;AACzB,YAAY,WAAW;AAQtB;AANM,IAAM,eAAqB,oBAAqB,SAAS,KAAK;AAE9D,IAAM,gBAGR,CAAC,EAAE,UAAU,QAAQ,SAAS,MAAM,MACxC,oBAAC,aAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;;;ACThD,SAAS,aAAa,oBAAoB;AAE1C,YAAYA,YAAW;AAahB,SAAS,KACf,OACA,KACyD;AACzD,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,oBACZ,YAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,SAEI,cAAO,IAAI;AACrB,MAAI,OAAO,YAAY,MAAM;AAC5B,WAAO,UAAU,CAAC,SAAS,aAAa,YAAY,MAAM,KAAK;AAAA,EAChE;AACA,SAAO,OAAO;AACf;;;AC7BA,SAAS,eAAAC,cAAa,oBAAoB;AAE1C,YAAYD,YAAW;;;ACNvB,SAAS,eAAAC,cAAa,cAAc,wBAAwB;AAE5D,YAAYD,YAAW;AAWhB,SAAS,KACf,OACA,KACI;AACJ,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,iBACf,MAAM,SAAS,yBACf,MAAM,SAAS,qBACf,MAAM,SAAS,6BACZC,aAAY,OAAO,KAAU,KAAK,IAClC;AACJ,QAAM,KAAW,aAAM;AACvB,SAAa;AAAA,IACZ,CAAC,aAAa,iBAAiB,YAAY,UAAU,SAAS,EAAE,IAAI,KAAK;AAAA,IACzE,MAAM,aAAa,YAAY,KAAK;AAAA,IACpC,MAAM,aAAa,YAAY,KAAK;AAAA,EACrC;AACD;;;ADXO,SAAS,QAIf,OAGA,KACe;AACf,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,aACL,MAAM,SAAS,wBACZA,aAAY,OAAO,KAAY,KAAK,IACpC;AACJ,QAAM,YAAY,aAAa,UAAU;AACzC,SAAO,KAAK,SAAS;AACtB;;;AErCA,SAAS,MAAM,YAAY;AAE3B,SAAS,qBAAqB,gBAAgB;AAC9C,YAAYD,YAAW;AAWhB,SAAS,MAAM,OAAyC;AAC9D,QAAM,QAAc,kBAAW,YAAY;AAC3C,QAAM,KAAW,aAAM;AACvB,QAAM,WAAW,SAAS,OAAO,KAAK;AACtC,QAAM,WAAiB,cAAO,KAAK;AACnC,QAAM,cAAc,MAAM;AAnB3B;AAoBE,WAAO;AAAA,MACN,KAAI,0CAAU,OAAV,YAAgB;AAAA,MACpB,SAAQ,0CAAU,QAAQ,WAAlB,YAA4B;AAAA,MACpC,MAAM,MAAM,KAAK,KAAK;AAAA,MACtB,MAAM,MAAM,KAAK,KAAK;AAAA,IACvB;AAAA,EACD;AACA,QAAM,OAAa,cAAqB,YAAY,CAAC;AACrD,QAAM,WAAW,MAAM;AACtB,QACC,KAAK,QAAQ,QAAO,qCAAU,OAC9B,KAAK,QAAQ,YAAW,qCAAU,QAAQ,WAC1C,SAAS,YAAY,OACpB;AACD,eAAS,UAAU;AACnB,WAAK,UAAU,YAAY;AAAA,IAC5B;AACA,WAAO,KAAK;AAAA,EACb;AACA,SAAa;AAAA,IACZ,CAAC,aAAa,oBAAoB,OAAO,UAAU,UAAU,EAAE,IAAI,KAAK;AAAA,IACxE;AAAA,IACA;AAAA,EACD;AACD","sourcesContent":["import type { Store } from \"atom.io/internal\"\nimport { IMPLICIT } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nexport const StoreContext = React.createContext<Store>(IMPLICIT.STORE)\n\nexport const StoreProvider: React.FC<{\n\tchildren: React.ReactNode\n\tstore?: Store\n}> = ({ children, store = IMPLICIT.STORE }) => (\n\t<StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n)\n","import type { ReadableToken, WritableFamilyToken, WritableToken } from \"atom.io\"\nimport { findInStore, setIntoStore } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useI<T>(\n\ttoken: WritableToken<T>,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K>,\n\tkey: K,\n): <New extends T>(next: New | ((old: T) => New)) => void\n\nexport function useI<T, K extends Json.Serializable>(\n\ttoken: WritableFamilyToken<T, K> | WritableToken<T>,\n\tkey?: K,\n): <New extends T>(next: New | ((old: T) => New)) => void {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst setter: React.MutableRefObject<\n\t\t(<New extends T>(next: New | ((old: T) => New)) => void) | null\n\t> = React.useRef(null)\n\tif (setter.current === null) {\n\t\tsetter.current = (next) => setIntoStore(stateToken, next, store)\n\t}\n\treturn setter.current\n}\n","import type {\n\tMutableAtomFamilyToken,\n\tMutableAtomToken,\n\tReadableToken,\n} from \"atom.io\"\nimport { findInStore, getJsonToken } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\nimport { useO } from \"./use-o\"\n\nexport function useJSON<Serializable extends Json.Serializable>(\n\ttoken: MutableAtomToken<any, Serializable>,\n): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(token: MutableAtomFamilyToken<any, Serializable, Key>, key: Key): Serializable\n\nexport function useJSON<\n\tSerializable extends Json.Serializable,\n\tKey extends Serializable,\n>(\n\ttoken:\n\t\t| MutableAtomFamilyToken<any, Serializable, Key>\n\t\t| MutableAtomToken<any, Serializable>,\n\tkey?: Key,\n): Serializable {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `mutable_atom_family`\n\t\t\t? findInStore(token, key as Key, store)\n\t\t\t: token\n\tconst jsonToken = getJsonToken(stateToken)\n\treturn useO(jsonToken)\n}\n","import type { ReadableFamilyToken, ReadableToken } from \"atom.io\"\nimport { findInStore, getFromStore, subscribeToState } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport function useO<T>(token: ReadableToken<T>): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K>,\n\tkey: K,\n): T\n\nexport function useO<T, K extends Json.Serializable>(\n\ttoken: ReadableFamilyToken<T, K> | ReadableToken<T>,\n\tkey?: K,\n): T {\n\tconst store = React.useContext(StoreContext)\n\tconst stateToken: ReadableToken<any> =\n\t\ttoken.type === `atom_family` ||\n\t\ttoken.type === `mutable_atom_family` ||\n\t\ttoken.type === `selector_family` ||\n\t\ttoken.type === `readonly_selector_family`\n\t\t\t? findInStore(token, key as K, store)\n\t\t\t: token\n\tconst id = React.useId()\n\treturn React.useSyncExternalStore<T>(\n\t\t(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),\n\t\t() => getFromStore(stateToken, store),\n\t\t() => getFromStore(stateToken, store),\n\t)\n}\n","import { redo, undo } from \"atom.io\"\nimport type { TimelineToken } from \"atom.io\"\nimport { subscribeToTimeline, withdraw } from \"atom.io/internal\"\nimport * as React from \"react\"\n\nimport { StoreContext } from \"./store-context\"\n\nexport type TimelineMeta = {\n\tat: number\n\tlength: number\n\tundo: () => void\n\tredo: () => void\n}\n\nexport function useTL(token: TimelineToken<any>): TimelineMeta {\n\tconst store = React.useContext(StoreContext)\n\tconst id = React.useId()\n\tconst timeline = withdraw(token, store)\n\tconst tokenRef = React.useRef(token)\n\tconst rebuildMeta = () => {\n\t\treturn {\n\t\t\tat: timeline?.at ?? NaN,\n\t\t\tlength: timeline?.history.length ?? NaN,\n\t\t\tundo: () => undo(token),\n\t\t\tredo: () => redo(token),\n\t\t}\n\t}\n\tconst meta = React.useRef<TimelineMeta>(rebuildMeta())\n\tconst retrieve = () => {\n\t\tif (\n\t\t\tmeta.current.at !== timeline?.at ||\n\t\t\tmeta.current.length !== timeline?.history.length ||\n\t\t\ttokenRef.current !== token\n\t\t) {\n\t\t\ttokenRef.current = token\n\t\t\tmeta.current = rebuildMeta()\n\t\t}\n\t\treturn meta.current\n\t}\n\treturn React.useSyncExternalStore<TimelineMeta>(\n\t\t(dispatch) => subscribeToTimeline(token, dispatch, `use-tl:${id}`, store),\n\t\tretrieve,\n\t\tretrieve,\n\t)\n}\n"]}
|
package/react/src/use-i.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { setState } from "atom.io"
|
|
2
1
|
import type { ReadableToken, WritableFamilyToken, WritableToken } from "atom.io"
|
|
3
|
-
import { findInStore } from "atom.io/internal"
|
|
2
|
+
import { findInStore, setIntoStore } from "atom.io/internal"
|
|
4
3
|
import type { Json } from "atom.io/json"
|
|
5
4
|
import * as React from "react"
|
|
6
5
|
|
|
@@ -30,7 +29,7 @@ export function useI<T, K extends Json.Serializable>(
|
|
|
30
29
|
(<New extends T>(next: New | ((old: T) => New)) => void) | null
|
|
31
30
|
> = React.useRef(null)
|
|
32
31
|
if (setter.current === null) {
|
|
33
|
-
setter.current = (next) =>
|
|
32
|
+
setter.current = (next) => setIntoStore(stateToken, next, store)
|
|
34
33
|
}
|
|
35
34
|
return setter.current
|
|
36
35
|
}
|
package/react/src/use-o.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { getState } from "atom.io"
|
|
2
1
|
import type { ReadableFamilyToken, ReadableToken } from "atom.io"
|
|
3
|
-
import { findInStore, subscribeToState } from "atom.io/internal"
|
|
2
|
+
import { findInStore, getFromStore, subscribeToState } from "atom.io/internal"
|
|
4
3
|
import type { Json } from "atom.io/json"
|
|
5
4
|
import * as React from "react"
|
|
6
5
|
|
|
@@ -28,7 +27,7 @@ export function useO<T, K extends Json.Serializable>(
|
|
|
28
27
|
const id = React.useId()
|
|
29
28
|
return React.useSyncExternalStore<T>(
|
|
30
29
|
(dispatch) => subscribeToState(stateToken, dispatch, `use-o:${id}`, store),
|
|
31
|
-
() =>
|
|
32
|
-
() =>
|
|
30
|
+
() => getFromStore(stateToken, store),
|
|
31
|
+
() => getFromStore(stateToken, store),
|
|
33
32
|
)
|
|
34
33
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var AtomIO7 = require('atom.io');
|
|
4
|
-
var json = require('atom.io/json');
|
|
5
3
|
var Internal3 = require('atom.io/internal');
|
|
4
|
+
var json = require('atom.io/json');
|
|
5
|
+
var AtomIO = require('atom.io');
|
|
6
6
|
|
|
7
7
|
function _interopNamespace(e) {
|
|
8
8
|
if (e && e.__esModule) return e;
|
|
@@ -22,13 +22,13 @@ function _interopNamespace(e) {
|
|
|
22
22
|
return Object.freeze(n);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
var AtomIO7__namespace = /*#__PURE__*/_interopNamespace(AtomIO7);
|
|
26
25
|
var Internal3__namespace = /*#__PURE__*/_interopNamespace(Internal3);
|
|
26
|
+
var AtomIO__namespace = /*#__PURE__*/_interopNamespace(AtomIO);
|
|
27
27
|
|
|
28
28
|
// realtime-client/src/pull-state.ts
|
|
29
29
|
function pullState(token, socket, store) {
|
|
30
30
|
const setServedValue = (data) => {
|
|
31
|
-
|
|
31
|
+
Internal3.setIntoStore(token, data, store);
|
|
32
32
|
};
|
|
33
33
|
socket.on(`serve:${token.key}`, setServedValue);
|
|
34
34
|
socket.emit(`sub:${token.key}`);
|
|
@@ -46,7 +46,7 @@ function pullFamilyMember(token, socket, store) {
|
|
|
46
46
|
const { key: familyKey, subKey: serializedSubKey } = token.family;
|
|
47
47
|
const subKey = json.parseJson(serializedSubKey);
|
|
48
48
|
socket == null ? void 0 : socket.on(`serve:${token.key}`, (data) => {
|
|
49
|
-
|
|
49
|
+
Internal3.setIntoStore(token, data, store);
|
|
50
50
|
});
|
|
51
51
|
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
52
52
|
return () => {
|
|
@@ -58,12 +58,12 @@ function pullMutableState(token, socket, store) {
|
|
|
58
58
|
const jsonToken = Internal3.getJsonToken(token);
|
|
59
59
|
const updateToken = Internal3.getUpdateToken(token);
|
|
60
60
|
socket.on(`init:${token.key}`, (data) => {
|
|
61
|
-
|
|
61
|
+
Internal3.setIntoStore(jsonToken, data, store);
|
|
62
62
|
});
|
|
63
63
|
socket.on(
|
|
64
64
|
`next:${token.key}`,
|
|
65
65
|
(data) => {
|
|
66
|
-
|
|
66
|
+
Internal3.setIntoStore(updateToken, data, store);
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
69
|
socket.emit(`sub:${token.key}`);
|
|
@@ -83,13 +83,13 @@ function pullMutableFamilyMember(token, socket, store) {
|
|
|
83
83
|
const subKey = json.parseJson(serializedSubKey);
|
|
84
84
|
socket == null ? void 0 : socket.on(`init:${token.key}`, (data) => {
|
|
85
85
|
const jsonToken = Internal3.getJsonToken(token);
|
|
86
|
-
|
|
86
|
+
Internal3.setIntoStore(jsonToken, data, store);
|
|
87
87
|
});
|
|
88
88
|
socket == null ? void 0 : socket.on(
|
|
89
89
|
`next:${token.key}`,
|
|
90
90
|
(data) => {
|
|
91
91
|
const trackerToken = Internal3.getUpdateToken(token);
|
|
92
|
-
|
|
92
|
+
Internal3.setIntoStore(trackerToken, data, store);
|
|
93
93
|
}
|
|
94
94
|
);
|
|
95
95
|
socket == null ? void 0 : socket.emit(`sub:${familyKey}`, subKey);
|
|
@@ -126,19 +126,19 @@ function serverAction(token, socket, store) {
|
|
|
126
126
|
unsubscribeFromLocalUpdates();
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
var myIdState__INTERNAL =
|
|
129
|
+
var myIdState__INTERNAL = AtomIO__namespace.atom({
|
|
130
130
|
key: `myId__INTERNAL`,
|
|
131
131
|
default: void 0
|
|
132
132
|
});
|
|
133
|
-
var myIdState =
|
|
133
|
+
var myIdState = AtomIO__namespace.selector({
|
|
134
134
|
key: `myId`,
|
|
135
135
|
get: ({ get }) => get(myIdState__INTERNAL)
|
|
136
136
|
});
|
|
137
|
-
var optimisticUpdateQueueState =
|
|
137
|
+
var optimisticUpdateQueueState = AtomIO__namespace.atom({
|
|
138
138
|
key: `updateQueue`,
|
|
139
139
|
default: []
|
|
140
140
|
});
|
|
141
|
-
var confirmedUpdateQueueState =
|
|
141
|
+
var confirmedUpdateQueueState = AtomIO__namespace.atom({
|
|
142
142
|
key: `serverConfirmedUpdateQueue`,
|
|
143
143
|
default: []
|
|
144
144
|
});
|
|
@@ -150,8 +150,11 @@ function isRootStore(store) {
|
|
|
150
150
|
|
|
151
151
|
// realtime-client/src/sync-server-action.ts
|
|
152
152
|
function syncAction(token, socket, store) {
|
|
153
|
-
const optimisticQueue =
|
|
154
|
-
|
|
153
|
+
const optimisticQueue = Internal3__namespace.getFromStore(
|
|
154
|
+
optimisticUpdateQueueState,
|
|
155
|
+
store
|
|
156
|
+
);
|
|
157
|
+
const confirmedQueue = Internal3__namespace.getFromStore(confirmedUpdateQueueState, store);
|
|
155
158
|
const unsubscribeFromLocalUpdates = Internal3__namespace.subscribeToTransaction(
|
|
156
159
|
token,
|
|
157
160
|
(clientUpdate) => {
|
|
@@ -159,7 +162,7 @@ function syncAction(token, socket, store) {
|
|
|
159
162
|
(update) => update.id === clientUpdate.id
|
|
160
163
|
);
|
|
161
164
|
if (optimisticUpdateQueueIndex === -1) {
|
|
162
|
-
|
|
165
|
+
Internal3__namespace.setIntoStore(
|
|
163
166
|
optimisticUpdateQueueState,
|
|
164
167
|
(queue) => {
|
|
165
168
|
queue.push(clientUpdate);
|
|
@@ -170,7 +173,7 @@ function syncAction(token, socket, store) {
|
|
|
170
173
|
);
|
|
171
174
|
socket.emit(`tx-run:${token.key}`, clientUpdate);
|
|
172
175
|
} else {
|
|
173
|
-
|
|
176
|
+
Internal3__namespace.setIntoStore(
|
|
174
177
|
optimisticUpdateQueueState,
|
|
175
178
|
(queue) => {
|
|
176
179
|
queue[optimisticUpdateQueueIndex] = clientUpdate;
|
|
@@ -185,7 +188,7 @@ function syncAction(token, socket, store) {
|
|
|
185
188
|
store
|
|
186
189
|
);
|
|
187
190
|
const reconcileUpdates = (optimisticUpdate, confirmedUpdate) => {
|
|
188
|
-
|
|
191
|
+
Internal3__namespace.setIntoStore(
|
|
189
192
|
optimisticUpdateQueueState,
|
|
190
193
|
(queue) => {
|
|
191
194
|
queue.shift();
|
|
@@ -226,7 +229,7 @@ function syncAction(token, socket, store) {
|
|
|
226
229
|
subsequentOptimistic
|
|
227
230
|
);
|
|
228
231
|
const { id, params } = subsequentOptimistic;
|
|
229
|
-
|
|
232
|
+
AtomIO__namespace.runTransaction(token2, id, store)(...params);
|
|
230
233
|
}
|
|
231
234
|
};
|
|
232
235
|
const registerAndAttemptConfirmedUpdate = (confirmedUpdate) => {
|
|
@@ -247,7 +250,7 @@ function syncAction(token, socket, store) {
|
|
|
247
250
|
(update) => update.epoch === confirmedUpdate.epoch
|
|
248
251
|
);
|
|
249
252
|
if (hasEnqueuedOptimisticUpdate) {
|
|
250
|
-
|
|
253
|
+
Internal3__namespace.setIntoStore(
|
|
251
254
|
confirmedUpdateQueueState,
|
|
252
255
|
(queue) => {
|
|
253
256
|
queue.push(confirmedUpdate);
|
|
@@ -291,7 +294,7 @@ function syncAction(token, socket, store) {
|
|
|
291
294
|
}
|
|
292
295
|
function syncState(token, socket, store) {
|
|
293
296
|
const setServedValue = (data) => {
|
|
294
|
-
|
|
297
|
+
Internal3.setIntoStore(token, data, store);
|
|
295
298
|
};
|
|
296
299
|
socket.on(`value:${token.key}`, setServedValue);
|
|
297
300
|
socket.emit(`get:${token.key}`);
|