Effect CommunityEC
Effect Community6mo ago
4 replies
Alex Dixon

Two tags, one service

Hello!

I’m switching from context generic tag for everything to effect.service for everything and trying to avoid rewriting existing code.

I have a generic tag version and an effect service version of the same interface. In the same app, I want to register both tags (they’re different), but have their implementation be the service provided by the effect.service. I’m aiming for 1 instance of the service/interface, just under two names.

At layer provide time I was thinking I could just get the service provided by the effect.service and map that to the other tag. But I’m not sure how.

Pseudocode:

const OldOne = Context.Tag<MyInterface>(“OldOne)

class NewOne extends Effect.Service(“NewOne, {
effect: Effect.gen(function*() {
return ” as MyInterface
}})

// ??
Layer.flatMap(NewOne.Default, l => Layer.effect(OldOne, Layer.unwrapEffect(l)).pipe(Layer.provideMerge(NewOne.Default))
Was this page helpful?