import { Context, Effect, Layer } from "effect";
interface Service1 {
type: string;
}
export const Service1: Context.Tag<Service1, Service1> =
Context.GenericTag<Service1>("@test/Service1");
const BaseLayer = Layer.effect(
Service1,
Effect.succeed({ type: "Base" }).pipe(
Effect.tap(() => console.log("BaseLayer built"))
)
);
const UpdatedLayer = BaseLayer.pipe(
Layer.updateService(Service1, (s) => {
console.log(s);
return {
type: "Updated",
};
})
).pipe(Layer.provide(BaseLayer));
const program = Effect.gen(function* () {
const s1 = yield* Service1;
console.log(s1); // logs { type: 'Base' } but why??
}).pipe(Effect.provide(UpdatedLayer));
Effect.runSync(program);
import { Context, Effect, Layer } from "effect";
interface Service1 {
type: string;
}
export const Service1: Context.Tag<Service1, Service1> =
Context.GenericTag<Service1>("@test/Service1");
const BaseLayer = Layer.effect(
Service1,
Effect.succeed({ type: "Base" }).pipe(
Effect.tap(() => console.log("BaseLayer built"))
)
);
const UpdatedLayer = BaseLayer.pipe(
Layer.updateService(Service1, (s) => {
console.log(s);
return {
type: "Updated",
};
})
).pipe(Layer.provide(BaseLayer));
const program = Effect.gen(function* () {
const s1 = yield* Service1;
console.log(s1); // logs { type: 'Base' } but why??
}).pipe(Effect.provide(UpdatedLayer));
Effect.runSync(program);