File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 1
1
import { IAsyncComputedValue , IAsyncComputedValueBase } from "vue-async-computed" ;
2
2
import { createDecorator , VueDecorator } from "vue-class-component" ;
3
+ import { DefaultComputed } from "vue/types/options" ;
3
4
4
5
export type IAsyncComputedOptions < T > = IAsyncComputedValueBase < T > ;
5
6
6
7
export default function AsyncComputed < TResult > (
7
- computedOptions ?: IAsyncComputedOptions < TResult > ) : VueDecorator {
8
+ computedOptions ?: IAsyncComputedOptions < TResult > ) : VueDecorator {
8
9
return createDecorator ( ( options , key ) => {
9
10
options . asyncComputed = options . asyncComputed || { } ;
10
11
11
- if ( options . methods === undefined ) {
12
- throw new Error ( "methods is undefined" ) ;
12
+ let method : DefaultComputed | null = null
13
+ if ( options . methods ?. [ key ] ) {
14
+ method = options . methods [ key ]
15
+ delete options . methods [ key ] ;
16
+ } else if ( options . computed ?. [ key ] ) {
17
+ method = options . computed [ key ]
18
+ delete options . computed [ key ] ;
19
+ } else {
20
+ throw new Error ( `AsyncComputed ${ key } is not a method or computed property` ) ;
13
21
}
14
22
15
- const method = options . methods [ key ] ;
16
-
17
23
options . asyncComputed [ key ] = {
18
24
get : method ,
19
25
...computedOptions ,
20
26
} as IAsyncComputedValue < TResult > ;
21
-
22
- delete options . methods [ key ] ;
23
27
} ) ;
24
28
}
You can’t perform that action at this time.
0 commit comments