The SubtreeRetainer class keeps track of a number of pieces of data, comparing the values of these pieces at every iteration.

This is useful for preventing redraws to relatively static (or huge) components whose VDOM only depends on very few values, when none of them have changed.

Example

// Check two callbacks for changes on each update
this.subtree = new SubtreeRetainer(
() => this.attrs.post.freshness,
() => this.showing
);

// Add more callbacks to be checked for updates
this.subtree.check(() => this.attrs.user.freshness);

// In a component's onbeforeupdate() method:
return this.subtree.needsRebuild()

See

https://mithril.js.org/lifecycle-methods.html#onbeforeupdate

Hierarchy

  • SubtreeRetainer

Constructors

Properties

Methods

Constructors

Properties

callbacks: (() => any)[]

Type declaration

    • (): any
    • Returns any

data: Record<string, any>

Methods

Generated using TypeDoc v0.24.8