Skip to Content
Bear documentation

factory

Import from bear/engine/factory.

Type Aliases

Factory

type Factory<S, P> = (situational) => BearElement<P>;

Defined in: bear/engine/factory.ts:8

A factory produces a BearElement from situational props. S = what the consuming assembly supplies at render time; P = the part's props. A factory for a part the assembly doesn't know states neither.

Type Parameters

Type ParameterDefault type
S extends objectReadonly<Record<string, unknown>>
P extends objectobject

Parameters

ParameterType
situationalS & ElementProps

Returns

BearElement<P>

Functions

factory()

function factory<P>(def, defaults): Factory<Partial<P>, P>;

Defined in: bear/engine/factory.ts:25

Create a factory from a PartDef with default props.

Returns a function that merges situational props (from the assembly) over the defaults, then calls the PartDef to produce a BearElement.

const osb716 = factory(OSB, { category: "7/16in" });
// Later, an assembly calls:
osb716({ face: someSurface, panelRegion: region })

Type Parameters

Type Parameter
P extends object

Parameters

ParameterType
defPartDef<P>
defaultsPartial<P>

Returns

Factory<Partial<P>, P>

On this page