Skip to main content

@definition

The @definition decorator is used to mark a property so it becomes part of the form definition. This means the property is automatically stored to and retrieved from the form definition.

Decorator type

Property ℹ️

Applies to

Decorator signature

@definition(
type: "string" | "number" | "boolean" | string,
optional?: "optional" | "required",
mode?: "rw" | "r" | "w"
)
tip

If you don't need fine-grained type control, you can simply use the shorthand notation:

@definition

Decorator parameters

NameTypeOptionalDescription
type"string" | "number" | "boolean" | stringNoSpecifies the type of the property. This type information is used by the builder to maintain the data of similar properties when switching between blocks. You can specify one of the primitives string, number, or boolean. Or specify a custom data type indicator to specify similar data types in blocks.
optional"optional" | "required"YesSpecifies if the property is optional or not (default is required).
mode"rw" | "r" | "w"YesSpecifies the operation mode for the property in the form definition. It can be one of the following values:
- rw: Reads and writes the property from/to the definition (this is the default mode);
- r: Only reads the property from the definition;
- w: Only writes the property to the definition.

Example

import { tripetto, definition, NodeBlock } from "tripetto";

@tripetto({
type: "node",
identifier: "example-block",
label: "Example",
icon: "data:image/svg+xml;base64,PHN2ZyAvPg=="
})
class ExampleBlock extends NodeBlock {
// These properties will now be part of the form definition
@definition
exampleProperty?: boolean;

// By specifying the type of the property, the data of the property is transferred
// when switching to another block that also has this exact property and type.
@definition("string", "optional")
anotherProperty?: string;
}