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

Support nested updates of objects through realm.create via UpdateMode.All #5944

Merged
merged 10 commits into from
Jul 14, 2023

Conversation

kraenhansen
Copy link
Member

@kraenhansen kraenhansen commented Jun 27, 2023

What, How & Why?

This PR implements an initial solution for applying the UpdateMode to all objects when passed to Realm.create().

This closes #5933.

☑️ ToDos

  • 📝 Changelog entry
  • 🚦 Tests

@cla-bot cla-bot bot added the cla: yes label Jun 27, 2023
@kraenhansen kraenhansen removed their assignment Jun 29, 2023
@kraenhansen
Copy link
Member Author

kraenhansen commented Jul 5, 2023

While having a state (currentUpdateMode on Realm) might work for now, I'd suggest avoiding storing and maintaining state for operations as it has a couple of drawbacks:

  • It can cause weird bugs if not properly set between calls of the operation.
    • If the reset happen at the end, it might not happen if an exception is throw.
    • If it happens in the beginning (as your suggestion is too), the deep dependent code has implicit dependencies on the state being sat before it's called, which isn't easily expressed in code and you'd need to rely on documentation. This makes the deep code less composable and therefore harder to reuse.
  • It will make it more difficult to transition the implementation into asynchronous code (i.e. make it harder to change if we wanted to), since that might introduce concurrent calls into the deep code and it can't reasonably expect the state to originate from its particular invocation.

All in all, I'd suggest refactoring to passing the update mode through argument, possibly by adding a property to the CreationContext.

@elle-j elle-j marked this pull request as ready for review July 13, 2023 09:27
@elle-j elle-j requested review from takameyer and kneth July 13, 2023 09:28
@elle-j
Copy link
Member

elle-j commented Jul 13, 2023

@kraenhansen, very valuable input! We've discussed various issues and options on Slack (see our channel) with your input in mind. For now we've opted to move forward with the initial solution (but using try-finally for setting/unsetting currentUpdateMode), and creating a ticket for finding a more ideal solution for a later v12 release.

Copy link
Contributor

@takameyer takameyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Just a few clarifying questions/suggestions

packages/realm/src/TypeHelpers.ts Show resolved Hide resolved
integration-tests/tests/src/tests/objects.ts Show resolved Hide resolved
@elle-j elle-j merged commit 03c1887 into main Jul 14, 2023
32 checks passed
@elle-j elle-j deleted the kh/nested-object-updates branch July 14, 2023 10:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UpdateMode doesn't get passed recursively when creating child objects in realm v12
4 participants