add undo-aware dirty tracking for documents#1060
Open
Third-Thing wants to merge 1 commit intolapce:mainfrom
Open
add undo-aware dirty tracking for documents#1060Third-Thing wants to merge 1 commit intolapce:mainfrom
Third-Thing wants to merge 1 commit intolapce:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The original proposal (#1054) resulted in users needing to subscribe to cache_rev for reactivity:
This led to a choice between a dedicated reactive dirty-state API,
Document::dirty() -> Memo<bool>, or makingis_dirty()reactive.The main reason for choosing the Memo approach was separation of concerns.
is_dirty()remains a plain imperative query, whiledirty()is the explicit reactive hook for UI. That removes the need to piggyback oncache_rev(), keeps dirty-state subscriptions decoupled from layout/cache invalidation, and makes application code clearer: views subscribe todoc.dirty().get(), while non-reactive code can still calldoc.is_dirty().Further, a tracked
is_dirty()would hide reactive behavior behind what looks like a normal getter and would implicitly subscribe callers to the full buffer signal. A dedicated memo is more explicit and only propagates when the dirty boolean actually changes.With this change, reactive UI becomes:
This would be a breaking change for types that implement Document. However, given that the existing Document methods imply a dynamic document (not static) it's assumed that the ability to properly track changes will be welcome.