ResultEventBus


An EventBus for passing results between multiple sets of screens.

It provides solutions for both event and state based results.

For Event results, use a ResultEffect to receive all results.

For State results, use conflateAsState to get only the latest result for a particular key.

These results are not saved across configuration changes or process death.

Summary

Public constructors

Cmn

Public functions

inline State<T>
@Composable
<T : Any?> conflateAsState(defaultValue: T)

Provides a single State from the eventBus for the given class type.

Cmn
State<T>
@Composable
<T : Any?> conflateAsState(resultKey: String, defaultValue: T)

Provides a single State from the eventBus for the given class type.

Cmn
Unit

Removes all results from the store and closes all active result channels.

Cmn
inline Unit
<T : Any?> removeResult()

Removes all results associated with the given type from the store and stops the bus from providing any additional events.

Cmn
Unit
removeResult(resultKey: String)

Removes all results associated with the given key from the store and stops the bus from providing any additional events.

Cmn
inline Unit
<T : Any?> sendResult(result: T)

Sends a result into the channel associated with the given resultKey.

Cmn
Unit
<T : Any?> sendResult(resultKey: String, result: T)

Sends a result into the channel associated with the given resultKey.

Cmn

Public constructors

ResultEventBus

ResultEventBus()

Public functions

conflateAsState

@Composable
inline fun <T : Any?> conflateAsState(defaultValue: T): State<T>

Provides a single State from the eventBus for the given class type.

Developers should use this to retrieve result updates as State.

Parameters
<T : Any?>

the type for the result to be returned as State.

defaultValue: T

the default value for the state when none is available.

conflateAsState

@Composable
fun <T : Any?> conflateAsState(resultKey: String, defaultValue: T): State<T>

Provides a single State from the eventBus for the given class type.

Developers should use this to retrieve result updates as State.

Parameters
<T : Any?>

the type of the State return for the result.

resultKey: String

the key for the State that will be returned.

defaultValue: T

the default value for the state when none is available.

removeAllResults

fun removeAllResults(): Unit

Removes all results from the store and closes all active result channels.

Call this when hoisting ResultEventBus outside of composition (instead of using rememberResultEventBus) to clear pending results when the composition is disposed or state resets.

removeResult

inline fun <T : Any?> removeResult(): Unit

Removes all results associated with the given type from the store and stops the bus from providing any additional events.

Parameters
<T : Any?>

the type of the result to be removed.

removeResult

fun removeResult(resultKey: String): Unit

Removes all results associated with the given key from the store and stops the bus from providing any additional events.

Parameters
resultKey: String

the key of the result to remove.

sendResult

inline fun <T : Any?> sendResult(result: T): Unit

Sends a result into the channel associated with the given resultKey.

Parameters
<T : Any?>

the type of the result.

result: T

the result to send.

sendResult

fun <T : Any?> sendResult(resultKey: String, result: T): Unit

Sends a result into the channel associated with the given resultKey.

Parameters
resultKey: String

the key for the result that is being sent.

result: T

the result to send.