Applying snapshot getted by getSnapshot to union of models with different optional properties throws error:
import { types, getSnapshot, applySnapshot } from "../src"
test("apply snapshot to union should not throw when union keeps models with different properties and snapshot getted by getSnapshot", () => {
const Foo = types.model({ foo: 1 })
const Bar = types.model({ bar: 1 })
const U = types.union(Foo, Bar)
const u = U.create({ foo: 1 })
applySnapshot(u, getSnapshot(Bar.create())) // THROW error
})
When union type validates snapshot, it validates all subtypes until one of them fits to snapshot. But validation of model type can add property to snapshot if value of optional model property is absent in snapshot (is it normal?):
import { types } from "../src"
test("model creating should not change snapshot", () => {
const M = types.model({ foo: 1 })
const o = {}
M.create(o)
expect(o).toEqual({}) // o is { foo: 1 }
})
getSnapshot returns frozen object. When mst tries to add property to frozen object in validation of model it throws error Cannot add property *, object is not extensible
Applying snapshot getted by getSnapshot to union of models with different optional properties throws error:
When union type validates snapshot, it validates all subtypes until one of them fits to snapshot. But validation of model type can add property to snapshot if value of optional model property is absent in snapshot (is it normal?):
getSnapshot returns frozen object. When mst tries to add property to frozen object in validation of model it throws error
Cannot add property *, object is not extensible