1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

Extend / correct documentation of SubtreeRetainer

This commit is contained in:
Franz Liedke
2020-09-11 15:53:31 +02:00
parent abb896d430
commit 09bead3ba2

View File

@@ -1,17 +1,22 @@
/** /**
* The `SubtreeRetainer` class represents a Mithril virtual DOM subtree. It * The `SubtreeRetainer` class keeps track of a number of pieces of data,
* keeps track of a number of pieces of data, allowing the subtree to be * comparing the values of these pieces at every iteration.
* retained if none of them have changed. *
* 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 * @example
* // constructor * // Check two callbacks for changes on each update
* this.subtree = new SubtreeRetainer( * this.subtree = new SubtreeRetainer(
* () => this.attrs.post.freshness, * () => this.attrs.post.freshness,
* () => this.showing * () => this.showing
* ); * );
*
* // Add more callbacks to be checked for updates
* this.subtree.check(() => this.attrs.user.freshness); * this.subtree.check(() => this.attrs.user.freshness);
* *
* // onbeforeupdate * // In a component's onbeforeupdate() method:
* return this.subtree.needsRebuild() * return this.subtree.needsRebuild()
* *
* @see https://mithril.js.org/lifecycle-methods.html#onbeforeupdate * @see https://mithril.js.org/lifecycle-methods.html#onbeforeupdate