Base class for all Pulsar components.
A Component is a long-lived object with identity — it is never recreated on re-render. Instead, it morphs its output in-place when state changes via morph.
Lifecycle
- Instantiate the component and store it as a field (never inline).
- The runtime calls attach once when the component is mounted.
- State changes are driven by morph, which runs an updater function and triggers a granular DOM reconciliation scoped to this component.
- detach is called when the component is removed from the tree.
Rules
- render must be pure: no side effects, no lazy iteration inside it. Compute derived data in getters and reference those getters from render.
- Components must be stored as fields, not created inline, so that identity and state are preserved across re-renders.
Example
final class Counter extends Component {
int count = 0;
void increment(Event _) => morph(() => count++);
void decrement(Event _) => morph(() => count--);
@override
Morphic render() {
return Div()([
H2()([count]),
Button().onClick(decrement)(['-']),
Button().onClick(increment)(['+']),
]);
}
}
- Implementers
Constructors
Properties
- attached ↔ bool
-
getter/setter pair
- componentRuntime → ComponentRuntime?
-
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtime → ComponentRuntime
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
styles
→ List<
Stylesheet> -
no setter
Methods
-
attach(
ComponentRuntime runtime) → void -
detach(
) → void -
morph(
void updater()) → void -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onMorph(
) → void -
render(
) → Morphic - Produces the Morphic tree for this component's current state.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
) → void
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited