Skip to content

Commit

Permalink
mobxjs#1121 add possibility to redefine a computed property
Browse files Browse the repository at this point in the history
  • Loading branch information
koretskiyav committed Aug 23, 2017
1 parent fb1b7d9 commit 91e2f26
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/types/observableobject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function defineObservablePropertyFromDescriptor(
descriptor: PropertyDescriptor,
defaultEnhancer: IEnhancer<any>
) {
if (adm.values[propName]) {
if (adm.values[propName] && !isComputedValue(adm.values[propName])) {
// already observable property
invariant(
"value" in descriptor,
Expand Down
28 changes: 28 additions & 0 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

0 comments on commit 91e2f26

Please sign in to comment.