NodeBindings
final class NodeBindings
Package: dev.joid.lib.ui.binding · Module: core · Source: NodeBindings.java
Signal bindings, followed suppliers, watches and queued events of one node or one UI.
Description
Section titled “Description”Each Node and each UI owns one.
It subscribes to its signals when the node is attached and unsubscribes when it is detached, reads its followed suppliers before each frame, and delivers the events of its InteractiveValues in the order of the changes, once the signals have settled.
A custom node reaches it through getBindings() to create its own interactive values.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| NodeBindings(Object owner, EventBus eventBus, Supplier | Creates the bindings of owner, which fires its events on eventBus, is named by name in the warnings and runs each event listener through runner. |
Methods
Section titled “Methods”Lifecycle
Section titled “Lifecycle”| Returns | Signature | Summary |
|---|---|---|
void | open() | Opens a batch: signal notifications and queued events wait until the matching close(). |
void | close() | Closes a batch; at the outermost level, it delivers the queued events in their order. |
| Returns | Signature | Summary |
|---|---|---|
void | release(String property) | Drops the binding or the followed supplier of property. |
void | releaseFollows() | Drops every followed supplier and keeps the bindings to signals, as on the copy of a node. |
Reactivity
Section titled “Reactivity”| Returns | Signature | Summary |
|---|---|---|
void | subscribe(boolean loaded) | Listens to the bound and watched signals, at the attachment of the node. |
void | unsubscribe() | Stops listening to the signals, at the detachment of the node. |
T | follow(String property, Supplier | Applies the value of supplier to property now and again before each frame when it changes, then returns the owner. |
this | bind(String property, Signal | Binds property to signal in both directions, then returns the owner: applier receives each value of the signal except null, and writer turns the value of the node into the value to write back. |
T | bindNullable(String property, Signal | Binds property like bind(...), and passes null values to applier too. |
void | sync(String property, Object value) | Writes value back to the signal bound to property. |
void | batch(Runnable runnable) | Runs runnable inside a batch. |
T | watch(Signal<?> signal, BooleanSupplier condition, Runnable action) | Runs action after each change of signal while condition is true and the node is attached, then returns the owner. |
void | pull() | Reads every followed supplier and applies the values that changed. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
boolean | isBound(String property) | If true, property is bound to a writable signal. |
boolean | isFollowed(String property) | If true, property follows a supplier. |
boolean | isSubscribed() | If true, the node is attached and listens to its signals. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
T | start(String property, V value, Consumer | Drops the binding of property, applies value through applier, then returns the owner. |
void | external(Runnable runnable) | Runs runnable as a change that comes from outside the bound signal, so its write back reaches the signal even when the node has not seen its last value yet. |
void | see(String property) | Records the current value of the signal bound to property as seen by the node. |
void | track(InteractiveValue<?> value) | Registers an interactive value, so input dispatches mark and commit it. |
void | mark() | Marks every interactive value at the start of an input dispatch. |
void | commit() | Commits every interactive value at the end of an input dispatch. |
T | listen(EventType type, EventListener listener) | Adds listener for the events of type, then returns the owner. |
this | fire(EventType<?> type, Supplier | Creates the event with event and fires it, and returns it; it returns null and creates nothing when no listener waits for this type. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
E | fireSubscribed(EventType<?> type, Supplier | Fires like fire(...) while the node is attached, after the signal notifications in progress; it returns null when the node is detached. |
Creation details
Section titled “Creation details”NodeBindings
Section titled “NodeBindings”NodeBindings(Object owner, EventBus eventBus, Supplier<String> name, Consumer<Runnable> runner)
Creates the bindings of owner, which fires its events on eventBus, is named by name in the warnings and runs each event listener through runner.
Method details
Section titled “Method details”void open()
Opens a batch: signal notifications and queued events wait until the matching close().
void close()
Closes a batch; at the outermost level, it delivers the queued events in their order.
release
Section titled “release”void release(String property)
Drops the binding or the followed supplier of property.
releaseFollows
Section titled “releaseFollows”void releaseFollows()
Drops every followed supplier and keeps the bindings to signals, as on the copy of a node.
subscribe
Section titled “subscribe”void subscribe(boolean loaded)
Listens to the bound and watched signals, at the attachment of the node.
A bound property takes the value its signal reached while the node was detached; when loaded is true, a watch whose signal changed meanwhile runs once.
unsubscribe
Section titled “unsubscribe”void unsubscribe()
Stops listening to the signals, at the detachment of the node.
follow
Section titled “follow”<T, V> T follow(String property, Supplier<V> supplier, Consumer<V> applier)
Applies the value of supplier to property now and again before each frame when it changes, then returns the owner.
A constant ComputedSignal applies once and is not kept.
this bind(String property, Signal<V> signal, Consumer<V> applier, Function<M,V> writer) fluent
Binds property to signal in both directions, then returns the owner: applier receives each value of the signal except null, and writer turns the value of the node into the value to write back.
Throws an IllegalArgumentException when the signal is read-only.
bindNullable
Section titled “bindNullable”<T, V, M> T bindNullable(String property, Signal<V> signal, Consumer<V> applier, Function<M,V> writer)
Throws:
IllegalArgumentException: The … of … is changed by the user, so it cannot follow …, which cannot be written: pass a writable Signal, or its value as a start value
Binds property like bind(...), and passes null values to applier too.
void sync(String property, Object value)
Writes value back to the signal bound to property.
When bound controls keep correcting each other’s value, it stops after 16 corrections, restores the value of the signal and prints a dev warning.
void batch(Runnable runnable)
Runs runnable inside a batch.
<T> T watch(Signal<?> signal, BooleanSupplier condition, Runnable action)
Runs action after each change of signal while condition is true and the node is attached, then returns the owner.
void pull()
Reads every followed supplier and applies the values that changed. When an applier throws, JOID prints a warning and the property keeps its previous value.
isBound
Section titled “isBound”boolean isBound(String property)
If true, property is bound to a writable signal.
isFollowed
Section titled “isFollowed”boolean isFollowed(String property)
If true, property follows a supplier.
isSubscribed
Section titled “isSubscribed”boolean isSubscribed()
If true, the node is attached and listens to its signals.
<T, V> T start(String property, V value, Consumer<V> applier)
Drops the binding of property, applies value through applier, then returns the owner.
external
Section titled “external”void external(Runnable runnable)
Runs runnable as a change that comes from outside the bound signal, so its write back reaches the signal even when the node has not seen its last value yet.
void see(String property)
Records the current value of the signal bound to property as seen by the node.
void track(InteractiveValue<?> value)
Registers an interactive value, so input dispatches mark and commit it.
void mark()
Marks every interactive value at the start of an input dispatch.
commit
Section titled “commit”void commit()
Commits every interactive value at the end of an input dispatch.
listen
Section titled “listen”<T> T listen(EventType<?> type, EventListener<?> listener)
Adds listener for the events of type, then returns the owner.
this fire(EventType<?> type, Supplier<E> event) fluent
Creates the event with event and fires it, and returns it; it returns null and creates nothing when no listener waits for this type.
A cancellable or consumable event fires at once; another one waits for the end of the batch in progress.
fireSubscribed
Section titled “fireSubscribed”<E extends Event> E fireSubscribed(EventType<?> type, Supplier<E> event)
Fires like fire(...) while the node is attached, after the signal notifications in progress; it returns null when the node is detached.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
