MCPcopy Create free account
hub / github.com/Effect-TS/effect / addUnsafe

Function addUnsafe

packages/effect/src/Context.ts:787–808  ·  view source on GitHub ↗
(
  self: Context<Services>,
  key: string,
  service: Types.NoInfer<S>
)

Source from the content-addressed store, hash-verified

785 * @since 4.0.0
786 */
787export const addUnsafe = <Services, I, S>(
788 self: Context<Services>,
789 key: string,
790 service: Types.NoInfer<S>
791): Context<Services | I> => {
792 const impl = self as ContextImpl<Services>
793 const cacheRoot = cacheKeys.has(key) ? undefined : impl.cacheRoot
794 if (impl.depth >= MaxDepth) {
795 // Rebase the overlay chain into a flat map, keeping the cacheRoot so a
796 // rebase on an ordinary key does not invalidate fiber caches
797 const map = new Map(impl.mapUnsafe)
798 map.set(key, service)
799 return makeImpl(cacheRoot, map, undefined, 0)
800 }
801
802 return makeImpl(
803 cacheRoot,
804 impl.base,
805 { key, value: service, parent: impl.overlay },
806 impl.depth + 1
807 )
808}
809
810/**
811 * Adds or removes a service depending on an `Option`.

Callers 4

FiberSet.tsFile · 0.85
runImplFunction · 0.85
runtimeFunction · 0.85
Context.tsFile · 0.85

Calls 3

makeImplFunction · 0.70
setMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected