56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { Connection } from "@t3tools/client-runtime/connection";
|
|
import { shellSnapshotLoaderLayer } from "@t3tools/client-runtime/state/shell";
|
|
import { threadSnapshotLoaderLayer } from "@t3tools/client-runtime/state/threads";
|
|
import * as Layer from "effect/Layer";
|
|
import { Atom } from "effect/unstable/reactivity";
|
|
|
|
import type { FoundationHotModule } from "../lib/foundation-fast-refresh";
|
|
import { hotSwappableAtomRuntime } from "../lib/hot-swappable-atom-runtime";
|
|
import { runtimeContextLayer } from "../lib/runtime";
|
|
import { appAtomRegistry } from "../state/atom-registry";
|
|
import {
|
|
mobileBackgroundActivityObserverLayer,
|
|
mobileBackgroundActivityReporterLayer,
|
|
} from "./background-activity";
|
|
import { connectionPlatformLayer } from "./platform";
|
|
|
|
declare const module: { readonly hot?: FoundationHotModule } | undefined;
|
|
|
|
const providedConnectionPlatformLayer = connectionPlatformLayer.pipe(
|
|
Layer.provide(runtimeContextLayer),
|
|
);
|
|
|
|
const snapshotLoaderLayer = Layer.merge(threadSnapshotLoaderLayer, shellSnapshotLoaderLayer);
|
|
|
|
type ConnectionLayerSource =
|
|
| typeof Connection.layer
|
|
| typeof snapshotLoaderLayer
|
|
| typeof runtimeContextLayer
|
|
| typeof connectionPlatformLayer
|
|
| typeof mobileBackgroundActivityObserverLayer
|
|
| typeof mobileBackgroundActivityReporterLayer;
|
|
|
|
const providedClientConnectionLayer = Layer.merge(Connection.layer, snapshotLoaderLayer).pipe(
|
|
Layer.provideMerge(
|
|
Layer.mergeAll(
|
|
runtimeContextLayer,
|
|
providedConnectionPlatformLayer,
|
|
mobileBackgroundActivityObserverLayer,
|
|
),
|
|
),
|
|
);
|
|
|
|
const connectionLayer = mobileBackgroundActivityReporterLayer.pipe(
|
|
Layer.provideMerge(providedClientConnectionLayer),
|
|
);
|
|
|
|
export const connectionAtomRuntime: Atom.AtomRuntime<
|
|
Layer.Success<ConnectionLayerSource>,
|
|
Layer.Error<ConnectionLayerSource>
|
|
> = hotSwappableAtomRuntime({
|
|
id: "t3.mobile.connection-runtime",
|
|
hotModule: typeof module === "undefined" ? undefined : module.hot,
|
|
registry: appAtomRegistry,
|
|
layer: connectionLayer,
|
|
});
|