public class Reactive extends Object
Computation, providing a lazy flush cycle and registering
reactive event collectors.
With a reactive programming model, the dependencies needed for producing a
result are automatically registered when the result is computed. When any
dependency of a computation is changed, that computation is scheduled to be
recomputed. To reduce the number of recomputations performed when many
dependencies are updated, the recomputation is performed lazily the next time
flush() is invoked.
Computation| Modifier and Type | Method and Description |
|---|---|
static elemental.events.EventRemover |
addEventCollector(ReactiveValueChangeListener reactiveValueChangeListener)
Adds a reactive change listener that will be invoked whenever a reactive
change event is fired from any reactive event router.
|
static void |
addFlushListener(FlushListener flushListener)
Adds a listener that will be invoked the next time
flush() is
invoked. |
static void |
addPostFlushListener(FlushListener postFlushListener)
Adds a listener that will be invoked during the next
flush(),
after all regular flush listeners have been invoked. |
static void |
flush()
Flushes all flush listeners and post flush listeners.
|
static Computation |
getCurrentComputation()
Gets the currently active computation.
|
static void |
notifyEventCollectors(ReactiveValueChangeEvent event)
Fires a reactive change event to all registered event collectors.
|
static void |
reset()
Resets Reactive to the initial state.
|
static Computation |
runWhenDependenciesChange(Command command)
Evaluates the given command whenever there is a change in any
ReactiveValue used in the command. |
static void |
runWithComputation(Computation computation,
Command command)
Runs a task with the given computation set as
getCurrentComputation(). |
public static void addFlushListener(FlushListener flushListener)
flush() is
invoked. A listener added during a flush will be invoked before that
flush finishes.flushListener - the flush listener to addpublic static void addPostFlushListener(FlushListener postFlushListener)
flush(),
after all regular flush listeners have been invoked. If a post flush
listener adds new flush listeners, those flush listeners will be invoked
before the next post flush listener is invoked.postFlushListener - the listener to addpublic static void flush()
public static Computation getCurrentComputation()
null if there is no
current computation.public static void runWithComputation(Computation computation, Command command)
getCurrentComputation(). If another computation is set as the
current computation, it is temporarily replaced by the provided
computation, but restored again after the provided task has been run.computation - the computation to set as currentcommand - the command to run while the computation is set as currentpublic static elemental.events.EventRemover addEventCollector(ReactiveValueChangeListener reactiveValueChangeListener)
reactiveValueChangeListener - the listener to addpublic static void notifyEventCollectors(ReactiveValueChangeEvent event)
event - the fired eventaddEventCollector(ReactiveValueChangeListener)public static Computation runWhenDependenciesChange(Command command)
ReactiveValue used in the command.command - the command to runComputation object which can be used to control the
evaluationpublic static void reset()
Intended for test cases to call in setup to avoid having tests affect each other as Reactive state is static and shared.
Should never be called from non-test code!
Copyright © 2000–2018 Vaadin Ltd. All rights reserved.