sdk2 project state management initial version #3083
Merged
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.
Context
Closes opral/inlang-sdk#120.
Architecture
The state is derived from the files in lix.
The files in lix are the source of truth. That's great for
reproducibility (you can send the file(s) around, the state
is always reproducible), crash resistance, and ensures that
the interplay with lix (tracking changes) works.
Every setter writes to a lix file, not the in-memory state.
Avoids running out of sync with the project file and ensures
that lix is tracking changes correctly.
Reactivity is contained in
/state
and does not leak outside.Maintaining reactivity is a high effort. Especially if reactivity
is all over the codebase. We learned this the hard way
(like full refactor hard way). Thus,
/state
reactive side effectsare modeled in
/state
alone.Notable changes
every state getter is async e.g.
project.settings.get()
.Making getters async is a hard requirement to derive state from the lix filesystem. Alternatively, the getters are "fake sync" where the UI will run out of sync. I looked into fink2 source code and already found multiple potential errors because project.settings.get() was sync.
a utility function
pollQuery()
has been implemented.Implementing polling manually everywhere is annoying and doesn't account for diffs. The utility function diffs and only emits if changes happen.