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

Function mount

packages/effect/src/ui/internal/kernel.ts:2245–2302  ·  view source on GitHub ↗
(
  component: Runnable,
  props: unknown,
  container: unknown,
  host: Host,
  options: Options
)

Source from the content-addressed store, hash-verified

2243
2244/** @internal */
2245export const mount = (
2246 component: Runnable,
2247 props: unknown,
2248 container: unknown,
2249 host: Host,
2250 options: Options
2251): Root => {
2252 // The first mount is timed as one flush, from its first `init`.
2253 const from = options.slow?.flush && options.slow.now()
2254 const tree: Tree = {
2255 ...options,
2256 host,
2257 init: options.init ?? initOf,
2258 // Wrapped: called as the tree's method, the browser's `queueMicrotask` throws "Illegal invocation".
2259 schedule: options.schedule ?? ((task) => queueMicrotask(task)),
2260 dirty: [],
2261 scheduled: true,
2262 flushing: true,
2263 closed: false,
2264 entered: 1,
2265 starts: []
2266 }
2267 tree.transitions = host.transitions?.(tree)
2268 const ctx: Context.Context<any> = Context.add(
2269 options.context ?? (Context.empty() as Context.Context<any>),
2270 CurrentTree,
2271 tree
2272 )
2273 const env: Env = { ctx, cause: undefined, waiting: [] }
2274 const instance = new Instance(
2275 tree,
2276 component,
2277 undefined,
2278 undefined,
2279 props,
2280 env
2281 )
2282 instance.named = options.path
2283 if (start(instance, container) === undefined) {
2284 instance.rendered = stand(instance, instance.failure!, container)
2285 }
2286 place(host, container, instance.rendered!, null)
2287 flush(tree, from)
2288 if (options.unwired !== true) leave(tree)
2289 return {
2290 instance,
2291 send: (message, source) => send(instance, message, source),
2292 // Defer Commands from `onPropsChange` until the instance has synced.
2293 setProps: (props) => enter(tree, () => applyProps(instance, props) && markDirty(instance)),
2294 close: () => {
2295 if (tree.closed) return
2296 tree.closed = true
2297 close(instance)
2298 unplace(host, container, instance.rendered!)
2299 host.commit?.()
2300 }
2301 }
2302}

Callers

nothing calls this directly

Calls 13

standFunction · 0.85
applyPropsFunction · 0.85
unplaceFunction · 0.85
startFunction · 0.70
placeFunction · 0.70
flushFunction · 0.70
leaveFunction · 0.70
sendFunction · 0.70
enterFunction · 0.70
markDirtyFunction · 0.70
closeFunction · 0.70
addMethod · 0.65

Tested by

no test coverage detected