class Foo extends Context.Tag(`Foo`)<Foo, string>() {}
class Foobar extends Context.Tag(`Bar`)<
Foobar,
// TODO: how can we use Effect.Effect<string> here, to avoid leaking implementation details? Using Foo inside the returned Effect doesn't automatically track it?
Effect.Effect<string, never, Foo>
>() {}
const layerParent = Layer.succeed(Foo, 'foo');
const runtimeParent = ManagedRuntime.make(layerParent);
const layerChild = pipe(
Layer.succeed(
Foobar,
// TODO: if Foo comes from a different module, can we prevent coupling against the module through these tags?
Effect.andThen(Foo, (foo) => foo + 'bar')
)
);
const runtimeChild = ManagedRuntime.make(layerChild);
const program = Effect.gen(function* () {
const effect = yield* Foobar;
return effect;
});
const fromChild = Effect.runSync(Effect.provide(program, runtimeChild));
const fromParent = Effect.provide(fromChild, runtimeParent);
const result = Effect.runSync(fromParent);
console.log(result); // prints foobar
class Foo extends Context.Tag(`Foo`)<Foo, string>() {}
class Foobar extends Context.Tag(`Bar`)<
Foobar,
// TODO: how can we use Effect.Effect<string> here, to avoid leaking implementation details? Using Foo inside the returned Effect doesn't automatically track it?
Effect.Effect<string, never, Foo>
>() {}
const layerParent = Layer.succeed(Foo, 'foo');
const runtimeParent = ManagedRuntime.make(layerParent);
const layerChild = pipe(
Layer.succeed(
Foobar,
// TODO: if Foo comes from a different module, can we prevent coupling against the module through these tags?
Effect.andThen(Foo, (foo) => foo + 'bar')
)
);
const runtimeChild = ManagedRuntime.make(layerChild);
const program = Effect.gen(function* () {
const effect = yield* Foobar;
return effect;
});
const fromChild = Effect.runSync(Effect.provide(program, runtimeChild));
const fromParent = Effect.provide(fromChild, runtimeParent);
const result = Effect.runSync(fromParent);
console.log(result); // prints foobar