Hi! I am trying to implement some sort of event store / redux store using corutines in android application
Here is the pseudocode:
Copy code
class Store {
private val channel = Channel<Action>()
suspend func dispatch(action: Action) {
channel.send(action)
}
init {
GlobalScope.launch {
for (action in channel) {
reduce(action)
notifyObservers()
}
}
}
}
Sadly, this code doesn't work - actions are not reducer.
Small detail: If i will explicitly set Dispatchers.Main in init and in dispatch - it work, but defeats my purpose.
My goal is to move action processing of main thread.
notifyObservers
will build
Props
for each active
ViewModel
and publish.
h
Hanno
06/14/2020, 10:09 PM
I am Not an android nor a redux expert, but reducers in redux are pure functions, that take a state, an Action and return the new state. You already have an action, but where is your state? In redux you pass the initial state when you create the store, so i guess it's an instance property of the store.
Where is "reduce" defined?