Skip to content

Commit

Permalink
move ManagedRuntime.TypeId to fix circular imports (#3682)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim <[email protected]>
  • Loading branch information
leonitousconforti and tim-smart committed Sep 26, 2024
1 parent cde84e8 commit 687e926
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-glasses-deliver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

move ManagedRuntime.TypeId to fix circular imports
3 changes: 2 additions & 1 deletion packages/effect/src/ManagedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type * as Effect from "./Effect.js"
import type * as Exit from "./Exit.js"
import type * as Fiber from "./Fiber.js"
import * as internal from "./internal/managedRuntime.js"
import * as circular from "./internal/managedRuntime/circular.js"
import type * as Layer from "./Layer.js"
import type * as Runtime from "./Runtime.js"
import type * as Unify from "./Unify.js"
Expand All @@ -13,7 +14,7 @@ import type * as Unify from "./Unify.js"
* @since 3.9.0
* @category symbol
*/
export const TypeId: unique symbol = internal.TypeId as TypeId
export const TypeId: unique symbol = circular.TypeId as TypeId

/**
* @since 3.9.0
Expand Down
5 changes: 2 additions & 3 deletions packages/effect/src/internal/layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import * as effect from "./core-effect.js"
import * as core from "./core.js"
import * as circular from "./effect/circular.js"
import * as fiberRuntime from "./fiberRuntime.js"
import * as circularManagedRuntime from "./managedRuntime/circular.js"
import * as EffectOpCodes from "./opCodes/effect.js"
import * as OpCodes from "./opCodes/layer.js"
import * as ref from "./ref.js"
Expand Down Expand Up @@ -1289,8 +1290,6 @@ const provideSomeRuntime = dual<
)
})

const ManagedRuntimeTypeId: ManagedRuntime.TypeId = Symbol.for("effect/ManagedRuntime") as ManagedRuntime.TypeId

/** @internal */
export const effect_provide = dual<
{
Expand Down Expand Up @@ -1339,7 +1338,7 @@ export const effect_provide = dual<
return provideSomeLayer(self, source as Layer.Layer<ROut, any, any>)
} else if (Context.isContext(source)) {
return core.provideSomeContext(self, source)
} else if (ManagedRuntimeTypeId in source) {
} else if (circularManagedRuntime.TypeId in source) {
return core.flatMap(
(source as ManagedRuntime.ManagedRuntime<ROut, any>).runtimeEffect,
(rt) => provideSomeRuntime(self, rt)
Expand Down
8 changes: 3 additions & 5 deletions packages/effect/src/internal/managedRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as effect from "./core-effect.js"
import * as core from "./core.js"
import * as fiberRuntime from "./fiberRuntime.js"
import * as internalLayer from "./layer.js"
import * as circular from "./managedRuntime/circular.js"
import * as internalRuntime from "./runtime.js"

interface ManagedRuntimeImpl<R, E> extends M.ManagedRuntime<R, E> {
Expand All @@ -20,10 +21,7 @@ interface ManagedRuntimeImpl<R, E> extends M.ManagedRuntime<R, E> {
}

/** @internal */
export const TypeId: M.TypeId = Symbol.for("effect/ManagedRuntime") as M.TypeId

/** @internal */
export const isManagedRuntime = (u: unknown): u is M.ManagedRuntime<unknown, unknown> => hasProperty(u, TypeId)
export const isManagedRuntime = (u: unknown): u is M.ManagedRuntime<unknown, unknown> => hasProperty(u, circular.TypeId)

function provide<R, ER, A, E>(
managed: ManagedRuntimeImpl<R, ER>,
Expand All @@ -42,7 +40,7 @@ function provide<R, ER, A, E>(

const ManagedRuntimeProto = {
...Effectable.CommitPrototype,
[TypeId]: TypeId,
[circular.TypeId]: circular.TypeId,
pipe() {
return pipeArguments(this, arguments)
},
Expand Down
6 changes: 6 additions & 0 deletions packages/effect/src/internal/managedRuntime/circular.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type * as M from "../../ManagedRuntime.js"

// circular with Layer

/** @internal */
export const TypeId: M.TypeId = Symbol.for("effect/ManagedRuntime") as M.TypeId

0 comments on commit 687e926

Please sign in to comment.