liveBook · Manning

Factory

As explained in Build a Frontend Web Framework (From Scratch)

A function that creates and returns objects or other constructed values according to a defined creation procedure.

A factory function creates component instances with custom state, rendering, and behavior, avoiding a single application-wide state object and reducer collection. section 9.0

A component factory organizes creation around a few responsibilities:

  • Create each component's state when the component is instantiated. section 9.4
  • Provide a render function and methods, including updateState(), for changing state. section 9.4
  • Patch the component's DOM subtree when its state changes instead of rerendering the entire application. section 9.0 section 9.4
  • Bind render functions and event handlers explicitly so this refers to the component instance. section 9.4

A stateful component instance

Instead of passing global state, reducers, and a root component into createApp(), the newer architecture can receive only a root component. That component is created through a factory, owns its state, renders its view, and patches its DOM subtree after updateState() runs. section 9.0 section 9.4

Figure 9.2 The new version of the framework’s application instance requires only the root component.
figure

Shows the architectural shift from an application requiring global state and reducers to one requiring only a root component. section 9.0

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Explains instantiation, state updates, view patching, and method binding, but does not provide production-level implementation details.
Examples
Uses a root component, component instances, local state, updateState(), render functions, and component DOM subtrees.
What it assumes
Assumes familiarity with stateless components, application state, reducers, the DOM, and reconciliation.
What you can do after
Build it from scratch by defining component state, rendering, updateState(), lifecycle behavior, and bound event handlers.
How it connects
Connects factories with stateful components, pure functions, reducers, lifecycle, render functions, event handlers, and DOM reconciliation.

Also explained in

Compare how 11 books explain factory →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.