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 = snapshotLoaderLayer.pipe(
41 Layer.provideMerge(Connection.layerWithOptions({ usageLimitSources: true })),
42 Layer.provideMerge(
43 Layer.mergeAll(
44 runtimeContextLayer,
45 providedConnectionPlatformLayer,
46 mobileBackgroundActivityObserverLayer,
47 ),
48 ),
49);
50
51const connectionLayer = mobileBackgroundActivityReporterLayer.pipe(
52 Layer.provideMerge(providedClientConnectionLayer),
53);
54
55export const connectionAtomRuntime: Atom.AtomRuntime<
56 Layer.Success<ConnectionLayerSource>,
57 Layer.Error<ConnectionLayerSource>
58> = hotSwappableAtomRuntime({
59 id: "t3.mobile.connection-runtime",
60 hotModule: typeof module === "undefined" ? undefined : module.hot,
61 registry: appAtomRegistry,
62 layer: connectionLayer,
63});