Are there any good examples of how I could make al...
# redux
a
Are there any good examples of how I could make all of my redux interactions happen on a background thread except for subscriptions for the UI? I would ideally like to be able to do reducer and async actions all on a background thread, so as to not slowdown my UI, but sadly I have not found many resources on this topic. Seems that most examples I've seen do everything on the main thread, which is fine until it comes to IO stuff like network requests/db requests.
b
Just switching to a background thread and instantiating your threadsafe store there should do the trick.
🎉 1
a
I'll try that. Thank you 👍🎉
b
If that doesn't work, you could implement your own main-safe store wrapper that switches suspend context on each interaction
👍 1
a
Tried something like this:
Copy code
val singleThreadDispatcher = newSingleThreadContext("test")
        CoroutineScope(singleThreadDispatcher + Job()).launch {
            suspend {
                    createThreadSafeStore(
                        reducer = appReducer,
                        enhancer = applyMiddleware(
                            loggerMiddleware
                        ),
                        preloadedState = AppState(platformState = platformState)
                    )
                
            }()
        }
Maybe I'm doing something wrong due to a miss understanding of dispatching on coroutines, but for some reason when I run this code my thread stays on the main thread when testing on iOS at least.
maybe I'm over complicating things too.