//reactivestate-core/com.ensody.reactivestate/EventNotifier
EventNotifier¶
interface EventNotifier<T> : MutableFlow<T.() -> Unit>
This is used to send events to an observer. All events are queued for later processing.
The possible events are defined as method calls on an interface T. This allows for easy composition of multiple events. One of the most common events interfaces is ErrorEvents.
See also¶
ReactiveState | for more advanced usage of this pattern. Example: kotlin interface MyHandlerEvents : ErrorEvents, OtherEvents { fun onSomethingHappened() }<br>class MyHandler { val eventNotifier = EventNotifier<MyHandlerEvents>()<br> fun doSomething() { withErrorReporting(eventNotifier) { if (computeResult() 5) { eventNotifier { onSomethingHappened() } } else { eventNotifier { onOtherEvent() } } } } } |
Functions¶
Name | Summary |
---|---|
addDelay | [common] fun <T> Flow<T>.addDelay(timeoutMillis: Long): Flow<T> Adds a timeoutMillis delay to a Flow. If delay is zero or negative this is a no-op. |
cancel | [common] abstract fun cancel() |
collect | [common] abstract suspend fun collect(collector: FlowCollector<T.() -> Unit>) |
conflatedMap | [common] inline fun <T, R> Flow<T>.conflatedMap(timeoutMillis: Long = 0, crossinline transform: suspend (value: T) -> R): Flow<R> Maps a conflated Flow with timeoutMillis delay between the first and last element. |
conflatedTransform | [common] inline fun <T, R> Flow<T>.conflatedTransform(timeoutMillis: Long = 0, crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit): Flow<R> Transforms a conflated Flow with timeoutMillis delay between the first and last element. |
conflatedWorker | [common] fun <T, R> Flow<T>.conflatedWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R> Executes each lambda in a Flow using conflatedMap. |
debounceWorker | [common] fun <T, R> Flow<T>.debounceWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R> Executes each lambda in a Flow using debounce and map. |
emit | [common] abstract suspend fun emit(value: T.() -> Unit) |
handleEvents | [common] suspend fun <T : ErrorEvents> EventNotifier<T>.handleEvents(handler: T) Consumes and handles EventNotifier’s events on the given handler. |
invoke | [common] abstract operator fun invoke(block: T.() -> Unit) Adds a lambda function to the event stream. |
isEmpty | [common] abstract fun isEmpty(): Boolean |
latestWorker | [common] fun <T, R> Flow<T>.latestWorker(timeoutMillis: Long = 0, transform: FlowTransform<T, R>): Flow<R> Executes each lambda in a Flow using debounce and mapLatest. |
shareOnDemand | [common] fun <T> Flow<T>.shareOnDemand(replay: Int = 0, context: CoroutineContext = EmptyCoroutineContext): SharedFlow<T> Turns this Flow into a SharedFlow without requiring a CoroutineScope (unlike shareIn). |
stateOnDemand | [common] fun <T> Flow<T>.stateOnDemand(context: CoroutineContext = EmptyCoroutineContext, synchronous: Boolean = true, emitValueOnStart: Boolean = true, getter: (previous: Wrapped<T>?) -> T): StateFlow<T> Turns this Flow into a StateFlow without requiring a CoroutineScope (unlike stateIn). |
tryEmit | [common] abstract fun tryEmit(value: T.() -> Unit): Boolean Adds a value to this Flow if there’s still capacity left. |