Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

runtime.ts

76 lines2.7 KB

1import { Connection } from "@t3tools/client-runtime/connection";
2import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell";
3import { PullRequestDiffLoader } from "@t3tools/client-runtime/state/pull-requests";
4import {
5 BoundedThreadSnapshotLoader,
6 ThreadHistoryController,
7} from "@t3tools/client-runtime/state/threads";
8import { Platform } from "react-native";
9import * as Layer from "effect/Layer";
10import { Atom } from "effect/reactivity";
11​
12import type { FoundationHotModule } from "../lib/foundation-fast-refresh";
13import { hotSwappableAtomRuntime } from "../lib/hot-swappable-atom-runtime";
14import * as Runtime from "../lib/runtime";
15import { appAtomRegistry } from "../state/atom-registry";
16import * as BackgroundActivity from "./background-activity";
17import * as ConnectionPlatform from "./platform";
18​
19declare const module: { readonly hot?: FoundationHotModule } | undefined;
20​
21const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer));
22​
23const layerSnapshotLoader = Layer.mergeAll(
24 PullRequestDiffLoader.layer,
25 BoundedThreadSnapshotLoader.layer,
26 ShellSnapshotLoader.layer,
27 ThreadHistoryController.layer,
28);
29​
30type ConnectionLayerSource =
31 | typeof Connection.layer
32 | typeof layerSnapshotLoader
33 | typeof Runtime.layer
34 | typeof ConnectionPlatform.layer
35 | typeof BackgroundActivity.layerObserver
36 | typeof BackgroundActivity.layerReporter;
37​
38const layerProvidedClientConnection = layerSnapshotLoader.pipe(
39 Layer.provideMerge(
40 Connection.layerWithOptions({
41 routeOrder: Platform.OS === "android" ? "saved" : "responsive",
42 omitKeybindings: true,
43 usageLimitSources: true,
44 hostPressure: true,
45 usageLimitsCommand: true,
46 providerCatalogsOnDemand: true,
47 providerCatalogDigests: true,
48 providerStatusDeltas: true,
49 // Halves idle pings. The timeout is checked on ping ticks, after an unanswered ping
50 // and 15 s with no frame: within 25 s of the last frame (20 s at the 5 s default),
51 // and a host stalled for 10 s can lose the socket (15 s at the default).
52 pingInterval: "10 seconds",
53 }),
54 ),
55 Layer.provideMerge(
56 Layer.mergeAll(
57 Runtime.layer,
58 layerProvidedConnectionPlatform,
59 BackgroundActivity.layerObserver,
60 ),
61 ),
62);
63​
64const layerConnection = BackgroundActivity.layerReporter.pipe(
65 Layer.provideMerge(layerProvidedClientConnection),
66);
67​
68export const connectionAtomRuntime: Atom.AtomRuntime<
69 Layer.Success<ConnectionLayerSource>,
70 Layer.Error<ConnectionLayerSource>
71> = hotSwappableAtomRuntime({
72 id: "t3.mobile.connection-runtime",
73 hotModule: typeof module === "undefined" ? undefined : module.hot,
74 registry: appAtomRegistry,
75 layer: layerConnection,
76});