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