Closed sisp closed 5 years ago
If you could that'd be great, but I suspect it was introduced there too
This is the simplest case I could find that causes the error:
import { Model, model, modelAction, prop, registerRootStore } from "mobx-keystone"
// When the below line is uncommented, no error occurs.
// import { Model, model, modelAction, prop, registerRootStore } from "../src"
test("issue #27", () => {
@model("#27/ModelWithArrayProp")
class ModelWithArrayProp extends Model({
values: prop<number[]>(),
}) {
onAttachedToRootStore(): void {
this.setValues([1, 2, 3])
}
@modelAction
public setValues(values: number[]): void {
this.values = values
}
}
const m = registerRootStore(new ModelWithArrayProp({ values: [] }))
expect(m.values).toEqual([1, 2, 3])
})
Apparently, it's important that the values
prop type is not primitive (e.g. an array). I've tested this case with v0.16 and it is passing there, so something has happened since then.
Hmm, I just tried the test case and it passed
are you using mobx4 or 5?
MobX 5. Hmm, let me try it again.
Uh, you're right. I'm not sure what happened. I'll investigate.
if you want can you try https://github.com/xaviergonz/mobx-keystone/pull/28 (though it's a wild guess)
Okay, I can at least reproduce the error again. I accidentally imported the built version of mobx-keystone
(from packages/lib/dist
) instead of the source directly (e.g. ../src
). The error does not occur when using the latter.
Steps to reproduce:
yarn install
yarn run lib:build
import { ... } from 'mobx-keystone'
, so the built version from dist
will be used) somewhere in packages/lib/test
.cd packages/lib && yarn test
Are you able to reproduce it now?
Yep! really weird that it only happens with the dist version, will check it, thanks!
Yes, I'm surprised, too. Thanks a lot for looking into it!
Heh, it was a bad babel transpilation of iterators. It didn't happen in tests since those use TS to compile, but it did happen with dist since that's compiled with babel
That's nasty ... I can confirm that #29 fixes the issue.
Fix released as 0.17.2
After upgrading to v0.17, I'm getting the following error:
There's no problem with v0.16. I suspect the cause of this problem has been introduced in #24. I'm calling an action of a child model instance in some parent model's
onAttachedToRootStore
which replaces the current (empty) array ofSomeModel
instances (prop<SomeModel[]>()
) with a new array ofSomeModel
instances. I haven't had time to come up with a minimal example for reproduction. If you can't guess what might be causing this problem, I'll try to create a test case for you.