Giter VIP home page Giter VIP logo

Comments (4)

pedroql avatar pedroql commented on May 24, 2024 1

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.

pedroql avatar pedroql commented on May 24, 2024 1

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.

mochadwi avatar mochadwi commented on May 24, 2024

The UI indeed much work to do. But the tools to play, pause, record, rewind the state is enough tweaking the MVFlowImpl?

from mvflow.

mochadwi avatar mochadwi commented on May 24, 2024

Nice, will check for your patch!

from mvflow.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.