diff --git a/src/types/observableobject.ts b/src/types/observableobject.ts index bc483a670..6da0d66e0 100644 --- a/src/types/observableobject.ts +++ b/src/types/observableobject.ts @@ -93,7 +93,7 @@ export function defineObservablePropertyFromDescriptor( descriptor: PropertyDescriptor, defaultEnhancer: IEnhancer ) { - if (adm.values[propName]) { + if (adm.values[propName] && !isComputedValue(adm.values[propName])) { // already observable property invariant( "value" in descriptor, diff --git a/test/observables.js b/test/observables.js index 09d360161..4baffdf79 100644 --- a/test/observables.js +++ b/test/observables.js @@ -1942,3 +1942,31 @@ test("Issue 1092 - We should be able to define observable on all siblings", t => t.end() }) + +test("Issue 1121 - It should be possible to redefine a computed property", t => { + t.plan(3) + + const a = observable({ + width: 10, + get surface() { return this.width } + }) + + let observeCalls = 0 + let reactionCalls = 0 + + mobx.observe(a, "surface", v => observeCalls++) + mobx.reaction(() => a.surface, v => reactionCalls++) + + t.doesNotThrow(() => { + mobx.extendObservable(a, { + get surface() { return this.width * 2 } + }) + }, "It should be possible to redefine a computed property") + + a.width = 11 + + t.equal(observeCalls, 1) + t.equal(reactionCalls, 1) + + t.end() +})