-
Notifications
You must be signed in to change notification settings - Fork 561
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
Refactor useObject #5208
Refactor useObject #5208
Conversation
* Prime any list properties with an cachedCollection so that updates fire correctly (Fixes #5185) * Primary Keys as non-primative values would reset the cached objects, since their reference always changes * Create a listener on the collection if the object doesn't exist, and rerender when it is created (Fixes #4514)
ac6b264
to
b5d36a0
Compare
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.
Very interesting PR :) LGTM
const listCaches = new Map(); | ||
const listTearDowns: Array<() => void> = []; | ||
// If the object doesn't exist, just return it with an noop tearDown | ||
if (object === null) { | ||
return { object, tearDown: () => undefined }; | ||
} | ||
|
||
// Create a cache for any Realm.List properties on the object | ||
object.keys().forEach((key) => { |
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.
Not sure how significant it would be in this particular case, but for of
loops are usually a lot faster than forEach
. So I assume in this case it would depend on how many times the function will be called and the number of keys on the object.
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 agree - I would opt for a for-of loop over the forEach
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.
done 👍🏼 thanks!
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.
Agree with LJ's comments but beyond those LGTM!
const listCaches = new Map(); | ||
const listTearDowns: Array<() => void> = []; | ||
// If the object doesn't exist, just return it with an noop tearDown | ||
if (object === null) { | ||
return { object, tearDown: () => undefined }; | ||
} | ||
|
||
// Create a cache for any Realm.List properties on the object | ||
object.keys().forEach((key) => { |
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 agree - I would opt for a for-of loop over the forEach
here.
Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com> Co-authored-by: Kræn Hansen <kraen.hansen@mongodb.com>
I've gotten all the PR changes. Unless someone yells, I'll get this merged sometime tomorrow. |
What, How & Why?
This closes #5185 and #4514
☑️ ToDos
Compatibility
label is updated or copied from previous entryCOMPATIBILITY.md
package.json
s (if updating internal packages)Breaking
label has been applied or is not necessaryIf this PR adds or changes public API's: