atom.io 0.36.0 → 0.36.2
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/internal/index.d.ts +93 -73
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +233 -248
- package/dist/internal/index.js.map +1 -1
- package/dist/introspection/index.d.ts +5 -6
- package/dist/introspection/index.d.ts.map +1 -1
- package/dist/introspection/index.js +2 -3
- package/dist/introspection/index.js.map +1 -1
- package/dist/main/index.d.ts +29 -37
- package/dist/main/index.d.ts.map +1 -1
- package/dist/main/index.js +8 -9
- package/dist/main/index.js.map +1 -1
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react-devtools/index.d.ts.map +1 -1
- package/dist/react-devtools/index.js.map +1 -1
- package/dist/realtime-client/index.d.ts +7 -8
- package/dist/realtime-client/index.d.ts.map +1 -1
- package/dist/realtime-client/index.js +3 -4
- package/dist/realtime-client/index.js.map +1 -1
- package/dist/realtime-react/index.d.ts +4 -4
- package/dist/realtime-react/index.d.ts.map +1 -1
- package/dist/realtime-react/index.js.map +1 -1
- package/dist/realtime-server/index.d.ts +2 -2
- package/dist/realtime-server/index.d.ts.map +1 -1
- package/dist/realtime-server/index.js.map +1 -1
- package/dist/transceivers/set-rtx/index.d.ts +9 -2
- package/dist/transceivers/set-rtx/index.d.ts.map +1 -1
- package/dist/transceivers/set-rtx/index.js +3 -0
- package/dist/transceivers/set-rtx/index.js.map +1 -1
- package/package.json +3 -3
- package/src/internal/atom/create-regular-atom.ts +5 -5
- package/src/internal/atom/has-role.ts +12 -0
- package/src/internal/atom/index.ts +1 -0
- package/src/internal/caching.ts +60 -41
- package/src/internal/families/find-in-store.ts +1 -1
- package/src/internal/families/get-family-of-token.ts +1 -1
- package/src/internal/families/init-family-member.ts +1 -1
- package/src/internal/families/seek-in-store.ts +1 -1
- package/src/internal/get-state/read-or-compute-value.ts +26 -21
- package/src/internal/index.ts +8 -8
- package/src/internal/join/create-join.ts +3 -2
- package/src/internal/join/join-internal.ts +7 -4
- package/src/internal/mutable/create-mutable-atom-family.ts +6 -5
- package/src/internal/mutable/create-mutable-atom.ts +1 -1
- package/src/internal/mutable/get-json-family.ts +1 -1
- package/src/internal/mutable/get-json-token.ts +1 -1
- package/src/internal/mutable/get-update-family.ts +1 -1
- package/src/internal/mutable/get-update-token.ts +1 -1
- package/src/internal/mutable/tracker-family.ts +27 -31
- package/src/internal/mutable/tracker.ts +29 -23
- package/src/internal/mutable/transceiver.ts +11 -10
- package/src/internal/selector/create-readonly-held-selector.ts +2 -2
- package/src/internal/selector/create-readonly-pure-selector.ts +2 -2
- package/src/internal/selector/create-writable-held-selector.ts +3 -4
- package/src/internal/selector/create-writable-pure-selector.ts +3 -3
- package/src/internal/set-state/evict-downstream.ts +17 -15
- package/src/internal/set-state/index.ts +1 -0
- package/src/internal/set-state/reset-in-store.ts +6 -50
- package/src/internal/set-state/set-atom.ts +17 -24
- package/src/internal/set-state/set-into-store.ts +29 -13
- package/src/internal/store/counterfeit.ts +1 -1
- package/src/internal/store/deposit.ts +7 -8
- package/src/internal/store/store.ts +6 -6
- package/src/internal/store/withdraw.ts +8 -8
- package/src/internal/subscribe/subscribe-in-store.ts +8 -8
- package/src/internal/subscribe/subscribe-to-timeline.ts +2 -2
- package/src/internal/subscribe/subscribe-to-transaction.ts +2 -2
- package/src/internal/timeline/create-timeline.ts +3 -3
- package/src/internal/transaction/act-upon-store.ts +2 -2
- package/src/internal/transaction/apply-transaction.ts +2 -2
- package/src/internal/transaction/build-transaction.ts +2 -2
- package/src/internal/transaction/create-transaction.ts +3 -3
- package/src/internal/transaction/index.ts +2 -2
- package/src/internal/transaction/is-root-store.ts +4 -2
- package/src/internal/utility-types.ts +1 -1
- package/src/introspection/attach-introspection-states.ts +3 -3
- package/src/introspection/attach-transaction-index.ts +4 -4
- package/src/introspection/attach-transaction-logs.ts +4 -4
- package/src/introspection/auditor.ts +3 -3
- package/src/main/atom.ts +4 -4
- package/src/main/dispose-state.ts +4 -3
- package/src/main/find-state.ts +1 -1
- package/src/main/get-state.ts +6 -5
- package/src/main/reset-state.ts +3 -3
- package/src/main/set-state.ts +3 -3
- package/src/main/subscribe.ts +3 -3
- package/src/main/tokens.ts +9 -18
- package/src/main/transaction.ts +13 -15
- package/src/react/use-json.ts +5 -5
- package/src/react-devtools/TransactionIndex.tsx +3 -3
- package/src/react-devtools/Updates.tsx +2 -2
- package/src/realtime-client/continuity/register-and-attempt-confirmed-update.ts +2 -2
- package/src/realtime-client/pull-mutable-atom-family-member.ts +8 -13
- package/src/realtime-client/pull-mutable-atom.ts +5 -8
- package/src/realtime-client/push-state.ts +6 -5
- package/src/realtime-client/server-action.ts +5 -4
- package/src/realtime-react/use-pull-mutable-atom.ts +1 -1
- package/src/realtime-react/use-pull-mutable-family-member.ts +1 -1
- package/src/realtime-react/use-server-action.ts +2 -2
- package/src/realtime-server/realtime-mutable-family-provider.ts +1 -1
- package/src/realtime-server/realtime-mutable-provider.ts +1 -1
- package/src/transceivers/set-rtx/set-rtx.ts +14 -1
- package/src/internal/set-state/copy-mutable-if-needed.ts +0 -29
|
@@ -3,7 +3,7 @@ import type {
|
|
|
3
3
|
TimelineUpdate,
|
|
4
4
|
TransactionUpdate,
|
|
5
5
|
} from "atom.io"
|
|
6
|
-
import type {
|
|
6
|
+
import type { Fn } from "atom.io/internal"
|
|
7
7
|
import { discoverType, prettyJson } from "atom.io/introspection"
|
|
8
8
|
import { stringifyJson } from "atom.io/json"
|
|
9
9
|
import * as React from "react"
|
|
@@ -37,7 +37,7 @@ const AtomUpdateFC: React.FC<{
|
|
|
37
37
|
|
|
38
38
|
const TransactionUpdateFC: React.FC<{
|
|
39
39
|
serialNumber: number
|
|
40
|
-
transactionUpdate: TransactionUpdate<
|
|
40
|
+
transactionUpdate: TransactionUpdate<Fn>
|
|
41
41
|
}> = ({ serialNumber, transactionUpdate }) => {
|
|
42
42
|
return (
|
|
43
43
|
<article
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
3
|
import {
|
|
4
4
|
actUponStore,
|
|
5
5
|
getEpochNumberOfContinuity,
|
|
@@ -22,7 +22,7 @@ export const useRegisterAndAttemptConfirmedUpdate =
|
|
|
22
22
|
optimisticUpdates: AtomIO.TransactionUpdate<any>[],
|
|
23
23
|
confirmedUpdates: AtomIO.TransactionUpdate<any>[],
|
|
24
24
|
) =>
|
|
25
|
-
(confirmed: AtomIO.TransactionUpdate<
|
|
25
|
+
(confirmed: AtomIO.TransactionUpdate<Fn>): void => {
|
|
26
26
|
function reconcileEpoch(
|
|
27
27
|
optimisticUpdate: AtomIO.TransactionUpdate<any>,
|
|
28
28
|
confirmedUpdate: AtomIO.TransactionUpdate<any>,
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type { AsJSON, Store, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
|
|
3
3
|
import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
|
|
4
4
|
import { parseJson } from "atom.io/json"
|
|
5
5
|
import type { Socket } from "socket.io-client"
|
|
6
6
|
|
|
7
7
|
/* eslint-disable no-console */
|
|
8
8
|
|
|
9
|
-
export function pullMutableAtomFamilyMember<
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
token: AtomIO.MutableAtomToken<T>,
|
|
13
|
-
): () => void {
|
|
9
|
+
export function pullMutableAtomFamilyMember<
|
|
10
|
+
T extends Transceiver<any, any, any>,
|
|
11
|
+
>(store: Store, socket: Socket, token: AtomIO.MutableAtomToken<T>): () => void {
|
|
14
12
|
if (!(`family` in token)) {
|
|
15
13
|
console.error(`Token is not a family member:`, token)
|
|
16
14
|
return () => {}
|
|
@@ -21,13 +19,10 @@ export function pullMutableAtomFamilyMember<T extends Transceiver<any, any>>(
|
|
|
21
19
|
const jsonToken = getJsonToken(store, token)
|
|
22
20
|
setIntoStore(store, jsonToken, data)
|
|
23
21
|
})
|
|
24
|
-
socket.on(
|
|
25
|
-
|
|
26
|
-
(
|
|
27
|
-
|
|
28
|
-
setIntoStore(store, trackerToken, data)
|
|
29
|
-
},
|
|
30
|
-
)
|
|
22
|
+
socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
|
|
23
|
+
const trackerToken = getUpdateToken(token)
|
|
24
|
+
setIntoStore(store, trackerToken, data)
|
|
25
|
+
})
|
|
31
26
|
socket.emit(`sub:${familyKey}`, subKey)
|
|
32
27
|
return () => {
|
|
33
28
|
socket.off(`serve:${token.key}`)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type { AsJSON, Store, Transceiver } from "atom.io/internal"
|
|
2
|
+
import type { AsJSON, SignalFrom, Store, Transceiver } from "atom.io/internal"
|
|
3
3
|
import { getJsonToken, getUpdateToken, setIntoStore } from "atom.io/internal"
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
|
-
export function pullMutableAtom<T extends Transceiver<any, any>>(
|
|
6
|
+
export function pullMutableAtom<T extends Transceiver<any, any, any>>(
|
|
7
7
|
store: Store,
|
|
8
8
|
socket: Socket,
|
|
9
9
|
token: AtomIO.MutableAtomToken<T>,
|
|
@@ -13,12 +13,9 @@ export function pullMutableAtom<T extends Transceiver<any, any>>(
|
|
|
13
13
|
socket.on(`init:${token.key}`, (data: AsJSON<T>) => {
|
|
14
14
|
setIntoStore(store, jsonToken, data)
|
|
15
15
|
})
|
|
16
|
-
socket.on(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
setIntoStore(store, updateToken, data)
|
|
20
|
-
},
|
|
21
|
-
)
|
|
16
|
+
socket.on(`next:${token.key}`, (data: SignalFrom<T>) => {
|
|
17
|
+
setIntoStore(store, updateToken, data)
|
|
18
|
+
})
|
|
22
19
|
socket.emit(`sub:${token.key}`)
|
|
23
20
|
return () => {
|
|
24
21
|
socket.off(`init:${token.key}`)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
1
|
+
import type { WritableToken } from "atom.io"
|
|
2
|
+
import type { Store } from "atom.io/internal"
|
|
3
|
+
import { subscribeToState } from "atom.io/internal"
|
|
3
4
|
import type { Json } from "atom.io/json"
|
|
4
5
|
import type { Socket } from "socket.io-client"
|
|
5
6
|
|
|
6
7
|
export function pushState<J extends Json.Serializable>(
|
|
7
|
-
store:
|
|
8
|
+
store: Store,
|
|
8
9
|
socket: Socket,
|
|
9
|
-
token:
|
|
10
|
+
token: WritableToken<J>,
|
|
10
11
|
): () => void {
|
|
11
12
|
socket.emit(`claim:${token.key}`)
|
|
12
|
-
|
|
13
|
+
subscribeToState(store, token, `push`, ({ newValue }) => {
|
|
13
14
|
socket.emit(`pub:${token.key}`, newValue)
|
|
14
15
|
})
|
|
15
16
|
return () => {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import
|
|
2
|
+
import type { Fn, Store } from "atom.io/internal"
|
|
3
|
+
import { subscribeToTransaction } from "atom.io/internal"
|
|
3
4
|
import type { Socket } from "socket.io-client"
|
|
4
5
|
|
|
5
|
-
export function serverAction<F extends
|
|
6
|
-
store:
|
|
6
|
+
export function serverAction<F extends Fn>(
|
|
7
|
+
store: Store,
|
|
7
8
|
socket: Socket,
|
|
8
9
|
token: AtomIO.TransactionToken<F>,
|
|
9
10
|
): () => void {
|
|
10
|
-
const unsubscribeFromLocalUpdates =
|
|
11
|
+
const unsubscribeFromLocalUpdates = subscribeToTransaction(
|
|
11
12
|
store,
|
|
12
13
|
token,
|
|
13
14
|
`tx-run:${token.key}:${socket.id}`,
|
|
@@ -6,7 +6,7 @@ import * as React from "react"
|
|
|
6
6
|
|
|
7
7
|
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
|
-
export function usePullMutable<T extends Transceiver<any, any>>(
|
|
9
|
+
export function usePullMutable<T extends Transceiver<any, any, any>>(
|
|
10
10
|
token: AtomIO.MutableAtomToken<T>,
|
|
11
11
|
): T {
|
|
12
12
|
const store = React.useContext(StoreContext)
|
|
@@ -9,7 +9,7 @@ import * as React from "react"
|
|
|
9
9
|
import { useRealtimeService } from "./use-realtime-service"
|
|
10
10
|
|
|
11
11
|
export function usePullMutableAtomFamilyMember<
|
|
12
|
-
T extends Transceiver<any, any>,
|
|
12
|
+
T extends Transceiver<any, any, any>,
|
|
13
13
|
K extends Canonical,
|
|
14
14
|
Key extends K,
|
|
15
15
|
>(familyToken: AtomIO.MutableAtomFamilyToken<T, K>, key: Key): T {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as AtomIO from "atom.io"
|
|
2
|
-
import type {
|
|
2
|
+
import type { Fn } from "atom.io/internal"
|
|
3
3
|
import { actUponStore, arbitrary } from "atom.io/internal"
|
|
4
4
|
import { StoreContext } from "atom.io/react"
|
|
5
5
|
import * as RTC from "atom.io/realtime-client"
|
|
@@ -7,7 +7,7 @@ import * as React from "react"
|
|
|
7
7
|
|
|
8
8
|
import { useRealtimeService } from "./use-realtime-service"
|
|
9
9
|
|
|
10
|
-
export function useServerAction<F extends
|
|
10
|
+
export function useServerAction<F extends Fn>(
|
|
11
11
|
token: AtomIO.TransactionToken<F>,
|
|
12
12
|
): (...parameters: Parameters<F>) => ReturnType<F> {
|
|
13
13
|
const store = React.useContext(StoreContext)
|
|
@@ -21,7 +21,7 @@ export function realtimeMutableFamilyProvider({
|
|
|
21
21
|
store = IMPLICIT.STORE,
|
|
22
22
|
}: ServerConfig) {
|
|
23
23
|
return function mutableFamilyProvider<
|
|
24
|
-
T extends Transceiver<any, any>,
|
|
24
|
+
T extends Transceiver<any, any, any>,
|
|
25
25
|
K extends Canonical,
|
|
26
26
|
>(
|
|
27
27
|
family: AtomIO.MutableAtomFamilyToken<T, K>,
|
|
@@ -17,7 +17,7 @@ export function realtimeMutableProvider({
|
|
|
17
17
|
store = IMPLICIT.STORE,
|
|
18
18
|
}: ServerConfig) {
|
|
19
19
|
return function mutableProvider<
|
|
20
|
-
Core extends Transceiver<Json.Serializable, Json.Serializable>,
|
|
20
|
+
Core extends Transceiver<any, Json.Serializable, Json.Serializable>,
|
|
21
21
|
>(token: AtomIO.MutableAtomToken<Core>): () => void {
|
|
22
22
|
let unsubscribeFromStateUpdates: (() => void) | null = null
|
|
23
23
|
|
|
@@ -7,6 +7,13 @@ export type SetUpdateType = `add` | `clear` | `del` | `tx`
|
|
|
7
7
|
export type SetUpdate = `${SetUpdateType}:${string}`
|
|
8
8
|
export type NumberedSetUpdate = `${number}=${SetUpdate}`
|
|
9
9
|
|
|
10
|
+
export interface SetRTXView<P extends primitive> extends ReadonlySet<P> {
|
|
11
|
+
readonly cache: ReadonlyArray<NumberedSetUpdate | null>
|
|
12
|
+
readonly cacheLimit: number
|
|
13
|
+
readonly cacheIdx: number
|
|
14
|
+
readonly cacheUpdateNumber: number
|
|
15
|
+
}
|
|
16
|
+
|
|
10
17
|
export interface SetRTXJson<P extends primitive> extends Json.Object {
|
|
11
18
|
members: P[]
|
|
12
19
|
cache: (NumberedSetUpdate | null)[]
|
|
@@ -16,7 +23,9 @@ export interface SetRTXJson<P extends primitive> extends Json.Object {
|
|
|
16
23
|
}
|
|
17
24
|
export class SetRTX<P extends primitive>
|
|
18
25
|
extends Set<P>
|
|
19
|
-
implements
|
|
26
|
+
implements
|
|
27
|
+
Transceiver<SetRTXView<P>, NumberedSetUpdate, SetRTXJson<P>>,
|
|
28
|
+
Lineage
|
|
20
29
|
{
|
|
21
30
|
public mode: TransceiverMode = `record`
|
|
22
31
|
public readonly subject: Subject<SetUpdate> = new Subject<SetUpdate>()
|
|
@@ -42,6 +51,10 @@ export class SetRTX<P extends primitive>
|
|
|
42
51
|
}
|
|
43
52
|
}
|
|
44
53
|
|
|
54
|
+
public view(): SetRTXView<P> {
|
|
55
|
+
return this
|
|
56
|
+
}
|
|
57
|
+
|
|
45
58
|
public toJSON(): SetRTXJson<P> {
|
|
46
59
|
return {
|
|
47
60
|
members: [...this],
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { MutableAtom, Transceiver } from ".."
|
|
2
|
-
import { Tracker } from "../mutable"
|
|
3
|
-
import type { Store } from "../store"
|
|
4
|
-
|
|
5
|
-
export function copyMutableIfNeeded<T extends Transceiver<any, any>>(
|
|
6
|
-
target: Store,
|
|
7
|
-
atom: MutableAtom<T>,
|
|
8
|
-
origin: Store,
|
|
9
|
-
): T {
|
|
10
|
-
const originValue = origin.valueMap.get(atom.key) as
|
|
11
|
-
| Transceiver<any, any>
|
|
12
|
-
| undefined
|
|
13
|
-
const targetValue = target.valueMap.get(atom.key)
|
|
14
|
-
|
|
15
|
-
if (originValue !== targetValue) {
|
|
16
|
-
return targetValue
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (originValue === undefined) {
|
|
20
|
-
return new atom.class()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
origin.logger.info(`📃`, `atom`, atom.key, `copying`)
|
|
24
|
-
const jsonValue = originValue.toJSON()
|
|
25
|
-
const copiedValue = atom.class.fromJSON(jsonValue)
|
|
26
|
-
target.valueMap.set(atom.key, copiedValue)
|
|
27
|
-
new Tracker(atom, origin)
|
|
28
|
-
return copiedValue
|
|
29
|
-
}
|