Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inheritance should work with computed #3950

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/mobx/__tests__/decorators_20223/stage3-decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,3 +1115,22 @@ test(`decorated field can be inherited, but doesn't inherite the effect of decor
const subStore = new SubStore()
expect(isAction(subStore.action)).toBe(false)
})

test(`inheritance should work with computed`, () => {
class Store {
@computed
get getNumber() {
return 1
}
}

class SubStore extends Store {
@computed
override get getNumber() {
return super.getNumber + 1
}
}

const store = new SubStore()
expect(store.getNumber).toBe(2)
})
6 changes: 4 additions & 2 deletions packages/mobx/src/types/computedannotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ function decorate_20223_(this: Annotation, get, context: ClassGetterDecoratorCon
options.name ||= __DEV__
? `${adm.name_}.${key.toString()}`
: `ObservableObject.${key.toString()}`
adm.values_.set(key, new ComputedValue(options))
const computedValue = new ComputedValue(options)
adm.values_.set(key, computedValue)
adm.values_.set(get, computedValue)
})

return function () {
return this[$mobx].getObservablePropValue_(key)
return this[$mobx].getObservablePropValue_(get)
}
}

Expand Down