Skip to content

State

An interface shows values that change: a total, a list, a setting, a status that arrives from a server. In JOID, init() builds the tree once per opening, and the values that change live in signals. This chapter builds on signals: it computes values from them, rebuilds the nodes that come and go, keeps values that several UIs or several launches share, and changes them over time.

A derived value is computed once from other signals, and behaves like a signal of its own.

final ComputedSignal<Integer> total = Signal.from(() -> price.get() * quantity.get());

Full file: DerivedUI.java

Read Derived values to learn map, Signal.from, batch, and how to run your own code when a value changes.

When a change adds or removes nodes, a node builds its children again; when the data is not there yet, a node waits behind a placeholder.

.watch(this.items, WatchProperty.CLEAR_CHILDREN, WatchProperty.BODY)

Read Rebuilding the tree to learn watch, wait and skeletons.

A store shares values between UIs and can keep them on disk; a remembered property keeps one field of a UI across launches.

final SettingsStore settings = super.useStore(SettingsStore.class, SettingsStore::new);

Full file: SettingsUI.java

Read Stores and remembered properties to learn where a value should live and how to write a store.

A task runs your code after a delay or on a period, and a signal set from another thread takes its value at the next frame.

final IntegerSignal seconds = new IntegerSignal(0);
Task.create(1000L).every(1000L).onRun(event -> seconds.increment()).attach(this);

Full file: TimerUI.java

Read Tasks and background updates to learn Task and how a worker thread hands its results to the interface.

Report a problem with this page