-
Notifications
You must be signed in to change notification settings - Fork 585
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
RJS-2680: Implement support for Mixed
data type with nested collections
#6513
RJS-2680: Implement support for Mixed
data type with nested collections
#6513
Conversation
// Collections are always treated as not equal since their | ||
// references will always be different for each access. | ||
const NOT_FOUND = -1; | ||
return NOT_FOUND; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we use a const here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean why not just return -1
? It's merely for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand you want to make clear that -1 is used when the value is not found, but for me it looks a little bit strange creating a const variable and then using it straight away in the same function. Aren't we also creating a new variable unnecessarily every time the method is called?
I think a comment would suffice in this case, or maybe move the const declaration at a class or higher level.
Just an observation though, I don't have super strong opinion on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point 🙂 In this case, this code only runs when the value to search for is a collection, and these two statements would likely just be replaced with returning -1
in the end anyway. In this context I think just having -1
(without either the variable or a comment) would not be too bad, but I think the readability increases if you do have it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me for what I can follow 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After your introduction in person, I don't have many comments.
As we don't need much update to the API documentation, I suggest that we write a larger section in CHANGELOG.md
when we are about to merge.
const isEmbedded = | ||
baseType === binding.PropertyType.Object && internal.objectSchema.tableType === binding.TableType.Embedded; | ||
toItemType(results.type) === binding.PropertyType.Object && | ||
internal.objectSchema.tableType === binding.TableType.Embedded; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
swapping the order might improve performance a bit 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment above about internal.objectSchema.tableType
throwing if we don't check for the Object property type first.
// form of Symbol singletons. This is due to not being able to construct | ||
// the actual list or dictionary in the current context. | ||
case realm::type_List: | ||
return ${this.addon.accessCtor("Symbol_for")}.call(_env, "Realm.List"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accessCtor
seems ripe for a rename. Perhaps it should be closer linked to "injectable"?
this.realm.write(() => { | ||
nestedList[0] = "primitive"; | ||
}); | ||
}).to.throw("Requested index 0 calling set() on list 'MixedClass.mixed' when empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as with the non-nested list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment.
this.realm.write(() => { | ||
list[0] = "primitive"; | ||
}); | ||
}).to.throw("Requested index 0 calling set() on list 'MixedClass.mixed' when empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm surprised this isn't allowed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where Realm.List
differs in behavior from a JS Array. The Core APIs for setting will throw if index >= size
, whereas inserting only throws for index >= size + 1
. This is the same behavior as we had before for Realm.List
.
From a JS perspective, setting a value at, say, index 5 of an empty list, we'd have to set index 0-4 to undefined
(although this would be converted to null
values).
* Fix type bundling issue * Inline functions into "create*Accessor*" functions * Refactored typeHelpers out of accessors
The max nesting level in debug in Core has been updated to be the same as for release.
…ions (#6513) * Move geospatial helper functions to related file. * Implement setting nested lists in Mixed. * Implement setting nested dictionaries in Mixed. * Implement getting nested lists in Mixed. * Implement getting nested dictionaries in Mixed. * Test creating and accessing nested lists and dicts. * Make previous flat collections tests use the new 'expect' function. * Test that max nesting level throws. * Delegate throwing when using a Set to 'mixedToBinding()'. * Implement setting nested collections on a dictionary via setter. * Test nested collections on dictionary via setter. * Minor update to names of tests. * Combine nested and flat collections tests into same suite. * Implement setting nested collections on a list via setter. * Test nested collections on list via setter. * Refactor common test logic to helper functions. * Optimize property setter for hot-path and use friendlier err msg. * Refactor test helper function to build collections of any depth. * Implement inserting nested collections on a list via 'push()'. * Test nested collections on a list via 'push()'. * Test updating dictionary entry to nested collections via setter. * Test updating nested list/dictionary item via setter. * Test removing items from collections via 'remove()'. * Test object notifications when modifying nested collections. * Group previous notification tests into one test. * Group collection notifications tests into 'List' and 'Dictionary'. * Test collection notifications when modifying nested collections. * Remove collections from test context. * Test filtering by query path on nested collections. * Align object schema property names in tests. * Test filtering with int at_type. * Implement setting nested collections on a dictionary via 'set()' overloads. * Test JS Array method 'values()'. * Test JS Array method 'entries()'. * Implement getting nested collections on dictionary 'values()' and 'entries()'. * Test 'values()' and 'entries()' on dictionary with nested collections. * Remove unnecessary 'fromBinding()' calls. * Refactor collection helpers from 'PropertyHelpers' into the respective collection file. * Introduce list/dict sentinels to circumvent extra Core access. * Rename getter to default. * Remove redundant 'snapshotGet'. * Add abstract 'get' and 'set' to 'OrderedCollection'. * Rename the collection helpers to 'accessor'. * Move tests into subsuites. * Fix 'Results.update()'. * Support nested collections in 'pop()', 'shift()', 'unshift()', 'splice()'. * Test list 'pop()'. * Test list 'shift()'. * Test list 'unshift()'. * Test list 'splice()'. * Return 'not found' for collections searched for in 'indexOf()'. * Test ordered collection 'indexOf()'. * Support list/dict sentinels in JSI. * Test references per access. * Enable skipped tests after Core bug fix. * Point to updated Core. * Fix accessor for non-Mixed top-level collection with Mixed items. * Enable and fix previously skipped test. * Update 'mixed{}'. * Update 'mixed<>'. * Remove now-invalidated test. * Remove unused injectable from Node bindgen template. * Replace if-statements with switch. * Add explicit Results and Set accessors for Mixed. * Adapt to change in Core treating missing keys as null in queries. * Rename insertion function. * Include tests of Dictionary property type with Mixed. * Test reassigning to new collection and self-assignment. * Test mixed * Update 'mixed[]'. * Test results accessor. * Update error messages. * Make accessor helpers an object field rather than spread. * Suggestions for "nested collections in mixed" (#6566) * Fix type bundling issue * Inline functions into "create*Accessor*" functions * Refactored typeHelpers out of accessors * Remove leftover 'Symbol_for' in node-wrapper template. * Test not invalidating new collection. * Remove test for max nesting level. The max nesting level in debug in Core has been updated to be the same as for release. * Remove reliance on issue-fix in certain tests. * Add key path test for object listener on mixed field. * Use '.values()' and '.entries()' in iteration. * Update comments. * Add CHANGELOG entry. --------- Co-authored-by: Kræn Hansen <[email protected]>
…ions (#6513) * Move geospatial helper functions to related file. * Implement setting nested lists in Mixed. * Implement setting nested dictionaries in Mixed. * Implement getting nested lists in Mixed. * Implement getting nested dictionaries in Mixed. * Test creating and accessing nested lists and dicts. * Make previous flat collections tests use the new 'expect' function. * Test that max nesting level throws. * Delegate throwing when using a Set to 'mixedToBinding()'. * Implement setting nested collections on a dictionary via setter. * Test nested collections on dictionary via setter. * Minor update to names of tests. * Combine nested and flat collections tests into same suite. * Implement setting nested collections on a list via setter. * Test nested collections on list via setter. * Refactor common test logic to helper functions. * Optimize property setter for hot-path and use friendlier err msg. * Refactor test helper function to build collections of any depth. * Implement inserting nested collections on a list via 'push()'. * Test nested collections on a list via 'push()'. * Test updating dictionary entry to nested collections via setter. * Test updating nested list/dictionary item via setter. * Test removing items from collections via 'remove()'. * Test object notifications when modifying nested collections. * Group previous notification tests into one test. * Group collection notifications tests into 'List' and 'Dictionary'. * Test collection notifications when modifying nested collections. * Remove collections from test context. * Test filtering by query path on nested collections. * Align object schema property names in tests. * Test filtering with int at_type. * Implement setting nested collections on a dictionary via 'set()' overloads. * Test JS Array method 'values()'. * Test JS Array method 'entries()'. * Implement getting nested collections on dictionary 'values()' and 'entries()'. * Test 'values()' and 'entries()' on dictionary with nested collections. * Remove unnecessary 'fromBinding()' calls. * Refactor collection helpers from 'PropertyHelpers' into the respective collection file. * Introduce list/dict sentinels to circumvent extra Core access. * Rename getter to default. * Remove redundant 'snapshotGet'. * Add abstract 'get' and 'set' to 'OrderedCollection'. * Rename the collection helpers to 'accessor'. * Move tests into subsuites. * Fix 'Results.update()'. * Support nested collections in 'pop()', 'shift()', 'unshift()', 'splice()'. * Test list 'pop()'. * Test list 'shift()'. * Test list 'unshift()'. * Test list 'splice()'. * Return 'not found' for collections searched for in 'indexOf()'. * Test ordered collection 'indexOf()'. * Support list/dict sentinels in JSI. * Test references per access. * Enable skipped tests after Core bug fix. * Point to updated Core. * Fix accessor for non-Mixed top-level collection with Mixed items. * Enable and fix previously skipped test. * Update 'mixed{}'. * Update 'mixed<>'. * Remove now-invalidated test. * Remove unused injectable from Node bindgen template. * Replace if-statements with switch. * Add explicit Results and Set accessors for Mixed. * Adapt to change in Core treating missing keys as null in queries. * Rename insertion function. * Include tests of Dictionary property type with Mixed. * Test reassigning to new collection and self-assignment. * Test mixed * Update 'mixed[]'. * Test results accessor. * Update error messages. * Make accessor helpers an object field rather than spread. * Suggestions for "nested collections in mixed" (#6566) * Fix type bundling issue * Inline functions into "create*Accessor*" functions * Refactored typeHelpers out of accessors * Remove leftover 'Symbol_for' in node-wrapper template. * Test not invalidating new collection. * Remove test for max nesting level. The max nesting level in debug in Core has been updated to be the same as for release. * Remove reliance on issue-fix in certain tests. * Add key path test for object listener on mixed field. * Use '.values()' and '.entries()' in iteration. * Update comments. * Add CHANGELOG entry. --------- Co-authored-by: Kræn Hansen <[email protected]>
What, How & Why?
Adds support for storing nested lists and dictionaries as the underlying value of a
Mixed
property on non-synced realms.Sets are not supported as a
Mixed
value.Review notes
"nested"
in its name.Mixed
data type realm-core#7392Test overview
Click to expand
Brief overview of usage
This closes #6344, #6345, #6245
☑️ ToDos