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

feat(document): add $createModifiedPathsSnapshot(), $restoreModifiedPathsSnapshot(), $clearModifiedPaths() #14699

Merged
merged 6 commits into from
Jul 3, 2024

Conversation

vkarpov15
Copy link
Collaborator

Fix #14268

Summary

$createModifiedPathsSnapshot() takes a snapshot of the document's current change tracking state, without modifying the document's properties. $restoreModifiedPathsSnapshot() restores the document's change tracking state to a given snapshot.

Primarily useful for custom transaction wrappers like #14268. When you modify a document in a transaction and that document was created outside of the transaction, you may need to restore the document's change tracking state if the transaction was aborted.

As part of making this work, I also moved Model.prototype.$__delta and supporting code to Document.prototype.$__delta. Otherwise, getChanges() crashes on subdocuments because subdocuments don't have a $__delta function.

Examples

Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

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

LGTM, some minor suggestions

lib/stateMachine.js Outdated Show resolved Hide resolved
lib/document.js Outdated Show resolved Hide resolved
lib/document.js Outdated Show resolved Hide resolved
lib/document.js Outdated Show resolved Hide resolved
@hasezoey hasezoey added this to the 8.5 milestone Jul 2, 2024
vkarpov15 and others added 4 commits July 3, 2024 11:41
Co-authored-by: hasezoey <hasezoey@gmail.com>
Co-authored-by: hasezoey <hasezoey@gmail.com>
Co-authored-by: hasezoey <hasezoey@gmail.com>
@vkarpov15 vkarpov15 merged commit 0e8525e into 8.5 Jul 3, 2024
46 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-14268 branch July 3, 2024 15:50
Comment on lines +217 to +224
* The function profile can look like:
* this.forEach(state1, fn); // iterates over all paths in state1
* this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
* this.forEach(fn); // iterates over all paths in all states
*
* @param {String} [state]
* @param {String} [state]
* @param {Function} callback
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* The function profile can look like:
* this.forEach(state1, fn); // iterates over all paths in state1
* this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
* this.forEach(fn); // iterates over all paths in all states
*
* @param {String} [state]
* @param {String} [state]
* @param {Function} callback

from what i can still tell, this function does not take any arugments, does it? (also the documented code above has no relation to this function

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

Successfully merging this pull request may close these issues.

2 participants