Skip to content

Commit 36b6552

Browse files
Merge pull request #1193 from yogeshpaliyal/fixBrokenRedux
feat: fix broken redux
2 parents 79fc9b8 + fbeb990 commit 36b6552

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/DashboardComposeActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import com.yogeshpaliyal.keypass.ui.style.KeyPassTheme
7272
import dagger.hilt.android.AndroidEntryPoint
7373
import org.reduxkotlin.compose.StoreProvider
7474
import org.reduxkotlin.compose.rememberDispatcher
75-
import org.reduxkotlin.compose.selectState
75+
import com.yogeshpaliyal.keypass.ui.redux.selectState
7676

7777
val LocalUserSettings = compositionLocalOf { UserSettings() }
7878

app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/components/DashboardBottomSheet.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import com.yogeshpaliyal.keypass.ui.nav.BottomNavViewModel
1414
import com.yogeshpaliyal.keypass.ui.nav.NavigationModelItem
1515
import com.yogeshpaliyal.keypass.ui.redux.actions.BottomSheetAction
1616
import com.yogeshpaliyal.keypass.ui.redux.actions.NavigationAction
17+
import com.yogeshpaliyal.keypass.ui.redux.selectState
1718
import com.yogeshpaliyal.keypass.ui.redux.states.BottomSheetState
1819
import com.yogeshpaliyal.keypass.ui.redux.states.HomeState
1920
import com.yogeshpaliyal.keypass.ui.redux.states.KeyPassState
2021
import org.reduxkotlin.compose.rememberDispatcher
21-
import org.reduxkotlin.compose.selectState
2222

2323
@Composable
2424
fun DashboardBottomSheet(viewModel: BottomNavViewModel) {

app/src/main/java/com/yogeshpaliyal/keypass/ui/nav/components/KeyPassBottomBar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.yogeshpaliyal.keypass.ui.redux.states.KeyPassState
2929
import com.yogeshpaliyal.keypass.ui.redux.states.ScreenState
3030
import com.yogeshpaliyal.keypass.ui.redux.states.SettingsState
3131
import org.reduxkotlin.compose.rememberDispatcher
32-
import org.reduxkotlin.compose.selectState
32+
import com.yogeshpaliyal.keypass.ui.redux.selectState
3333

3434

3535

app/src/main/java/com/yogeshpaliyal/keypass/ui/redux/KeyPassRedux.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.yogeshpaliyal.keypass.ui.redux
22

3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.DisallowComposableCalls
5+
import androidx.compose.runtime.DisposableEffect
6+
import androidx.compose.runtime.mutableStateOf
7+
import androidx.compose.runtime.remember
38
import com.yogeshpaliyal.keypass.ui.redux.actions.BatchActions
49
import com.yogeshpaliyal.keypass.ui.redux.actions.BottomSheetAction
510
import com.yogeshpaliyal.keypass.ui.redux.actions.GoBackAction
@@ -16,7 +21,9 @@ import com.yogeshpaliyal.keypass.ui.redux.states.KeyPassState
1621
import com.yogeshpaliyal.keypass.ui.redux.states.ScreenState
1722
import com.yogeshpaliyal.keypass.ui.redux.states.generateDefaultState
1823
import org.reduxkotlin.Reducer
24+
import org.reduxkotlin.TypedStore
1925
import org.reduxkotlin.applyMiddleware
26+
import org.reduxkotlin.compose.rememberStore
2027
import org.reduxkotlin.createStore
2128

2229
object KeyPassRedux {
@@ -100,3 +107,44 @@ object KeyPassRedux {
100107
applyMiddleware(utilityMiddleware, intentNavigationMiddleware)
101108
)
102109
}
110+
111+
112+
113+
/**
114+
* * These are function copied from
115+
* * https://github.com/reduxkotlin/redux-kotlin-compose/blob/master/redux-kotlin-compose/src/commonMain/kotlin/org/reduxkotlin/compose/selectState.kt
116+
* Selects a value from the local store.
117+
* @param selector to extract the value
118+
* @param State state type
119+
* @param Slice extracted value type
120+
* @return selected value
121+
*/
122+
@Composable
123+
public inline fun <reified State, Slice> selectState(
124+
crossinline selector: @DisallowComposableCalls State.() -> Slice
125+
): androidx.compose.runtime.State<Slice> {
126+
return rememberStore<State>().selectState(selector)
127+
}
128+
129+
/**
130+
* These are function copied from
131+
* https://github.com/reduxkotlin/redux-kotlin-compose/blob/master/redux-kotlin-compose/src/commonMain/kotlin/org/reduxkotlin/compose/selectState.kt
132+
*
133+
* Selects a value from the local store.
134+
* @receiver a store to extract the value from
135+
* @param selector to extract the value
136+
* @param State state type
137+
* @param Slice extracted value type
138+
* @return selected value
139+
*/
140+
@Composable
141+
public inline fun <State, Slice> TypedStore<State, *>.selectState(
142+
crossinline selector: @DisallowComposableCalls State.() -> Slice
143+
): androidx.compose.runtime.State<Slice> {
144+
val result = remember { mutableStateOf(state.selector()) }
145+
DisposableEffect(result) {
146+
val unsubscribe = subscribe { result.value = state.selector() }
147+
onDispose(unsubscribe)
148+
}
149+
return result
150+
}

0 commit comments

Comments
 (0)