-
Notifications
You must be signed in to change notification settings - Fork 584
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
Update ClassMap
before notifying schema change listeners
#5955
Conversation
packages/realm/src/Realm.ts
Outdated
@@ -599,7 +599,7 @@ export class Realm { | |||
public readonly syncSession: SyncSession | null; | |||
|
|||
private schemaExtras: RealmSchemaExtra = {}; | |||
private classes: ClassMap; | |||
private classes!: ClassMap; |
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 almost thinking that this drawback from deferring to a method at line 688 isn't worth it. As we don't expect to have to initialize the class map more than twice and it's not too complex, I would probably suggest duplicating and inlining it on 662 and 688 instead.
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.
You make a good point, I'll inline those calls 👍
P.S. would be nice to add something in function signatures that tells TS that a certain property will be set. Similar to asserts
or is
. That would remove the risks of having to use !
as in the above case.
See the comments in the test regarding potentially unexpected behavior.
What, How & Why?
When calling
Realm._updateSchema()
in a write transaction, the schema change listener is fired after the call into Core, but before_updateSchema()
returns (and thus before the write transaction is completed).The
ClassMap
instance on the Realm was previously updated/reinitialized in_updateSchema()
, but since the listener was fired before that, theClassMap
had not been updated in time. This PR moves that update into theschemaDidChange
callback, updating it before notifying schema change listeners.This closes #5574
☑️ ToDos