liveBook · Manning

Decorator

As explained in Web Component Development with Modern Libraries and Tooling

A JavaScript language feature that applies declarative metadata or behavior to classes and class members.

A decorator is a declarative annotation that modifies the behavior of a class, property, method, or getter. In web components, decorators reduce boilerplate while connecting component code to custom elements, attributes, events, public APIs, and reactive updates. section 6.4 section 7.4

Stencil and FAST use decorators to describe how a component participates in the browser platform. A class decorator registers a custom element, property decorators connect properties with HTML attributes, and method decorators configure events or public methods. Options can control reflection, mutability, shadow DOM, styling, and form participation. section 6.4

Common decorator roles include:

  • Map a property to an HTML attribute, optionally choosing a kebab-case name, a converter, or a synchronization mode. section 6.4

Reactive properties in FAST

A component can declare @observable n, double, and triple properties. Its nChanged method recalculates double and triple whenever n changes, while bindings display all three values and buttons increment or decrement n. Getters can provide the same derived values; a getter with changing dependencies uses @volatile. section 7.4

How Web Component Development with Modern Libraries and Tooling covers it

How deep it goes
Explains decorator targets, configuration options, attribute synchronization, and reactive updates, but not decorator implementation internals.
Examples
Demonstrates component registration, property mapping, attribute conversion, and a reactive my-math component with observable values.
What it assumes
Assumes familiarity with JavaScript classes, properties, methods, and web components while introducing framework-specific decorator roles.
What you can do after
Apply decorators via Stencil or FAST to declare custom elements, synchronize attributes, expose APIs, and update bindings reactively.
How it connects
Connects decorators with web components, custom elements, HTML attributes, shadow DOM, events, lifecycle methods, and reactive bindings.

Also explained in

Compare how 9 books explain decorator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Component Development with Modern Libraries and Tooling. The section links point to the parts of the book it draws on.