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

Function makeTagProxy

packages/effect/src/Effect.ts:13442–13476  ·  view source on GitHub ↗
(TagClass: Context.Tag<any, any> & Record<PropertyKey, any>)

Source from the content-addressed store, hash-verified

13440}
13441
13442const makeTagProxy = (TagClass: Context.Tag<any, any> & Record<PropertyKey, any>) => {
13443 const cache = new Map()
13444 return new Proxy(TagClass, {
13445 get(target: any, prop: any, receiver) {
13446 if (prop in target) {
13447 return Reflect.get(target, prop, receiver)
13448 }
13449 if (cache.has(prop)) {
13450 return cache.get(prop)
13451 }
13452 const fn = (...args: Array<any>) =>
13453 core.andThen(target, (s: any) => {
13454 if (typeof s[prop] === "function") {
13455 cache.set(prop, (...args: Array<any>) => core.andThen(target, (s: any) => s[prop](...args)))
13456 return s[prop](...args)
13457 }
13458 cache.set(prop, core.andThen(target, (s: any) => s[prop]))
13459 return s[prop]
13460 })
13461 const cn = core.andThen(target, (s: any) => s[prop])
13462 // @effect-diagnostics-next-line floatingEffect:off
13463 Object.assign(fn, cn)
13464 const apply = fn.apply
13465 const bind = fn.bind
13466 const call = fn.call
13467 const proto = Object.setPrototypeOf({}, Object.getPrototypeOf(cn))
13468 proto.apply = apply
13469 proto.bind = bind
13470 proto.call = call
13471 Object.setPrototypeOf(fn, proto)
13472 cache.set(prop, fn)
13473 return fn
13474 }
13475 })
13476}
13477
13478/**
13479 * Creates a unique tag for a dependency, embedding the service's methods as

Callers 2

TagFunction · 0.85
Effect.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected