-
Notifications
You must be signed in to change notification settings - Fork 577
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
Added overloaded set method for dictionary #5377
Conversation
For the reviewers:
|
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.
Minor comments. Great job!
this.realm.write(() => item.dict.remove("key1").remove("key2")); | ||
|
||
expect(Object.keys(item.dict)).deep.equals([]); | ||
//expect(item.dict).deep.equals({}); //TODO Not sure why this does not work |
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 guess it's because dict
has instance methods besides the key/value pairs it might have.
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! Thanks
packages/realm/src/Dictionary.ts
Outdated
const inputObj = typeof elementOrKey == "string" ? { [elementOrKey]: value } : elementOrKey; | ||
for (const [key, val] of Object.entries(inputObj)) { | ||
internal.insertAny(key, toBinding(val, undefined)); | ||
} | ||
return 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.
Great catch .. I also found this on my other PR - let's see who gets to merge first 😄 (although it shouldn't conflict too much).
@@ -44,7 +44,7 @@ export class ObjectListeners<T> { | |||
}); | |||
} catch (err) { | |||
// Scheduling a throw on the event loop, | |||
// since throwing synchroniously here would result in an abort in the calling C++ | |||
// since throwing synchronously here would result in an abort in the calling C++ |
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.
Thanks. Strange I didn't catch these in 789a688 🤔
Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com>
Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com>
packages/realm/src/Dictionary.ts
Outdated
* @param value The value of the element to add | ||
* @throws {@link AssertionError} If not inside a write transaction or if value violates type constraints | ||
* @returns The dictionary | ||
* @since 10.6.0 //TODO Should also this be 12.0? |
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 not sure about this, also considering this is an overloaded method
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 believe it should be 10.6.0 as we introduced Realm.Dictionary
in that version
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.
Great job!
packages/realm/src/Dictionary.ts
Outdated
* @param value The value of the element to add | ||
* @throws {@link AssertionError} If not inside a write transaction or if value violates type constraints | ||
* @returns The dictionary | ||
* @since 12.0 //TODO Is this correct? |
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.
It will be 12.0.0 (or maybe 12.0.0-rc.0)
packages/realm/src/Dictionary.ts
Outdated
* @param value The value of the element to add | ||
* @throws {@link AssertionError} If not inside a write transaction or if value violates type constraints | ||
* @returns The dictionary | ||
* @since 10.6.0 //TODO Should also this be 12.0? |
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 believe it should be 10.6.0 as we introduced Realm.Dictionary
in that version
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.
Just some minor things. Otherwise LGTM!
@@ -1,7 +1,7 @@ | |||
## vNext (TBD) | |||
|
|||
### Enhancements | |||
* None | |||
* Add an overload to `Dictionary.set` method that takes two arguments, a `key` and a `value`. ([#4286](https://github.com/realm/realm-js/issues/4286)) |
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.
Could be useful to provide an example of the new syntax in the changelog for anyone reading 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.
Added an example of usage
internal.insertAny(key, toBinding(value, undefined)); | ||
const elements = typeof elementsOrKey == "string" ? { [elementsOrKey]: value } : elementsOrKey; | ||
for (const [key, val] of Object.entries(elements)) { | ||
internal.insertAny(key, toBinding(val, undefined)); |
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.
Does undefined
need to be explicitly set in toBinding
? Any argument not defined will be undefined
in its method.
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.
Makes sense. This seems to have been done mostly in this commit: e9ce475#diff-90e9134a0cbc40c4c81b2a112040ea96569d8de35ce930f7e3d2f20521a712e7, maybe it was done to make the parameter explicit?
This closes #4286
☑️ ToDos