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