mvrx-mocking / com.airbnb.mvrx.mocking / MockableMavericksStateStore

MockableMavericksStateStore

class MockableMavericksStateStore<S : MavericksState> : MockableStateStore<S>

Allows switching between a mocked state store and a real state store behavior. This is intended to enable testing.

When StateStoreBehavior.Scriptable behavior is set, next can be called to force a state synchronously. When in this mode, calls to set have no effect. In other modes, it is an error to call next.

The mode can be dynamically changed to modify behavior at runtime.

Constructors

<init>

MockableMavericksStateStore(initialState: S, mockBehavior: MockBehavior, coroutineScope: CoroutineScope, contextOverride: CoroutineContext = EmptyCoroutineContext)

Allows switching between a mocked state store and a real state store behavior. This is intended to enable testing.

Properties

coroutineScope

val coroutineScope: CoroutineScope

flow

val flow: Flow<S>

mockBehavior

var mockBehavior: MockBehavior

state

val state: S

Functions

addOnCancelListener

fun addOnCancelListener(callback: (MockableMavericksStateStore<*>) -> Unit): Unit

addOnStateSetListener

fun addOnStateSetListener(callback: (previousState: S, newState: S) -> Unit): Unit

Add a listener that will be called each time a state is set on this state store via the set function.

get

fun get(block: (S) -> Unit): Unit

next

fun next(state: S): Unit

removeOnStateSetListener

fun removeOnStateSetListener(callback: (previousState: S, newState: S) -> Unit): Unit

set

fun set(stateReducer: S.() -> S): Unit