atom.io 0.15.3 → 0.15.5
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.cjs +29 -16
- package/data/dist/index.cjs.map +1 -1
- package/data/dist/index.js +30 -17
- package/data/dist/index.js.map +1 -1
- package/data/src/join.ts +15 -2
- package/dist/index.cjs +32 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +153 -85
- package/dist/index.js +157 -1
- package/dist/index.js.map +1 -1
- package/internal/dist/index.cjs +98 -159
- package/internal/dist/index.cjs.map +1 -1
- package/internal/dist/index.d.ts +44 -32
- package/internal/dist/index.js +89 -105
- package/internal/dist/index.js.map +1 -1
- package/internal/src/atom/create-regular-atom.ts +1 -1
- package/internal/src/get-environment-data.ts +18 -0
- package/internal/src/index.ts +2 -0
- package/internal/src/ingest-updates/index.ts +3 -0
- package/internal/src/ingest-updates/ingest-atom-update.ts +14 -0
- package/internal/src/ingest-updates/ingest-selector-update.ts +17 -0
- package/internal/src/ingest-updates/ingest-transaction-update.ts +22 -0
- package/internal/src/mutable/tracker.ts +4 -4
- package/internal/src/not-found-error.ts +3 -8
- package/internal/src/operation.ts +4 -4
- package/internal/src/selector/create-read-write-selector.ts +6 -4
- package/internal/src/selector/create-readonly-selector.ts +3 -3
- package/internal/src/selector/register-selector.ts +6 -4
- package/internal/src/selector/update-selector-atoms.ts +2 -2
- package/internal/src/store/deposit.ts +5 -5
- package/internal/src/store/store.ts +4 -4
- package/internal/src/store/withdraw-new-family-member.ts +8 -11
- package/internal/src/store/withdraw.ts +11 -12
- package/internal/src/subscribe/subscribe-to-state.ts +2 -2
- package/internal/src/subscribe/subscribe-to-timeline.ts +4 -4
- package/internal/src/timeline/add-atom-to-timeline.ts +7 -7
- package/internal/src/timeline/create-timeline.ts +29 -21
- package/internal/src/timeline/time-travel.ts +19 -45
- package/internal/src/transaction/apply-transaction.ts +5 -51
- package/internal/src/transaction/build-transaction.ts +9 -2
- package/internal/src/transaction/create-transaction.ts +4 -4
- package/internal/src/transaction/index.ts +2 -2
- package/introspection/dist/index.cjs +9 -9
- package/introspection/dist/index.cjs.map +1 -1
- package/introspection/dist/index.d.ts +6 -6
- package/introspection/dist/index.js +9 -9
- package/introspection/dist/index.js.map +1 -1
- package/introspection/src/attach-atom-index.ts +4 -4
- package/introspection/src/attach-introspection-states.ts +2 -2
- package/introspection/src/attach-selector-index.ts +4 -4
- package/introspection/src/attach-timeline-family.ts +6 -6
- package/introspection/src/attach-timeline-index.ts +6 -4
- package/introspection/src/attach-transaction-index.ts +1 -1
- package/introspection/src/index.ts +1 -1
- package/package.json +11 -12
- package/react/dist/index.cjs.map +1 -1
- package/react/dist/index.d.ts +4 -4
- package/react/dist/index.js.map +1 -1
- package/react/src/store-hooks.ts +5 -5
- package/react-devtools/dist/index.cjs +7 -9
- package/react-devtools/dist/index.cjs.map +1 -1
- package/react-devtools/dist/index.d.ts +10 -265
- package/react-devtools/dist/index.js +7 -9
- package/react-devtools/dist/index.js.map +1 -1
- package/react-devtools/src/StateEditor.tsx +3 -3
- package/react-devtools/src/StateIndex.tsx +3 -3
- package/react-devtools/src/TimelineIndex.tsx +2 -2
- package/react-devtools/src/Updates.tsx +1 -1
- package/realtime-client/dist/index.cjs +68 -66
- package/realtime-client/dist/index.cjs.map +1 -1
- package/realtime-client/dist/index.d.ts +8 -7
- package/realtime-client/dist/index.js +63 -62
- package/realtime-client/dist/index.js.map +1 -1
- package/realtime-client/src/pull-family-member.ts +1 -1
- package/realtime-client/src/pull.ts +1 -1
- package/realtime-client/src/push.ts +2 -3
- package/realtime-client/src/realtime-state.ts +11 -3
- package/realtime-client/src/server-action.ts +65 -65
- package/realtime-react/dist/index.cjs +90 -56
- package/realtime-react/dist/index.cjs.map +1 -1
- package/realtime-react/dist/index.d.ts +11 -6
- package/realtime-react/dist/index.js +89 -55
- package/realtime-react/dist/index.js.map +1 -1
- package/realtime-react/src/on-mount.ts +23 -0
- package/realtime-react/src/realtime-context.tsx +14 -6
- package/realtime-react/src/use-pull-family-member.ts +5 -8
- package/realtime-react/src/use-pull-mutable-family-member.ts +4 -7
- package/realtime-react/src/use-pull-mutable.ts +4 -7
- package/realtime-react/src/use-pull.ts +5 -8
- package/realtime-react/src/use-push.ts +5 -9
- package/realtime-react/src/use-realtime-service.ts +30 -0
- package/realtime-react/src/use-server-action.ts +8 -8
- package/realtime-server/dist/index.cjs +109 -40
- package/realtime-server/dist/index.cjs.map +1 -1
- package/realtime-server/dist/index.d.ts +7 -6
- package/realtime-server/dist/index.js +90 -39
- package/realtime-server/dist/index.js.map +1 -1
- package/realtime-server/src/hook-composition/expose-family.ts +2 -2
- package/realtime-server/src/hook-composition/expose-mutable-family.ts +1 -1
- package/realtime-server/src/hook-composition/expose-single.ts +1 -1
- package/realtime-server/src/hook-composition/index.ts +2 -1
- package/realtime-server/src/hook-composition/receive-state.ts +2 -2
- package/realtime-server/src/hook-composition/receive-transaction.ts +13 -32
- package/realtime-server/src/hook-composition/sync-transaction.ts +92 -0
- package/realtime-testing/dist/index.cjs +3 -3
- 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 +4 -3
- package/src/atom.ts +30 -7
- package/src/dispose.ts +2 -2
- package/src/find-state.ts +64 -0
- package/src/get-state.ts +2 -2
- package/src/index.ts +23 -0
- package/src/logger.ts +1 -0
- package/src/selector.ts +16 -0
- package/src/set-state.ts +2 -2
- package/src/silo.ts +2 -2
- package/src/subscribe.ts +7 -11
- package/src/timeline.ts +20 -12
- package/src/transaction.ts +31 -12
- package/src/validators.ts +74 -0
- package/dist/chunk-K22LR3V6.js +0 -138
- package/dist/chunk-K22LR3V6.js.map +0 -1
- package/internal/src/set-state/copy-mutable-into-new-store.ts +0 -34
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/realtime-context.tsx","../src/use-pull.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["RTC","React","StoreContext"],"mappings":";;;AAAA,SAAS,YAAY;AACrB,YAAY,SAAS;AACrB,YAAY,WAAW;
|
|
1
|
+
{"version":3,"sources":["../src/realtime-context.tsx","../src/use-pull.ts","../src/use-realtime-service.ts","../src/on-mount.ts","../src/use-pull-family-member.ts","../src/use-pull-mutable.ts","../src/use-pull-mutable-family-member.ts","../src/use-push.ts","../src/use-server-action.ts"],"names":["RTC","React","StoreContext"],"mappings":"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","sourcesContent":["import { useI } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\n\nexport type RealtimeReactStore = {\n\tsocket: Socket | null\n\tservices: Map<\n\t\tstring,\n\t\t[consumerCount: number, dispose: (() => void) | undefined]\n\t> | null\n}\n\nexport const RealtimeContext = React.createContext<RealtimeReactStore>({\n\tsocket: null,\n\tservices: null,\n})\n\nexport const RealtimeProvider: React.FC<{\n\tchildren: React.ReactNode\n\tsocket: Socket | null\n}> = ({ children, socket }) => {\n\tconst services = React.useRef(new Map<string, [number, () => void]>()).current\n\tconst setMyId = useI(RTC.myIdState__INTERNAL)\n\tReact.useEffect(() => {\n\t\tsetMyId(socket?.id)\n\t\tsocket?.on(`connect`, () => {\n\t\t\tsetMyId(socket.id)\n\t\t})\n\t\tsocket?.on(`disconnect`, () => {\n\t\t\tsetMyId(undefined)\n\t\t})\n\t}, [socket, setMyId])\n\treturn (\n\t\t<RealtimeContext.Provider value={{ socket, services }}>\n\t\t\t{children}\n\t\t</RealtimeContext.Provider>\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePull<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullState(token, socket, store),\n\t)\n}\n","import * as React from \"react\"\nimport type { Socket } from \"socket.io-client\"\nimport { onMount } from \"./on-mount\"\nimport { RealtimeContext } from \"./realtime-context\"\n\nexport function useRealtimeService(\n\tkey: string,\n\tcreate: (socket: Socket) => (() => void) | undefined,\n): void {\n\tconst { socket, services } = React.useContext(RealtimeContext)\n\tonMount(() => {\n\t\tlet service = services?.get(key)\n\t\tif (service) {\n\t\t\tservice[0]++\n\t\t} else {\n\t\t\tconst dispose = socket ? create(socket) : undefined\n\t\t\tservice = [1, dispose]\n\t\t\tservices?.set(key, service)\n\t\t}\n\t\treturn () => {\n\t\t\tif (service) {\n\t\t\t\tservice[0]--\n\t\t\t\tif (service[0] === 0) {\n\t\t\t\t\tservice[1]?.()\n\t\t\t\t\tservices?.delete(key)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}, [socket?.id])\n}\n","import * as React from \"react\"\n\nexport function onMount(\n\teffect: () => (() => void) | undefined,\n\tdeps?: any[],\n): void {\n\tif (process.env.NODE_ENV === `development`) {\n\t\tconst cleanup = React.useRef<(() => void) | undefined>()\n\t\tReact.useEffect(() => {\n\t\t\tlet dispose = cleanup.current\n\t\t\tif (dispose) {\n\t\t\t\treturn () => {\n\t\t\t\t\tdispose?.()\n\t\t\t\t\tcleanup.current = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\tdispose = effect()\n\t\t\tcleanup.current = dispose\n\t\t}, deps)\n\t} else {\n\t\tReact.useEffect(effect, deps)\n\t}\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullFamilyMember<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullFamilyMember(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutable<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableState(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Transceiver } from \"atom.io/internal\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePullMutableFamilyMember<\n\tT extends Transceiver<any>,\n\tJ extends Json.Serializable,\n>(token: AtomIO.MutableAtomToken<T, J>): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`pull:${token.key}`, (socket) =>\n\t\tRTC.pullMutableFamilyMember(token, socket, store),\n\t)\n}\n","import type * as AtomIO from \"atom.io\"\nimport type { Json } from \"atom.io/json\"\nimport { StoreContext } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function usePush<J extends Json.Serializable>(\n\ttoken: AtomIO.WritableToken<J>,\n): void {\n\tconst store = React.useContext(StoreContext)\n\tuseRealtimeService(`push:${token.key}`, (socket) =>\n\t\tRTC.pushState(token, socket, store),\n\t)\n}\n","import * as AtomIO from \"atom.io\"\nimport { StoreContext, useO } from \"atom.io/react\"\nimport * as RTC from \"atom.io/realtime-client\"\nimport * as React from \"react\"\n\nimport { useRealtimeService } from \"./use-realtime-service\"\n\nexport function useServerAction<ƒ extends AtomIO.ƒn>(\n\ttoken: AtomIO.TransactionToken<ƒ>,\n): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {\n\tconst store = React.useContext(StoreContext)\n\tconst updateQueueState = AtomIO.findState(RTC.updateQueueAtoms, token)\n\tconst updateQueue = useO(updateQueueState)\n\n\tuseRealtimeService(`tx:${token.key}`, (socket) =>\n\t\tRTC.synchronizeTransactionResults(token, socket, updateQueue, store),\n\t)\n\treturn AtomIO.runTransaction(token, store)\n}\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
|
|
3
|
+
export function onMount(
|
|
4
|
+
effect: () => (() => void) | undefined,
|
|
5
|
+
deps?: any[],
|
|
6
|
+
): void {
|
|
7
|
+
if (process.env.NODE_ENV === `development`) {
|
|
8
|
+
const cleanup = React.useRef<(() => void) | undefined>()
|
|
9
|
+
React.useEffect(() => {
|
|
10
|
+
let dispose = cleanup.current
|
|
11
|
+
if (dispose) {
|
|
12
|
+
return () => {
|
|
13
|
+
dispose?.()
|
|
14
|
+
cleanup.current = undefined
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
dispose = effect()
|
|
18
|
+
cleanup.current = dispose
|
|
19
|
+
}, deps)
|
|
20
|
+
} else {
|
|
21
|
+
React.useEffect(effect, deps)
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -3,28 +3,36 @@ import * as RTC from "atom.io/realtime-client"
|
|
|
3
3
|
import * as React from "react"
|
|
4
4
|
import type { Socket } from "socket.io-client"
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export type RealtimeReactStore = {
|
|
7
|
+
socket: Socket | null
|
|
8
|
+
services: Map<
|
|
9
|
+
string,
|
|
10
|
+
[consumerCount: number, dispose: (() => void) | undefined]
|
|
11
|
+
> | null
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const RealtimeContext = React.createContext<RealtimeReactStore>({
|
|
7
15
|
socket: null,
|
|
16
|
+
services: null,
|
|
8
17
|
})
|
|
9
18
|
|
|
10
19
|
export const RealtimeProvider: React.FC<{
|
|
11
20
|
children: React.ReactNode
|
|
12
21
|
socket: Socket | null
|
|
13
22
|
}> = ({ children, socket }) => {
|
|
23
|
+
const services = React.useRef(new Map<string, [number, () => void]>()).current
|
|
14
24
|
const setMyId = useI(RTC.myIdState__INTERNAL)
|
|
15
25
|
React.useEffect(() => {
|
|
16
|
-
|
|
17
|
-
setMyId(socket.id)
|
|
18
|
-
}
|
|
26
|
+
setMyId(socket?.id)
|
|
19
27
|
socket?.on(`connect`, () => {
|
|
20
28
|
setMyId(socket.id)
|
|
21
29
|
})
|
|
22
30
|
socket?.on(`disconnect`, () => {
|
|
23
|
-
setMyId(
|
|
31
|
+
setMyId(undefined)
|
|
24
32
|
})
|
|
25
33
|
}, [socket, setMyId])
|
|
26
34
|
return (
|
|
27
|
-
<RealtimeContext.Provider value={{ socket }}>
|
|
35
|
+
<RealtimeContext.Provider value={{ socket, services }}>
|
|
28
36
|
{children}
|
|
29
37
|
</RealtimeContext.Provider>
|
|
30
38
|
)
|
|
@@ -4,16 +4,13 @@ import { StoreContext } from "atom.io/react"
|
|
|
4
4
|
import * as RTC from "atom.io/realtime-client"
|
|
5
5
|
import * as React from "react"
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
9
|
export function usePullFamilyMember<J extends Json.Serializable>(
|
|
10
|
-
token: AtomIO.
|
|
10
|
+
token: AtomIO.WritableToken<J>,
|
|
11
11
|
): void {
|
|
12
|
-
const { socket } = React.useContext(RealtimeContext)
|
|
13
12
|
const store = React.useContext(StoreContext)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}, [token.key, socket])
|
|
13
|
+
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
14
|
+
RTC.pullFamilyMember(token, socket, store),
|
|
15
|
+
)
|
|
19
16
|
}
|
|
@@ -5,17 +5,14 @@ import { StoreContext } from "atom.io/react"
|
|
|
5
5
|
import * as RTC from "atom.io/realtime-client"
|
|
6
6
|
import * as React from "react"
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
9
9
|
|
|
10
10
|
export function usePullMutableFamilyMember<
|
|
11
11
|
T extends Transceiver<any>,
|
|
12
12
|
J extends Json.Serializable,
|
|
13
13
|
>(token: AtomIO.MutableAtomToken<T, J>): void {
|
|
14
|
-
const { socket } = React.useContext(RealtimeContext)
|
|
15
14
|
const store = React.useContext(StoreContext)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}, [token.key, socket])
|
|
15
|
+
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
16
|
+
RTC.pullMutableFamilyMember(token, socket, store),
|
|
17
|
+
)
|
|
21
18
|
}
|
|
@@ -5,17 +5,14 @@ import { StoreContext } from "atom.io/react"
|
|
|
5
5
|
import * as RTC from "atom.io/realtime-client"
|
|
6
6
|
import * as React from "react"
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
9
9
|
|
|
10
10
|
export function usePullMutable<
|
|
11
11
|
T extends Transceiver<any>,
|
|
12
12
|
J extends Json.Serializable,
|
|
13
13
|
>(token: AtomIO.MutableAtomToken<T, J>): void {
|
|
14
|
-
const { socket } = React.useContext(RealtimeContext)
|
|
15
14
|
const store = React.useContext(StoreContext)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
}, [token.key, socket])
|
|
15
|
+
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
16
|
+
RTC.pullMutableState(token, socket, store),
|
|
17
|
+
)
|
|
21
18
|
}
|
|
@@ -4,16 +4,13 @@ import { StoreContext } from "atom.io/react"
|
|
|
4
4
|
import * as RTC from "atom.io/realtime-client"
|
|
5
5
|
import * as React from "react"
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
9
|
export function usePull<J extends Json.Serializable>(
|
|
10
|
-
token: AtomIO.
|
|
10
|
+
token: AtomIO.WritableToken<J>,
|
|
11
11
|
): void {
|
|
12
|
-
const { socket } = React.useContext(RealtimeContext)
|
|
13
12
|
const store = React.useContext(StoreContext)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
}, [token.key, socket])
|
|
13
|
+
useRealtimeService(`pull:${token.key}`, (socket) =>
|
|
14
|
+
RTC.pullState(token, socket, store),
|
|
15
|
+
)
|
|
19
16
|
}
|
|
@@ -4,17 +4,13 @@ import { StoreContext } from "atom.io/react"
|
|
|
4
4
|
import * as RTC from "atom.io/realtime-client"
|
|
5
5
|
import * as React from "react"
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
8
8
|
|
|
9
9
|
export function usePush<J extends Json.Serializable>(
|
|
10
|
-
token: AtomIO.
|
|
10
|
+
token: AtomIO.WritableToken<J>,
|
|
11
11
|
): void {
|
|
12
|
-
const { socket } = React.useContext(RealtimeContext)
|
|
13
12
|
const store = React.useContext(StoreContext)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return RTC.pushState(token, socket, `use-push:${id}`, store)
|
|
18
|
-
}
|
|
19
|
-
}, [token.key, socket])
|
|
13
|
+
useRealtimeService(`push:${token.key}`, (socket) =>
|
|
14
|
+
RTC.pushState(token, socket, store),
|
|
15
|
+
)
|
|
20
16
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from "react"
|
|
2
|
+
import type { Socket } from "socket.io-client"
|
|
3
|
+
import { onMount } from "./on-mount"
|
|
4
|
+
import { RealtimeContext } from "./realtime-context"
|
|
5
|
+
|
|
6
|
+
export function useRealtimeService(
|
|
7
|
+
key: string,
|
|
8
|
+
create: (socket: Socket) => (() => void) | undefined,
|
|
9
|
+
): void {
|
|
10
|
+
const { socket, services } = React.useContext(RealtimeContext)
|
|
11
|
+
onMount(() => {
|
|
12
|
+
let service = services?.get(key)
|
|
13
|
+
if (service) {
|
|
14
|
+
service[0]++
|
|
15
|
+
} else {
|
|
16
|
+
const dispose = socket ? create(socket) : undefined
|
|
17
|
+
service = [1, dispose]
|
|
18
|
+
services?.set(key, service)
|
|
19
|
+
}
|
|
20
|
+
return () => {
|
|
21
|
+
if (service) {
|
|
22
|
+
service[0]--
|
|
23
|
+
if (service[0] === 0) {
|
|
24
|
+
service[1]?.()
|
|
25
|
+
services?.delete(key)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}, [socket?.id])
|
|
30
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import * as AtomIO from "atom.io"
|
|
2
|
-
import { StoreContext } from "atom.io/react"
|
|
2
|
+
import { StoreContext, useO } from "atom.io/react"
|
|
3
3
|
import * as RTC from "atom.io/realtime-client"
|
|
4
4
|
import * as React from "react"
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useRealtimeService } from "./use-realtime-service"
|
|
7
7
|
|
|
8
8
|
export function useServerAction<ƒ extends AtomIO.ƒn>(
|
|
9
9
|
token: AtomIO.TransactionToken<ƒ>,
|
|
10
10
|
): (...parameters: Parameters<ƒ>) => ReturnType<ƒ> {
|
|
11
11
|
const store = React.useContext(StoreContext)
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
const updateQueueState = AtomIO.findState(RTC.updateQueueAtoms, token)
|
|
13
|
+
const updateQueue = useO(updateQueueState)
|
|
14
|
+
|
|
15
|
+
useRealtimeService(`tx:${token.key}`, (socket) =>
|
|
16
|
+
RTC.synchronizeTransactionResults(token, socket, updateQueue, store),
|
|
17
|
+
)
|
|
18
18
|
return AtomIO.runTransaction(token, store)
|
|
19
19
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var AtomIO6 = require('atom.io');
|
|
4
4
|
var Internal = require('atom.io/internal');
|
|
5
5
|
var json = require('atom.io/json');
|
|
6
6
|
|
|
@@ -22,10 +22,28 @@ function _interopNamespace(e) {
|
|
|
22
22
|
return Object.freeze(n);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
var
|
|
25
|
+
var AtomIO6__namespace = /*#__PURE__*/_interopNamespace(AtomIO6);
|
|
26
26
|
var Internal__namespace = /*#__PURE__*/_interopNamespace(Internal);
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
var __defProp = Object.defineProperty;
|
|
29
|
+
var __defProps = Object.defineProperties;
|
|
30
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
31
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
32
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
33
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
34
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
35
|
+
var __spreadValues = (a, b) => {
|
|
36
|
+
for (var prop in b || (b = {}))
|
|
37
|
+
if (__hasOwnProp.call(b, prop))
|
|
38
|
+
__defNormalProp(a, prop, b[prop]);
|
|
39
|
+
if (__getOwnPropSymbols)
|
|
40
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
41
|
+
if (__propIsEnum.call(b, prop))
|
|
42
|
+
__defNormalProp(a, prop, b[prop]);
|
|
43
|
+
}
|
|
44
|
+
return a;
|
|
45
|
+
};
|
|
46
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
29
47
|
var useExposeSingle = ({
|
|
30
48
|
socket,
|
|
31
49
|
store = Internal__namespace.IMPLICIT.STORE
|
|
@@ -38,7 +56,7 @@ var useExposeSingle = ({
|
|
|
38
56
|
unsubscribeFromStateUpdates = null;
|
|
39
57
|
};
|
|
40
58
|
const fillSubRequest = () => {
|
|
41
|
-
socket.emit(`serve:${token.key}`,
|
|
59
|
+
socket.emit(`serve:${token.key}`, AtomIO6__namespace.getState(token, store));
|
|
42
60
|
unsubscribeFromStateUpdates = Internal__namespace.subscribeToState(
|
|
43
61
|
token,
|
|
44
62
|
({ newValue }) => {
|
|
@@ -85,13 +103,13 @@ var useExposeFamily = ({
|
|
|
85
103
|
const fillSubRequest = (subKey) => {
|
|
86
104
|
var _a;
|
|
87
105
|
if (subKey === void 0) {
|
|
88
|
-
const keys =
|
|
106
|
+
const keys = AtomIO6__namespace.getState(index, store);
|
|
89
107
|
for (const key of keys) {
|
|
90
108
|
const token = family(key);
|
|
91
109
|
socket.emit(
|
|
92
110
|
`serve:${family.key}`,
|
|
93
111
|
json.parseJson(((_a = token.family) == null ? void 0 : _a.subKey) || `null`),
|
|
94
|
-
|
|
112
|
+
AtomIO6__namespace.getState(token, store)
|
|
95
113
|
);
|
|
96
114
|
}
|
|
97
115
|
const unsubscribeFromTokenCreation = subscribeToTokenCreation(
|
|
@@ -118,7 +136,7 @@ var useExposeFamily = ({
|
|
|
118
136
|
socket.on(`unsub:${family.key}`, fillFamilyUnsubRequest);
|
|
119
137
|
} else {
|
|
120
138
|
const token = family(subKey);
|
|
121
|
-
socket.emit(`serve:${token.key}`,
|
|
139
|
+
socket.emit(`serve:${token.key}`, AtomIO6__namespace.getState(token, store));
|
|
122
140
|
const unsubscribe = Internal.subscribeToState(
|
|
123
141
|
token,
|
|
124
142
|
({ newValue }) => {
|
|
@@ -161,7 +179,7 @@ var useExposeMutable = ({
|
|
|
161
179
|
unsubscribeFromStateUpdates = null;
|
|
162
180
|
};
|
|
163
181
|
const fillSubRequest = () => {
|
|
164
|
-
socket.emit(`init:${token.key}`,
|
|
182
|
+
socket.emit(`init:${token.key}`, AtomIO6__namespace.getState(jsonToken, store));
|
|
165
183
|
unsubscribeFromStateUpdates = Internal.subscribeToState(
|
|
166
184
|
trackerToken,
|
|
167
185
|
({ newValue }) => {
|
|
@@ -204,7 +222,7 @@ var useExposeMutableFamily = ({
|
|
|
204
222
|
const fillSubRequest = (subKey) => {
|
|
205
223
|
var _a;
|
|
206
224
|
if (subKey === void 0) {
|
|
207
|
-
const keys =
|
|
225
|
+
const keys = AtomIO6__namespace.getState(index, store);
|
|
208
226
|
for (const key of keys) {
|
|
209
227
|
const token = family(key);
|
|
210
228
|
const jsonToken = Internal.getJsonToken(token);
|
|
@@ -212,7 +230,7 @@ var useExposeMutableFamily = ({
|
|
|
212
230
|
socket.emit(
|
|
213
231
|
`init:${family.key}`,
|
|
214
232
|
json.parseJson(((_a = jsonToken.family) == null ? void 0 : _a.subKey) || `null`),
|
|
215
|
-
|
|
233
|
+
AtomIO6__namespace.getState(jsonToken, store)
|
|
216
234
|
);
|
|
217
235
|
const unsubFromUpdates = Internal.subscribeToState(
|
|
218
236
|
trackerToken,
|
|
@@ -238,7 +256,7 @@ var useExposeMutableFamily = ({
|
|
|
238
256
|
socket.emit(
|
|
239
257
|
`init:${family.key}`,
|
|
240
258
|
json.parseJson(((_a2 = jsonToken.family) == null ? void 0 : _a2.subKey) || `null`),
|
|
241
|
-
|
|
259
|
+
AtomIO6__namespace.getState(jsonToken, store)
|
|
242
260
|
);
|
|
243
261
|
const unsubFromUpdates = Internal.subscribeToState(
|
|
244
262
|
trackerToken,
|
|
@@ -262,7 +280,7 @@ var useExposeMutableFamily = ({
|
|
|
262
280
|
const token = family(subKey);
|
|
263
281
|
const jsonToken = Internal.getJsonToken(token);
|
|
264
282
|
const updateToken = Internal.getUpdateToken(token);
|
|
265
|
-
socket.emit(`init:${token.key}`,
|
|
283
|
+
socket.emit(`init:${token.key}`, AtomIO6__namespace.getState(jsonToken, store));
|
|
266
284
|
const unsubscribe = Internal.subscribeToState(
|
|
267
285
|
updateToken,
|
|
268
286
|
({ newValue }) => {
|
|
@@ -291,52 +309,103 @@ var useExposeMutableFamily = ({
|
|
|
291
309
|
};
|
|
292
310
|
};
|
|
293
311
|
};
|
|
312
|
+
var useReceiveState = ({ socket, store }) => {
|
|
313
|
+
return function receiveState(token) {
|
|
314
|
+
const publish = (newValue) => AtomIO6.setState(token, newValue, store);
|
|
315
|
+
const fillPubUnclaim = () => {
|
|
316
|
+
socket.off(`pub:${token.key}`, publish);
|
|
317
|
+
socket.off(`unclaim:${token.key}`, fillPubUnclaim);
|
|
318
|
+
};
|
|
319
|
+
const fillPubClaim = () => {
|
|
320
|
+
socket.on(`pub:${token.key}`, publish);
|
|
321
|
+
socket.on(`unclaim:${token.key}`, fillPubUnclaim);
|
|
322
|
+
};
|
|
323
|
+
socket.on(`claim:${token.key}`, fillPubClaim);
|
|
324
|
+
return () => {
|
|
325
|
+
socket.off(`claim:${token.key}`, fillPubClaim);
|
|
326
|
+
socket.off(`pub:${token.key}`, publish);
|
|
327
|
+
};
|
|
328
|
+
};
|
|
329
|
+
};
|
|
294
330
|
var useReceiveTransaction = ({ socket, store }) => {
|
|
295
331
|
return function receiveTransaction(tx) {
|
|
296
|
-
const fillTransactionRequest = (update) =>
|
|
297
|
-
|
|
298
|
-
|
|
332
|
+
const fillTransactionRequest = (update) => {
|
|
333
|
+
const performanceKey = `tx-run:${tx.key}:${update.id}`;
|
|
334
|
+
const performanceKeyStart = `${performanceKey}:start`;
|
|
335
|
+
const performanceKeyEnd = `${performanceKey}:end`;
|
|
336
|
+
performance.mark(performanceKeyStart);
|
|
337
|
+
AtomIO6__namespace.runTransaction(tx, store)(...update.params);
|
|
338
|
+
performance.mark(performanceKeyEnd);
|
|
339
|
+
const metric = performance.measure(
|
|
340
|
+
performanceKey,
|
|
341
|
+
performanceKeyStart,
|
|
342
|
+
performanceKeyEnd
|
|
343
|
+
);
|
|
344
|
+
store == null ? void 0 : store.logger.info(`\u{1F680}`, `transaction`, tx.key, update.id, metric.duration);
|
|
345
|
+
};
|
|
346
|
+
socket.on(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
347
|
+
return () => socket.off(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
299
348
|
};
|
|
300
349
|
};
|
|
350
|
+
var completeUpdateAtoms = AtomIO6__namespace.atomFamily({
|
|
351
|
+
key: `completeUpdate`,
|
|
352
|
+
default: null
|
|
353
|
+
});
|
|
354
|
+
var transactionRedactorAtoms = AtomIO6__namespace.atomFamily({
|
|
355
|
+
key: `transactionRedactor`,
|
|
356
|
+
default: { filter: (updates) => updates }
|
|
357
|
+
});
|
|
358
|
+
var redactedUpdateSelectors = AtomIO6__namespace.selectorFamily({
|
|
359
|
+
key: `redactedUpdate`,
|
|
360
|
+
get: ([transactionKey, updateId]) => ({ get, find }) => {
|
|
361
|
+
const update = get(find(completeUpdateAtoms, updateId));
|
|
362
|
+
const { filter } = get(find(transactionRedactorAtoms, transactionKey));
|
|
363
|
+
if (update && filter) {
|
|
364
|
+
return __spreadProps(__spreadValues({}, update), { updates: filter(update.updates) });
|
|
365
|
+
}
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
301
369
|
function useSyncTransaction({
|
|
302
370
|
socket,
|
|
303
371
|
store = Internal__namespace.IMPLICIT.STORE
|
|
304
372
|
}) {
|
|
305
|
-
return function
|
|
306
|
-
|
|
373
|
+
return function syncTransaction(tx, filter) {
|
|
374
|
+
if (filter) {
|
|
375
|
+
AtomIO6__namespace.setState(
|
|
376
|
+
AtomIO6__namespace.findState(transactionRedactorAtoms, tx.key),
|
|
377
|
+
{ filter },
|
|
378
|
+
store
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
const fillTransactionRequest = (update) => {
|
|
382
|
+
AtomIO6__namespace.runTransaction(tx, store, update.id)(...update.params);
|
|
383
|
+
};
|
|
384
|
+
socket.on(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
385
|
+
const fillTransactionSubscriptionRequest = () => {
|
|
307
386
|
const unsubscribe = Internal__namespace.subscribeToTransaction(
|
|
308
387
|
tx,
|
|
309
|
-
(
|
|
388
|
+
(update) => {
|
|
310
389
|
unsubscribe();
|
|
311
|
-
|
|
390
|
+
const updateState = AtomIO6__namespace.findState(completeUpdateAtoms, update.id);
|
|
391
|
+
AtomIO6__namespace.setState(updateState, update, store);
|
|
392
|
+
const toEmit = filter ? AtomIO6__namespace.getState(
|
|
393
|
+
AtomIO6__namespace.findState(redactedUpdateSelectors, [tx.key, update.id]),
|
|
394
|
+
store
|
|
395
|
+
) : update;
|
|
396
|
+
socket.emit(`tx-new:${tx.key}`, toEmit);
|
|
312
397
|
},
|
|
313
|
-
`
|
|
398
|
+
`tx-sub:${tx.key}:${socket.id}`,
|
|
314
399
|
store
|
|
315
400
|
);
|
|
316
|
-
|
|
401
|
+
socket.on(`tx-unsub:${tx.key}`, unsubscribe);
|
|
317
402
|
};
|
|
318
|
-
socket.on(`tx:${tx.key}`,
|
|
319
|
-
return () => socket.off(`tx:${tx.key}`, fillTransactionRequest);
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
var useReceiveState = ({ socket, store }) => {
|
|
323
|
-
return function receiveState(token) {
|
|
324
|
-
const publish = (newValue) => AtomIO4.setState(token, newValue, store);
|
|
325
|
-
const fillPubUnclaim = () => {
|
|
326
|
-
socket.off(`pub:${token.key}`, publish);
|
|
327
|
-
socket.off(`unclaim:${token.key}`, fillPubUnclaim);
|
|
328
|
-
};
|
|
329
|
-
const fillPubClaim = () => {
|
|
330
|
-
socket.on(`pub:${token.key}`, publish);
|
|
331
|
-
socket.on(`unclaim:${token.key}`, fillPubUnclaim);
|
|
332
|
-
};
|
|
333
|
-
socket.on(`claim:${token.key}`, fillPubClaim);
|
|
403
|
+
socket.on(`tx-sub:${tx.key}`, fillTransactionSubscriptionRequest);
|
|
334
404
|
return () => {
|
|
335
|
-
socket.off(`
|
|
336
|
-
socket.off(`pub:${token.key}`, publish);
|
|
405
|
+
socket.off(`tx-run:${tx.key}`, fillTransactionRequest);
|
|
337
406
|
};
|
|
338
407
|
};
|
|
339
|
-
}
|
|
408
|
+
}
|
|
340
409
|
|
|
341
410
|
exports.useExposeFamily = useExposeFamily;
|
|
342
411
|
exports.useExposeMutable = useExposeMutable;
|