Comments (4)
Hi Mochamad,
While something like that is possible, I haven't worked on that nor am planning to.
If you want to create a quick POC, you can handle the rendered states in this line (e.g. keep them in a list if you are recording).
But the UI work is a fair bit of work and yet another chunk of work if you would like to have an extensible solution (for the POC you can just modify the MVFlowImpl
class).
from mvflow.
Yes, that should be fine.
Here's a quick patch I created. Not saying it's perfect but probably is enough to get you started.
Note: I didn't run/compile this but you should be able to fill in the blanks if needed.
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- mvflow-core/src/main/kotlin/net/pedroloureiro/mvflow/MVFlow.kt (revision 16270e644cc47534d45b93e172bcef0560c9ea62)
+++ mvflow-core/src/main/kotlin/net/pedroloureiro/mvflow/MVFlow.kt (date 1603218980185)
@@ -189,7 +189,7 @@
fun observeEffects(): Flow<Effect>
}
-private class MVFlowImpl<State, Action, Mutation, Effect>(
+private class ReplayableMVFlowImpl<State, Action, Mutation, Effect>(
initialState: State,
private val handler: HandlerWithEffects<State, Action, Mutation, Effect>,
private val reducer: Reducer<State, Mutation>,
@@ -199,6 +199,8 @@
private val state = MutableStateFlow(initialState)
private val externalEffectChannel = BroadcastChannel<Effect>(Channel.BUFFERED)
private val mutex = Mutex()
+ // warning: this list might become so big it might give you OOM problems
+ private val previousStates = mutableListOf<State>()
private inner class LoggingEffectSender(private val logger: Logger) : EffectSender<Effect> {
override suspend fun send(effect: Effect) {
@@ -239,6 +241,12 @@
}
}
+ fun replayState(view: MVFlow.View<State, Action>, index: Int) {
+ // with a few more changes we could store the view in this impl class but keep in mind that the view outlives
+ // the flow container so you are risk leaking the view (and probably the activity with that)
+ view.render(previousStates[index])
+ }
+
private fun sendStateUpdatesIntoView(
callerCoroutineScope: CoroutineScope,
view: MVFlow.View<State, Action>,
@@ -254,6 +262,7 @@
.onEach {
logger.invoke("New state: $it")
view.render(it)
+ previousStates.add(it)
}
.launchIn(callerCoroutineScope)
}
from mvflow.
The UI indeed much work to do. But the tools to play, pause, record, rewind the state is enough tweaking the MVFlowImpl
?
from mvflow.
Nice, will check for your patch!
from mvflow.
Related Issues (11)
- Unit Test samples HOT 1
- Handler State Become Stale for Actions That Produce Long Running Flows HOT 1
- Ability to allow same Flow emission HOT 4
- is it possible to use MVFlow in Jetpack Compose? HOT 1
- Consider moving from SharedFlow to Channel HOT 1
- Best practices to send a throwable from Fragment/Activity? HOT 2
- Is it possible to combine reducer & handler? HOT 1
- Migrate from jcenter HOT 1
- How to stop an async task launched by the handler HOT 2
- Android sample app wont even sync on latest Android Studio Iguana HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mvflow.