-
-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement
InitialRoot
option for Document attachment (#986)
This commit allows setting initial values for documents with a predefined structure. It checks if the document has been set up with initial values and applies them if not, instead of checking for an empty or initial state. The attach function now accepts an initialRoot option, which can be partially applied. Existing keys in the Document are preserved, while new keys from initialRoot are added. This implementation applies initialRoot locally after pushpull during Attach. Usage example: doc := document.New("key-1") client1.Attach(ctx, doc, client.WithInitialRoot(map[string]any{ "k": json.NewCounter(0, crdt.LongCnt), })) doc.Update(func(root *json.Object, p *presence.Presence) error { root.GetCounter("k").Increase(1) return nil }) Note: - No type checking is performed for initialRoot elements. - Concurrent document creation may lead to overwrites due to LWW.
- Loading branch information
1 parent
9e36425
commit 70309c9
Showing
4 changed files
with
327 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters