Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

runtime.ts

45 lines1.5 KB

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 { runtimeContextLayer } from "../lib/runtime";
8import {
9 mobileBackgroundActivityObserverLayer,
10 mobileBackgroundActivityReporterLayer,
11} from "./background-activity";
12import { connectionPlatformLayer } from "./platform";
13​
14const providedConnectionPlatformLayer = connectionPlatformLayer.pipe(
15 Layer.provide(runtimeContextLayer),
16);
17​
18const snapshotLoaderLayer = Layer.merge(threadSnapshotLoaderLayer, shellSnapshotLoaderLayer);
19​
20type ConnectionLayerSource =
21 | typeof Connection.layer
22 | typeof snapshotLoaderLayer
23 | typeof runtimeContextLayer
24 | typeof connectionPlatformLayer
25 | typeof mobileBackgroundActivityObserverLayer
26 | typeof mobileBackgroundActivityReporterLayer;
27​
28const providedClientConnectionLayer = Layer.merge(Connection.layer, snapshotLoaderLayer).pipe(
29 Layer.provideMerge(
30 Layer.mergeAll(
31 runtimeContextLayer,
32 providedConnectionPlatformLayer,
33 mobileBackgroundActivityObserverLayer,
34 ),
35 ),
36);
37​
38const connectionLayer = mobileBackgroundActivityReporterLayer.pipe(
39 Layer.provideMerge(providedClientConnectionLayer),
40);
41​
42export const connectionAtomRuntime: Atom.AtomRuntime<
43 Layer.Success<ConnectionLayerSource>,
44 Layer.Error<ConnectionLayerSource>
45> = Atom.runtime(connectionLayer);