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