-
-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(breaking): Add ClassTag, improve Effect.serviceConstants, requir…
…e string identifier for all tags (#2028) Co-authored-by: Tim <hello@timsmart.co>
- Loading branch information
1 parent
ab22977
commit 2da707f
Showing
92 changed files
with
457 additions
and
357 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
"@effect/platform-node-shared": minor | ||
"@effect/platform-browser": minor | ||
"@effect/opentelemetry": minor | ||
"@effect/platform-node": minor | ||
"@effect/experimental": minor | ||
"@effect/platform-bun": minor | ||
"@effect/rpc-workers": minor | ||
"@effect/platform": minor | ||
"@effect/rpc-http": minor | ||
"effect": minor | ||
"@effect/schema": minor | ||
"@effect/cli": minor | ||
"@effect/rpc": minor | ||
--- | ||
|
||
With this change we now require a string key to be provided for all tags and renames the dear old `Tag` to `GenericTag`, so when previously you could do: | ||
|
||
```ts | ||
import { Effect, Context } from "effect"; | ||
interface Service { | ||
readonly _: unique symbol; | ||
} | ||
const Service = Context.Tag< | ||
Service, | ||
{ | ||
number: Effect.Effect<never, never, number>; | ||
} | ||
>(); | ||
``` | ||
|
||
you are now mandated to do: | ||
|
||
```ts | ||
import { Effect, Context } from "effect"; | ||
interface Service { | ||
readonly _: unique symbol; | ||
} | ||
const Service = Context.GenericTag< | ||
Service, | ||
{ | ||
number: Effect.Effect<never, never, number>; | ||
} | ||
>("Service"); | ||
``` | ||
|
||
This makes by default all tags globals and ensures better debuggaility when unexpected errors arise. | ||
|
||
Furthermore we introduce a new way of constructing tags that should be considered the new default: | ||
|
||
```ts | ||
import { Effect, Context } from "effect"; | ||
class Service extends Context.Tag("Service")< | ||
Service, | ||
{ | ||
number: Effect.Effect<never, never, number>; | ||
} | ||
>() {} | ||
|
||
const program = Effect.flatMap(Service, ({ number }) => number).pipe( | ||
Effect.flatMap((_) => Effect.log(`number: ${_}`)) | ||
); | ||
``` | ||
|
||
this will use "Service" as the key and will create automatically an opaque identifier (the class) to be used at the type level, it does something similar to the above in a single shot. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--- | ||
"@effect/platform-node-shared": minor | ||
"@effect/platform-browser": minor | ||
"@effect/opentelemetry": minor | ||
"@effect/platform-node": minor | ||
"@effect/experimental": minor | ||
"@effect/platform-bun": minor | ||
"@effect/rpc-workers": minor | ||
"@effect/platform": minor | ||
"@effect/rpc-http": minor | ||
"effect": minor | ||
"@effect/schema": minor | ||
"@effect/cli": minor | ||
"@effect/rpc": minor | ||
--- | ||
|
||
This change enables `Effect.serviceConstants` and `Effect.serviceMembers` to access any constant in the service, not only the effects, namely it is now possible to do: | ||
|
||
```ts | ||
import { Effect, Context } from "effect"; | ||
|
||
class NumberRepo extends Context.TagClass("NumberRepo")< | ||
NumberRepo, | ||
{ | ||
readonly numbers: Array<number>; | ||
} | ||
>() { | ||
static numbers = Effect.serviceConstants(NumberRepo).numbers; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.