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

Class HelperImpl

packages/effect/src/ui/View.ts:2259–2331  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2257const notRunning: Running = () => false
2258
2259class HelperImpl<Msg, Props> implements Helper<Msg, Props> {
2260 readonly props: Props
2261 readonly elements: Vocabulary<any> | undefined
2262 readonly runningFn: Running
2263 /** The instance's path, or the instance, whose path is read only when `id` is called. */
2264 readonly at: string | PathSource
2265 readonly store: LazyStore | undefined
2266 constructor(
2267 props: Props,
2268 elements: Vocabulary<any> | undefined,
2269 running: Running | undefined,
2270 at: string | PathSource,
2271 store: LazyStore | undefined
2272 ) {
2273 this.props = props
2274 this.elements = elements
2275 this.runningFn = running ?? notRunning
2276 this.at = at
2277 this.store = store
2278 }
2279 lazy(
2280 this: any,
2281 fn: (h: any, ...args: Array<any>) => Content<Msg, any>,
2282 ...args: Array<any>
2283 ): any {
2284 const store = this.store
2285 if (store === undefined) return toNode(fn(this, ...args))
2286 const lazies = (store.lazy ??= new Lazies()) as Lazies
2287 const key = args.length === 0 ? fn : args[0]
2288 const entry = lazies.entries.get(key)
2289 const round = lazies.round
2290 if (entry !== undefined && entry.fn === fn && sameArgs(entry.args, args)) {
2291 if (entry.round !== round) {
2292 entry.round = round
2293 lazies.used++
2294 }
2295 return entry.node
2296 }
2297 if (dev) lazies.missed?.(entry, fn, args)
2298 const node = toNode(fn(this, ...args))
2299 // A key an earlier call of this render took stays theirs.
2300 if (entry !== undefined && entry.round === round) return node
2301 if (entry === undefined) lazies.entries.set(key, { fn, args, node, round })
2302 else {
2303 entry.fn = fn
2304 entry.args = args
2305 entry.node = node
2306 entry.round = round
2307 }
2308 lazies.used++
2309 return node
2310 }
2311 isRunning(command: Command.Definition.Any, group?: unknown): boolean {
2312 return this.runningFn(
2313 commandKey.nameOf(command),
2314 commandKey.groupKeyOf(command, group)
2315 )
2316 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected