This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object TestStore : Store( | |
storeThread = null, | |
logger = { tag, message -> Log.d(tag, message) }) { | |
fun clear() { | |
sideEffects.clear() | |
stateHandlers.clear() | |
state = State() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun should_query_by_localId_correctly() { | |
val item = createPersistenceItem(1) | |
item.insertOrUpdate(db) | |
val managedItem = db.queryByLocalId(item.localId) | |
assertThat(managedItem, iz(notNullValue())) | |
managedItem!!.assertIsEqualsTo(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun should_reduceItemsCollection_when_CreateItemAction_and_empty_collection() { | |
val createItemAction = CreateItemAction( | |
localId = LOCAL_ID, | |
text = TEXT, | |
favorite = FAVORITE, | |
color = COLOR, | |
position = POSITION) | |
val itemsReduced = CreationReducer.reduceItemsCollection( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun should_delete_Item_and_handle_State() { | |
val item1 = createItem(1) | |
val item2 = createItem(2) | |
val item3 = createItem(3) | |
val defaultList = listOf(item1, item2, item3) | |
val state = State(itemsListScreen = ItemsListScreen(defaultList), | |
navigation = Navigation.ITEMS_LIST) | |
store.dispatch(state) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.cesarvaliente.kunidirectional.persistence.Color as PersistenceColor | |
import com.cesarvaliente.kunidirectional.store.Color as StoreColor | |
fun StoreColor.toPersistenceColor(): PersistenceColor = | |
when (this) { | |
StoreColor.BLUE -> PersistenceColor.BLUE | |
StoreColor.GREEN -> PersistenceColor.GREEN | |
StoreColor.RED -> PersistenceColor.RED | |
StoreColor.WHITE -> PersistenceColor.WHITE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Color.toColorResource(): Int = | |
//We don't use Presentation models, we enrich the Store models using EF | |
when (this) { | |
RED -> R.color.red | |
YELLOW -> R.color.yellow | |
GREEN -> R.color.green | |
BLUE -> R.color.blue | |
WHITE -> R.color.white | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RealmClass | |
open class Item() : RealmModel { | |
constructor(localId: String, text: String?, favorite: Boolean = false, | |
colorEnum: Color = Color.WHITE, position: Long) : this() { | |
this.localId = localId | |
this.text = text | |
this.favorite = favorite | |
this.color = colorEnum.name | |
this.position = position | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum class Color { | |
RED, YELLOW, GREEN, BLUE, WHITE | |
} | |
data class Item( | |
val localId: String = generateLocalId(), | |
val text: String? = null, | |
val favorite: Boolean = false, | |
val color: Color = Color.WHITE, | |
val position: Long = object : PositionsFactory {}.newPosition()) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
compile project(':persistence') | |
compile project(':store') | |
........ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersistenceSideEffect(val store: Store, | |
persistenceThread: ThreadExecutor? = null): SideEffect(persistenceThread) { | |
init { | |
store.sideEffects.add(this) | |
} | |
override fun handle(action: Action) { | |
when (action) { | |
is CreationAction -> CreationHandler.handle(action) { store.dispatch(it) } |
NewerOlder