-
We are seeing edge cases sometimes where @model('NoteStore')
export class NoteStore extends Model({
listView: prop<NoteListView>(() => new NoteListView({})),
}) { I'm wondering what could cause this. We do construct noteStores from snapshots, but we never include the listView in that snapshot. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 11 replies
-
I tried this and all cases seemed to work (except when $modelType was not present and it was a prop and not a tProp) https://stackblitz.com/edit/typescript-dxrdkn?file=index.ts import { model, Model, prop, fromSnapshot, tProp } from 'mobx-keystone';
console.clear();
@model('NoteListView')
class NoteListView extends Model({}) {}
@model('NoteStore')
class NoteStore extends Model({
listView: prop<NoteListView>(() => new NoteListView({})),
}) {}
{
const m = new NoteStore({});
console.log(m.listView);
const m2 = new NoteStore({ listView: undefined });
console.log(m2.listView);
const m3 = fromSnapshot<NoteStore>({ $modelType: 'NoteStore' });
console.log(m3.listView);
const m4 = fromSnapshot<NoteStore>({
$modelType: 'NoteStore',
listView: undefined,
});
console.log(m4.listView);
// this won't work because the model type is missing
const m5 = fromSnapshot<NoteStore>({});
console.log(m5.listView);
}
@model('NoteStore2')
class NoteStore2 extends Model({
listView: tProp(NoteListView, () => new NoteListView({})),
}) {}
{
const m = new NoteStore2({});
console.log(m.listView);
const m2 = new NoteStore2({ listView: undefined });
console.log(m2.listView);
const m3 = fromSnapshot(NoteStore2, { $modelType: 'NoteStore2' });
console.log(m3.listView);
const m4 = fromSnapshot(NoteStore2, {
$modelType: 'NoteStore2',
listView: undefined,
});
console.log(m4.listView);
const m5 = fromSnapshot(NoteStore2, {});
console.log(m5.listView);
} Maybe you are not passing $modelType to fromSnapshot sometimes? |
Beta Was this translation helpful? Give feedback.
-
Also seeing this |
Beta Was this translation helpful? Give feedback.
-
I've got a reproduction of the issue here: https://stackblitz.com/edit/typescript-ccdhgu?file=index.ts It seems that when using applySnapshot, if you don't pass in all the properties then they get set to undefined. |
Beta Was this translation helpful? Give feedback.
I've got a reproduction of the issue here:
https://stackblitz.com/edit/typescript-ccdhgu?file=index.ts
It seems that when using applySnapshot, if you don't pass in all the properties then they get set to undefined.