Wocart

@wocart/theme v4.1.0


@wocart/theme / index / createInstance

Function: createInstance()

createInstance(definition, id, props?): ComponentInstance

Create a new instance with insertion-time defaults: materialises field.default values only — content-keyed fields stay unset until a merchant overrides them. Throws on programmer errors (empty id, unknown keys, wrong-typed values, a required field with nothing to fill it); the storefront never calls this. A required field with a contentKey is filled from the content pack at render, so it may be left unset here.

Authored defaults are validated exactly like provided values: a default that fails its field's rules (out-of-range number, off-list select option) is an authoring bug, and validateThemeDefinition reports it at assembly time — baking it into an instance silently here would let the writer and the reader disagree.

Parameters

definition

ComponentDefinition

id

string

props?

JsonObject

Returns

ComponentInstance