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

runtime.ts

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