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

sdk2 project state management initial version #3083

Conversation

samuelstroschein
Copy link
Member

@samuelstroschein samuelstroschein commented Aug 29, 2024

Context

Closes opral/inlang-sdk#120.

  • State in the inlang project must react to changing settings.
  • State should be derived from the lix files for reproduction and reliability (lix is the source of truth)

Architecture

  1. 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.

  2. 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.

  3. 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 effects
    are 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.

-project.settings.get()
+await project.settings.get()

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.

pollQuery(
  () => db.selectFrom("mock").where("id", "=", "joker").selectAll().execute(),
).subscribe((value) => console.log(value);

Copy link

changeset-bot bot commented Aug 29, 2024

⚠️ No Changeset found

Latest commit: b8f2702

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@samuelstroschein samuelstroschein merged commit 5312b1d into lix-integration Aug 29, 2024
2 checks passed
@samuelstroschein samuelstroschein deleted the samuelstroschein/mesdk-161-reactive-state-for-projectsettings-and-projectplugins branch August 29, 2024 22:43
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant