mvrx-mocking / com.airbnb.mvrx.mocking / DataClassSetDsl

DataClassSetDsl

interface DataClassSetDsl

When a lambda has a receiver that extends this class it can make use of this special DSL syntax for changing properties on a data class. This syntax makes it easier to change deeply nested properties.

Example: mavericksState.set { ::listing { ::host { ::name } } }.with { "Elena" }

Types

NestedProperty

open class NestedProperty<Type : Any, NestedType> : KProperty0<NestedType>

Represents two properties that are associated by a nested object hierarchy.

Setter

class Setter<DataClass : Any, PropType>

Helper to copy a nested class and update a property on it.

Functions

invoke

open operator fun <Type1 : Any, Type2> KProperty0<Type1?>.invoke(block: Type1.() -> KProperty0<Type2>): KProperty0<Type2>

set

open fun <DataClass : Any, Type> DataClass.set(block: DataClass.() -> KProperty0<Type>): DataClassSetDsl.Setter<DataClass, Type>

A small utility function to help copy kotlin data classes when changing a single property, especially where there is deep nesting. This is heavy on reflection, so isn't intended for high performance use cases.

setEmpty

open fun <DataClass : Any, T> DataClass.setEmpty(block: DataClass.() -> KProperty0<List<T>?>): DataClass

Shortcut to set a List property to an empty list.

setFalse

open fun <DataClass : Any> DataClass.setFalse(block: DataClass.() -> KProperty0<Boolean?>): DataClass

Shortcut to set a Boolean property to false.

setLoading

open fun <DataClass : Any, Type : Async<AsyncType>, AsyncType> DataClass.setLoading(block: DataClass.() -> KProperty0<Type>): DataClass

A shortcut to setting an Async property to Loading, instead of "data.set { ::property }.with { Loading() }".

setNetworkFailure

open fun <DataClass : Any, Type : Async<AsyncType>, AsyncType> DataClass.setNetworkFailure(block: DataClass.() -> KProperty0<Type>): DataClass

A shortcut to setting an Async property to Fail, instead of "data.set { ::property }.with { Fail() }".

setNull

open fun <DataClass : Any, Type> DataClass.setNull(block: DataClass.() -> KProperty0<Type?>): DataClass

A shortcut to setting a property to null, instead of "data.set { ::property }.with { null }".

setTrue

open fun <DataClass : Any> DataClass.setTrue(block: DataClass.() -> KProperty0<Boolean?>): DataClass

Shortcut to set a Boolean property to true.

setZero

open fun <DataClass : Any> DataClass.setZero(block: DataClass.() -> KProperty0<Number?>): DataClass

Shortcut to set a numeric property to zero.

success

open fun <T, Type> Async<T>.success(block: T.() -> KProperty0<Type>): KProperty0<Type>

Use this to update the property value of an Async's type when it is in the Success state. This will throw an exception if the Async it is used on is not Success.

with

open fun <PropertyType, DataClass : Any> DataClassSetDsl.Setter<DataClass, PropertyType>.with(block: (PropertyType) -> PropertyType): DataClass

Provide the new value to update your property to. "it" in the lambda is the lambda is the current value, and you should return the new value.

Inheritors

MockBuilder

open class MockBuilder<V : MockableMavericksView, Args : Parcelable> : MavericksViewMocks<V, Args>, DataClassSetDsl