Skip to content

Commit

Permalink
Merge pull request #1151 from koretskiyav/Issue_1121_-_redefine_compu…
Browse files Browse the repository at this point in the history
…ted_property

#1121 add possibility to redefine a computed property #GoodnessSquadKyiv
  • Loading branch information
mweststrate authored Sep 18, 2017
2 parents 016b75f + ac3d71f commit 70cd11b
Show file tree
Hide file tree
Showing 2 changed files with 30 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
29 changes: 29 additions & 0 deletions test/observables.js
Original file line number Diff line number Diff line change
Expand Up @@ -1942,3 +1942,32 @@ 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(4)

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.equal(a.surface, 22)

t.end()
})

0 comments on commit 70cd11b

Please sign in to comment.