-
Couldn't load subscription status.
- Fork 25
Open
Description
Trying to access any properties from the modelInstance in the toSnapshotProcessor fails with the following error:
Uncaught TypeError: Cannot read properties of undefined (reading 'id')
at BaseModel.id (sharedInternalModel.ts:36:19)
at get idAndText (field.ts:56:20)
at toSnapshotProcessor (field.ts:50:43)
at Array.toSnapshotProcessor (sharedInternalModel.ts:323:12)
at chainedFn (chainFns.ts:11:25)
at transformFn (tweakPlainObject.ts:116:29)
at internal.ts:81:44
at executeAction (action.ts:70:19)
at setNewInternalSnapshot (action.ts:50:16)
at tweakPlainObject (tweakPlainObject.ts:120:3)
It looks like the model isn't finalized and modelInstance.$ is still undefined when the model is snapshotted?
Minimal reproduction:
@model("todoSample/Todo")
export class Todo extends Model(
{
id: idProp,
text: tProp(types.string),
},
{
toSnapshotProcessor(sn, modelInstance) {
return { ...sn, idAndText: modelInstance.idAndText };
},
},
) {
@computed
get idAndText() {
return `${this.id} - ${this.text}`;
}
@modelAction
setText(text: string) {
this.text = text;
}
}
const todo = new Todo({ text: "Hello" });
// Never able to make it here:
const output = getSnapshot(todo);Metadata
Metadata
Assignees
Labels
No labels