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