Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a buffer for text edition #51

Open
leandroBorgesFerreira opened this issue Jun 18, 2023 · 1 comment
Open

Create a buffer for text edition #51

leandroBorgesFerreira opened this issue Jun 18, 2023 · 1 comment

Comments

@leandroBorgesFerreira
Copy link
Owner

leandroBorgesFerreira commented Jun 18, 2023

The state flow with all stories is being updated with every new character typed. A buffer that controls when to update the StateFlow would be a good performance improvement.

@leandroBorgesFerreira
Copy link
Owner Author

The logic to follow is more or less this:

private fun updateTexts(stepMap: Map<Int, StoryStep>): Map<Int, StoryStep> {
        val mutableSteps = stepMap.toMutableMap()

        textChanges.forEach { (position, text) ->
            val editStep = mutableSteps[position]

            editStep?.copy(text = text)?.let { step ->
                mutableSteps[position] = step
            }
        }

        textChanges.clear()

        return mutableSteps
    }

The method updateText should be called when X new characters were added or when a action that changes the state of the Document is done (ex: checking an item, deleting an item, undoing an action)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

No branches or pull requests

1 participant