Reference Source
import SubtreeRetainer from 'flarum/utils/SubtreeRetainer.js'
public class | source

SubtreeRetainer

The SubtreeRetainer class represents a Mithril virtual DOM subtree. It keeps track of a number of pieces of data, allowing the subtree to be retained if none of them have changed.

See:

Example:

// constructor
this.subtree = new SubtreeRetainer(
  () => this.props.post.freshness,
  () => this.showing
);
this.subtree.check(() => this.props.user.freshness);

// view
this.subtree.retain() || 'expensive expression'

Constructor Summary

Public Constructor
public

constructor(callbacks: ...callbacks)

Member Summary

Public Members
public
public

data: {}

Method Summary

Public Methods
public

check(callbacks: ...Function)

Add another callback to be checked.

public

Invalidate the subtree, forcing it to be rerendered.

public

retain(): Object | false

Return a virtual DOM directive that will retain a subtree if no data has changed since the last check.

Public Constructors

public constructor(callbacks: ...callbacks) source

Params:

NameTypeAttributeDescription
callbacks ...callbacks

Functions returning data to keep track of.

Public Members

public callbacks: * source

public data: {} source

Public Methods

public check(callbacks: ...Function) source

Add another callback to be checked.

Params:

NameTypeAttributeDescription
callbacks ...Function

public invalidate() source

Invalidate the subtree, forcing it to be rerendered.

public retain(): Object | false source

Return a virtual DOM directive that will retain a subtree if no data has changed since the last check.

Return:

Object | false