You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building an editor application with undo/redo functionality. I separated the undoable domain state from volatile runtime state:
Undoable state -> stored in a MobX(-Keystone) store (UStore) (Being in MobX-Keystone probably shouldn't be of concern here)
Volatile UI/runtime state -> stored in a ViewModel store (VMStore)
The ViewModels wrap the domain objects and add additional observables and computed values.
This obviously doesn't work because the getter creates a new ViewModel instance every time.
However, the ViewModels:
need their own observables
depend on both domain state and volatile state
should stay stable as long as the origin object stays the same
Approaches I considered
computed: Probably wrong, since computed values should be pure and shouldn't create observable objects.
createTransformer / computedFn from mobx-utils: These seem to have the same issue (returning observable instances from computed-like constructs).
Store the VM instances and sync them. For example: keep a currentModeVM and update it when uState.activeMode changes.
But the mechanisms for detecting that change are unclear:
3a. observe / intercept seem discouraged
3b. reaction / autorun run after transactions and are meant for side effects
3c. manually notifying the VM layer from the domain layer feels wrong
Question
What is the best approach?
There seem to be a few issues where that topic was more or less discussed, but they didn't really help me:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm building an editor application with undo/redo functionality. I separated the undoable domain state from volatile runtime state:
Undoable state -> stored in a MobX(-Keystone) store (UStore) (Being in MobX-Keystone probably shouldn't be of concern here)
Volatile UI/runtime state -> stored in a ViewModel store (VMStore)
The ViewModels wrap the domain objects and add additional observables and computed values.
Domain (undoable state)
ViewModels
Each ViewModel wraps a domain object and adds volatile state:
Problem
This obviously doesn't work because the getter creates a new ViewModel instance every time.
However, the ViewModels:
Approaches I considered
But the mechanisms for detecting that change are unclear:
3a. observe / intercept seem discouraged
3b. reaction / autorun run after transactions and are meant for side effects
3c. manually notifying the VM layer from the domain layer feels wrong
Question
What is the best approach?
There seem to be a few issues where that topic was more or less discussed, but they didn't really help me:
Happy to here about best practices, maybe someone has an even better architecture. Maybe I'm really on the wrong path.
Beta Was this translation helpful? Give feedback.
All reactions