Skip to content

Commit

Permalink
fix(computed): support arrow function usage for computed option
Browse files Browse the repository at this point in the history
fix #733
  • Loading branch information
yyx990803 committed Feb 18, 2020
1 parent 9571ede commit 2fb7a63
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/reactivity/src/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface WritableComputedRef<T> extends Ref<T> {
readonly effect: ReactiveEffect<T>
}

export type ComputedGetter<T> = () => T
export type ComputedGetter<T> = (ctx?: any) => T
export type ComputedSetter<T> = (v: T) => void

export interface WritableComputedOptions<T> {
Expand Down
4 changes: 1 addition & 3 deletions packages/runtime-core/__tests__/apiOptions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ describe('api: options', () => {
bar(): number {
return this.foo + 1
},
baz(): number {
return this.bar + 1
}
baz: (vm): number => vm.bar + 1
},
render() {
return h(
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/apiOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ export function applyOptions(
__DEV__ && checkDuplicateProperties!(OptionTypes.COMPUTED, key)

if (isFunction(opt)) {
renderContext[key] = computed(opt.bind(ctx))
renderContext[key] = computed(opt.bind(ctx, ctx))
} else {
const { get, set } = opt
if (isFunction(get)) {
renderContext[key] = computed({
get: get.bind(ctx),
get: get.bind(ctx, ctx),
set: isFunction(set)
? set.bind(ctx)
: __DEV__
Expand Down

0 comments on commit 2fb7a63

Please sign in to comment.