LateInitCell and Derivatives
LateInitCell starts with null inside, but insists that it doesn’t contain a null value! It will throw an exception if you try to get the contents and they are null.
The next cells are all built off the LateInitCell back, so they all share the following additional utility methods:
LazyCell
LazyCell will lazily evaluate its contents from a function whenever you attempt to obtain the contents and they are null.
Combine this with invalidate()
in order to re-evaluate the contents using the
function.
Several modules have their own wrapper of this, e.g. Core has the
OpModeLazyCell
and OpModeFreshLazyCell
and Mercurial has the
SubsytemObjectCell
. These wrappers provide additional functionality tied to
their specific domains.
InvalidatingCell
Invalidating Cell is like lazy cell, but has a built in self invalidation function as well.
Whenever the contents of the cell are accessed, the invalidating function is checked, to see if the cell should be re-evaluated.
The cell contents should not be accessed through the self
parameter, as this
will cause stack overflow, this is what the contents
parameter is for.
StaleAccessCell
A time-based wrapper for InvalidatingCell.
This example will invalidate when it has been 5.1 seconds since last access.
StaleEvalCell
A time-based wrapper for InvalidatingCell
This example will invalidate when it has been 5.1 seconds since last eval.