Effect CommunityEC
Effect Community3y ago
6 replies
kayng84

Code for Layer and Services.

I have the following code to play with Layer & services: https://gist.github.com/khoinguyen/ff6b51ba39b296a020063d393a966e7a (sorry, the code is long and cannot post directly here)

As the output show, the function are construct the conntrackEffect every time the function called. I understand it is because I provide the layer in each function.

The problem is I working in a legacy app which not Effect-TS as a whole, I want to migrate part of it to Effect-TS by refactor the Promise function called before to Effect. So I cannot push the provide layer to main program.

I see in the document it have Effect.provideContext, but got this when try to construct the Context, I got this error:
const ConnTrackerContext = Context.make(ConnTrackService, ConnTrackLive)
// ----------------------------------------------------------^
// Argument of type 'Layer<never, never, ConnTrackService>' is not assignable to parameter of type 'ConnTrackService'.
//  Type 'Layer<never, never, ConnTrackService>' is missing the following properties from type 'ConnTrackService': track, deletets(2345)

Not sure what API to use here.

Please advise, any changes to make better code are very appreciated.
Gist
A simple Connection tracking with Effect-Ts. GitHub Gist: instantly share code, notes, and snippets.
A simple Connection tracking with Effect-Ts
Was this page helpful?