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

runtime.ts

60 lines2.0 KB

1import { Connection } from "@t3tools/client-runtime/connection";
2import { ShellSnapshotLoader } from "@t3tools/client-runtime/state/shell";
3import {
4 BoundedThreadSnapshotLoader,
5 ThreadHistoryController,
6} from "@t3tools/client-runtime/state/threads";
7import * as Layer from "effect/Layer";
8import { Atom } from "effect/reactivity";
9​
10import type { FoundationHotModule } from "../lib/foundation-fast-refresh";
11import { hotSwappableAtomRuntime } from "../lib/hot-swappable-atom-runtime";
12import * as Runtime from "../lib/runtime";
13import { appAtomRegistry } from "../state/atom-registry";
14import * as BackgroundActivity from "./background-activity";
15import * as ConnectionPlatform from "./platform";
16​
17declare const module: { readonly hot?: FoundationHotModule } | undefined;
18​
19const layerProvidedConnectionPlatform = ConnectionPlatform.layer.pipe(Layer.provide(Runtime.layer));
20​
21const layerSnapshotLoader = Layer.mergeAll(
22 BoundedThreadSnapshotLoader.layer,
23 ShellSnapshotLoader.layer,
24 ThreadHistoryController.layer,
25);
26​
27type ConnectionLayerSource =
28 | typeof Connection.layer
29 | typeof layerSnapshotLoader
30 | typeof Runtime.layer
31 | typeof ConnectionPlatform.layer
32 | typeof BackgroundActivity.layerObserver
33 | typeof BackgroundActivity.layerReporter;
34​
35const layerProvidedClientConnection = layerSnapshotLoader.pipe(
36 Layer.provideMerge(
37 Connection.layerWithOptions({ usageLimitSources: true, usageLimitsCommand: true }),
38 ),
39 Layer.provideMerge(
40 Layer.mergeAll(
41 Runtime.layer,
42 layerProvidedConnectionPlatform,
43 BackgroundActivity.layerObserver,
44 ),
45 ),
46);
47​
48const layerConnection = BackgroundActivity.layerReporter.pipe(
49 Layer.provideMerge(layerProvidedClientConnection),
50);
51​
52export const connectionAtomRuntime: Atom.AtomRuntime<
53 Layer.Success<ConnectionLayerSource>,
54 Layer.Error<ConnectionLayerSource>
55> = hotSwappableAtomRuntime({
56 id: "t3.mobile.connection-runtime",
57 hotModule: typeof module === "undefined" ? undefined : module.hot,
58 registry: appAtomRegistry,
59 layer: layerConnection,
60});