Properties

Types

The type of a Wafer property indicates how it is set to, and parsed from, an attribute with the same name.

class MyExample extends Wafer {
static get props() {
return {
count: {
type: Number,
},
};
}
}

An attribute is set from a property when the value changes and the property is reflected.

A property is always set from an attribute when an attribute changes.

Possible values are:

String

The property takes the attribute's raw string value. When reflected the attribute is set to the property's string value.

Number

The property is set to the attribute value cast as a number - Number(attrValue). When reflected the attribute is set to the property's string value.

Boolean

The property is set to true if an attribute is present, false otherwise. When reflected the attribute is set to an empty string if the property is true, and removed otherwise.

Any other type, including Array and Object

The property is set to the attribute's value parsed as JSON - JSON.parse(attrValue). When reflected the attribute is set to the stringified JSON value - JSON.stringify(propValue).

Types are optional - properties without a type will be treated in the same way as any other type above.

Next: Initial value Previous: Introduction