I have:
Not following the above template might result in your issue being closed without further notice
Today a coworker was telling me that it took them a while to find a bug related to passing an instance as argument to types.optional, since as soon as a second node of the same type was created it would crash because it was attached to the first node parent.
const someDefault = TModel1.create({...})
const TModel2 = types.create({ m1: types.optional(TModel1, someDefault) })
const a = TModel2.create({}) // ok
const b = TModel2.create({}) // boom!
My question is, should that particular case be prevented?
If so, what would the best course of action?
- A. snapshot-ize the instance - mostly non-breaking, but might loose the environment (not a big deal, since anyway children and parents have to have the same environment anyway)
- B. throw an error - breaking-ish change though?
- C. (my least favorite) just show a console warning
I have:
Not following the above template might result in your issue being closed without further notice
Today a coworker was telling me that it took them a while to find a bug related to passing an instance as argument to types.optional, since as soon as a second node of the same type was created it would crash because it was attached to the first node parent.
My question is, should that particular case be prevented?
If so, what would the best course of action?