Open History to see the last commit
1import { Connection } from "@t3tools/client-runtime/connection";
2import { shellSnapshotLoaderLayer } from "@t3tools/client-runtime/state/shell";
3import {
4 boundedThreadSnapshotLoaderLayer,
5 threadHistoryControllerLayer,
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 shellSnapshotLoaderLayer,
29 threadHistoryControllerLayer,
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 = Layer.merge(Connection.layer, snapshotLoaderLayer).pipe(
41 Layer.provideMerge(
42 Layer.mergeAll(
43 runtimeContextLayer,
44 providedConnectionPlatformLayer,
45 mobileBackgroundActivityObserverLayer,
46 ),
47 ),
48);
49
50const connectionLayer = mobileBackgroundActivityReporterLayer.pipe(
51 Layer.provideMerge(providedClientConnectionLayer),
52);
53
54export const connectionAtomRuntime: Atom.AtomRuntime<
55 Layer.Success<ConnectionLayerSource>,
56 Layer.Error<ConnectionLayerSource>
57> = hotSwappableAtomRuntime({
58 id: "t3.mobile.connection-runtime",
59 hotModule: typeof module === "undefined" ? undefined : module.hot,
60 registry: appAtomRegistry,
61 layer: connectionLayer,
62});