Closed wangzhewudiya closed 1 year ago
That's working as expected, from/to snapshot processors are not shared across model extensions.
If you want to share them you can extract them to a shared function and call it on each model's toSnapshotOptions.
For example:
import { model, Model, prop, ExtendedModel } from "mobx-keystone"
function sharedToSnapshotProcessor(sn: WhateverSnType, modelInstance: WhateverModelInstance) {
console.log("toSnapshotProcessor")
return {
...sn,
}
}
@model("MyApp/Point")
class Point extends Model({
_version: prop(2),
x: prop<number>(),
y: prop<number>(),
}, {
toSnapshotProcessor(sn, modelInstance) {
return sharedToSnapshotProcessor(sn, modelInstance);
}, // or toSnapshotProcessor: sharedToSnapshotProcessor
}) {
get sum() {
return this.x + this.y
}
}
@model("MyApp/Point3d")
class Point3d extends ExtendedModel(Point, {
z: prop<number>(1),
}, {
toSnapshotProcessor(sn, modelInstance) {
return sharedToSnapshotProcessor(sn, modelInstance);
}, // or toSnapshotProcessor: sharedToSnapshotProcessor
}) {
get sum() {
return super.sum + this.z
}
}
ModelOptions is configured on Point, but instantiating Point3d will not execute ModelOptions. How can I make ModelOptions on Point take effect?