org.reactfx.DefaultEventStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of richtextfx Show documentation
Show all versions of richtextfx Show documentation
FX-Text-Area for formatted text and other special effects.
package org.reactfx;
import java.util.function.Consumer;
class DefaultEventStream extends EventStreamBase {
private final EventStream input;
private final T initial;
private T latestEvent = null;
private boolean firstObserver = true;
private boolean emitted = false;
public DefaultEventStream(
EventStream input,
T initial) {
this.input = input;
this.initial = initial;
}
@Override
protected void newObserver(Consumer super T> observer) {
if(firstObserver) {
firstObserver = false;
if(!emitted) {
observer.accept(initial);
}
} else {
observer.accept(latestEvent);
}
}
@Override
protected final Subscription observeInputs() {
firstObserver = true;
emitted = false;
latestEvent = initial;
return input.subscribe(x -> {
latestEvent = x;
emitted = true;
emit(x);
});
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy