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

UndoManager POC #2

Open
DandyLyons opened this issue Nov 8, 2023 · 0 comments
Open

UndoManager POC #2

DandyLyons opened this issue Nov 8, 2023 · 0 comments

Comments

@DandyLyons
Copy link
Contributor

DandyLyons commented Nov 8, 2023

I'm not sure if you're interested, but I would like to get a proof of concept made for implementing SwiftData's undo/redo functionality in TCA.

I've explored it some so far but it is not easy. Two major problems I've found so far:

  1. Registering the UndoManager with SwiftData:
  • Undo/Redo functionality is off by default, and so far the only way I've seen how to enable it is:
    1. pass isUndoEnabled: true into modelContainer(for:inMemory:isAutosaveEnabled:isUndoEnabled:onSetup:)
    2. then grab the undo manager from @Environment(\.undoManager)
    3. then call undoManager.undo()
  • But, right now, we are creating our ModelContainer manually in our Dependency client and none of the initializers for ModelContainer, ModelConfiguration, nor ModelContext have a isUndoEnabled param.
  • Perhaps, we can just create our own UndoManager and attach it to our context, but I've tried that in various ways and have yet to get it working.
  1. Observability:
  • Currently, we're calling send(.onAppear) to refresh our data, any time that we ask SwiftData to make a change. But the problem is 1) we have to remember to always call send(.onAppear), and 2) If something else modifies SwiftData (e.g. a sync from CloudKit) then we are unaware and we now have stale data.
  • If we were using vanilla @Query it would handle this for us. I discovered a way to incorporate an @Query into TCA. Here's a PR. I'm still learning the pros/cons of this approach.
  • Also, in a few weeks pointfree.co will release their solution for implementing Observable into TCA. So hopefully that should solve observability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant