Differences Between `Effect.Tag` and `Context.Tag`
is there a deeper difference between
Effect.TagEffect.Tag and Context.TagContext.Tag other than Effect.TagEffect.Tag creates static properties for the fields which you can directly yield*yield*?class NotificationsEffect extends Effect.Tag("NotificationsEffect")<
NotificationsEffect,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
class NotificationsContext extends Context.Tag("NotificationsContext")<
NotificationsContext,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
async function main() {
const runtime = ManagedRuntime.make(
Layer.mergeAll(NotificationsEffect.Live, NotificationsContext.Live)
);
await runtime.runPromise(NotificationsEffect.notify("Hello, world!"));
await runtime.runPromise(
Effect.gen(function* () {
const notificationsContext = yield* NotificationsContext;
yield* notificationsContext.notify("Hello, world!");
})
);
await runtime.dispose();
}
main().then(() => console.log("Program completed successfully."));class NotificationsEffect extends Effect.Tag("NotificationsEffect")<
NotificationsEffect,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
class NotificationsContext extends Context.Tag("NotificationsContext")<
NotificationsContext,
{ readonly notify: (message: string) => Effect.Effect<void> }
>() {
static Live = Layer.succeed(this, {
notify: (message) => Console.log(message),
});
}
async function main() {
const runtime = ManagedRuntime.make(
Layer.mergeAll(NotificationsEffect.Live, NotificationsContext.Live)
);
await runtime.runPromise(NotificationsEffect.notify("Hello, world!"));
await runtime.runPromise(
Effect.gen(function* () {
const notificationsContext = yield* NotificationsContext;
yield* notificationsContext.notify("Hello, world!");
})
);
await runtime.dispose();
}
main().then(() => console.log("Program completed successfully."));