Closed swayf closed 4 years ago
if we take as example setterAction.test.ts and add line
p.y = 5
expect(p.y).toBe(5)
expect(p.$.y).toBe(5) // <-- new line
it works. but after adding computed value in the model
@model("P")
export class P extends Model({
y: prop(0, { setterAction: true }),
}) {
@modelAction
setY(n: number) {
this.y = n
}
// new computed getter
@computed
get computedValue() {
return this.y * 10;
}
}
p.y = 5
expect(p.y).toBe(5)
expect(p.$.y).toBe(5) // <-- new line does not work any more
the problem place is here:
export function internalApplySet<O extends object>(
this: O,
fieldName: string | number,
value: any
): void {
if (isObservable(this)) {
set(this, fieldName, value)
} else {
;(this as any)[fieldName] = value
}
}
set(this, fieldName, value) does not works right in this case as example, if I change it to
export function internalApplySet<O extends object>(
this: O,
fieldName: string | number,
value: any
): void {
if (isObservable(this)) {
if (isObservable((this as any).$)) {
set((this as any).$, fieldName, value)
} else {
set(this, fieldName, value)
}
}
else {
;(this as any)[fieldName] = value
}
}
the extended tests works, even with autorun and computed all old tests also. but I am not sure if it is right way to solve the problem =)
Hey, thanks for the detailed bug report! I'll release v0.43.1 with a fix soon
I have strange example
is it bug, or I use this feature in wrong way?