Rename ExceptionsStore/State/Action to ExceptionsFragmentStore/State/Action.
This commit is contained in:
parent
ac32a88d45
commit
22446263f1
|
@ -26,7 +26,7 @@ import org.mozilla.fenix.components.StoreProvider
|
|||
import org.mozilla.fenix.settings.SupportUtils
|
||||
|
||||
class ExceptionsFragment : Fragment() {
|
||||
private lateinit var exceptionsStore: ExceptionsStore
|
||||
private lateinit var exceptionsStore: ExceptionsFragmentStore
|
||||
private lateinit var exceptionsView: ExceptionsView
|
||||
private lateinit var exceptionsInteractor: ExceptionsInteractor
|
||||
|
||||
|
@ -43,8 +43,8 @@ class ExceptionsFragment : Fragment() {
|
|||
): View? {
|
||||
val view = inflater.inflate(R.layout.fragment_exceptions, container, false)
|
||||
exceptionsStore = StoreProvider.get(this) {
|
||||
ExceptionsStore(
|
||||
ExceptionsState(
|
||||
ExceptionsFragmentStore(
|
||||
ExceptionsFragmentState(
|
||||
items = loadAndMapExceptions()
|
||||
)
|
||||
)
|
||||
|
@ -102,7 +102,7 @@ class ExceptionsFragment : Fragment() {
|
|||
|
||||
coroutineScope {
|
||||
launch(Main) {
|
||||
exceptionsStore.dispatch(ExceptionsAction.Change(items))
|
||||
exceptionsStore.dispatch(ExceptionsFragmentAction.Change(items))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,29 +15,29 @@ import mozilla.components.lib.state.Store
|
|||
data class ExceptionsItem(val url: String)
|
||||
|
||||
/**
|
||||
* The [Store] for holding the [ExceptionsState] and applying [ExceptionsAction]s.
|
||||
* The [Store] for holding the [ExceptionsFragmentState] and applying [ExceptionsFragmentAction]s.
|
||||
*/
|
||||
class ExceptionsStore(initialState: ExceptionsState) :
|
||||
Store<ExceptionsState, ExceptionsAction>(initialState, ::exceptionsStateReducer)
|
||||
class ExceptionsFragmentStore(initialState: ExceptionsFragmentState) :
|
||||
Store<ExceptionsFragmentState, ExceptionsFragmentAction>(initialState, ::exceptionsStateReducer)
|
||||
|
||||
/**
|
||||
* Actions to dispatch through the `ExceptionsStore` to modify `ExceptionsState` through the reducer.
|
||||
*/
|
||||
sealed class ExceptionsAction : Action {
|
||||
data class Change(val list: List<ExceptionsItem>) : ExceptionsAction()
|
||||
sealed class ExceptionsFragmentAction : Action {
|
||||
data class Change(val list: List<ExceptionsItem>) : ExceptionsFragmentAction()
|
||||
}
|
||||
|
||||
/**
|
||||
* The state for the Exceptions Screen
|
||||
* @property items List of exceptions to display
|
||||
*/
|
||||
data class ExceptionsState(val items: List<ExceptionsItem>) : State
|
||||
data class ExceptionsFragmentState(val items: List<ExceptionsItem>) : State
|
||||
|
||||
/**
|
||||
* The ExceptionsState Reducer.
|
||||
*/
|
||||
fun exceptionsStateReducer(state: ExceptionsState, action: ExceptionsAction): ExceptionsState {
|
||||
fun exceptionsStateReducer(state: ExceptionsFragmentState, action: ExceptionsFragmentAction): ExceptionsFragmentState {
|
||||
return when (action) {
|
||||
is ExceptionsAction.Change -> state.copy(items = action.list)
|
||||
is ExceptionsFragmentAction.Change -> state.copy(items = action.list)
|
||||
}
|
||||
}
|
|
@ -79,7 +79,7 @@ class ExceptionsView(
|
|||
view.exceptions_empty_view.text = textWithLink
|
||||
}
|
||||
|
||||
fun update(state: ExceptionsState) {
|
||||
fun update(state: ExceptionsFragmentState) {
|
||||
view.exceptions_empty_view.visibility =
|
||||
if (state.items.isEmpty()) View.VISIBLE else View.GONE
|
||||
view.exceptions_list.visibility = if (state.items.isEmpty()) View.GONE else View.VISIBLE
|
||||
|
|
|
@ -9,14 +9,14 @@ import org.junit.Assert.assertEquals
|
|||
import org.junit.Assert.assertNotSame
|
||||
import org.junit.Test
|
||||
|
||||
class ExceptionsStoreTest {
|
||||
class ExceptionsFragmentStoreTest {
|
||||
@Test
|
||||
fun onChange() = runBlocking {
|
||||
val initialState = emptyDefaultState()
|
||||
val store = ExceptionsStore(initialState)
|
||||
val store = ExceptionsFragmentStore(initialState)
|
||||
val newExceptionsItem = ExceptionsItem("URL")
|
||||
|
||||
store.dispatch(ExceptionsAction.Change(listOf(newExceptionsItem))).join()
|
||||
store.dispatch(ExceptionsFragmentAction.Change(listOf(newExceptionsItem))).join()
|
||||
assertNotSame(initialState, store.state)
|
||||
assertEquals(
|
||||
store.state.items,
|
||||
|
@ -24,7 +24,7 @@ class ExceptionsStoreTest {
|
|||
)
|
||||
}
|
||||
|
||||
private fun emptyDefaultState(): ExceptionsState = ExceptionsState(
|
||||
private fun emptyDefaultState(): ExceptionsFragmentState = ExceptionsFragmentState(
|
||||
items = listOf()
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user