File tree 4 files changed +220
-141
lines changed
4 files changed +220
-141
lines changed Original file line number Diff line number Diff line change 3
3
"version" : " 3.5.0" ,
4
4
"description" : " Async computed properties for Vue" ,
5
5
"main" : " dist/vue-async-computed.js" ,
6
- "types" : " types /index.d.ts" ,
6
+ "types" : " src /index.d.ts" ,
7
7
"files" : [
8
8
" bin/" ,
9
9
" dist/"
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import Vue, { PluginFunction } from "vue";
3
3
export interface IAsyncComputedOptions {
4
4
errorHandler ?: ( error : string | Error ) => void ;
5
5
useRawError ?: boolean ;
6
+ default ?: any ;
6
7
}
7
8
8
9
export default class AsyncComputed {
@@ -11,23 +12,9 @@ export default class AsyncComputed {
11
12
static version : string ;
12
13
}
13
14
14
- type AsyncComputedGetter < T > = ( ) => Promise < T > ;
15
- interface IAsyncComputedProperty < T > {
16
- default ?: T | ( ( ) => T ) ;
17
- get : AsyncComputedGetter < T > ;
18
- watch ?: ( ) => void ;
19
- shouldUpdate ?: ( ) => boolean ;
20
- lazy ?: boolean ;
21
- }
22
-
23
- interface IAsyncComputedProperties {
24
- [ K : string ] : AsyncComputedGetter < any > | IAsyncComputedProperty < any > ;
25
- }
26
-
27
15
declare module "vue/types/options" {
28
- // tslint:disable-next-line:interface-name
29
- interface ComponentOptions < V extends Vue > {
30
- asyncComputed ?: IAsyncComputedProperties ;
16
+ interface ComputedOptions < T > {
17
+ asynchronous ?: boolean ;
31
18
}
32
19
}
33
20
@@ -45,4 +32,4 @@ declare module "vue/types/vue" {
45
32
interface Vue {
46
33
$asyncComputed : { [ K : string ] : IASyncComputedState } ;
47
34
}
48
- }
35
+ }
Original file line number Diff line number Diff line change @@ -24,8 +24,17 @@ const AsyncComputed = {
24
24
const asyncComputed = this . $options . asyncComputed || { }
25
25
this . $asyncComputed = { }
26
26
27
+ for ( const key in this . $options . computed ) {
28
+ if ( this . $options . computed [ key ] . asynchronous ) {
29
+ asyncComputed [ key ] = this . $options . computed [ key ]
30
+ delete this . $options . computed [ key ]
31
+ }
32
+ }
33
+
27
34
if ( ! Object . keys ( asyncComputed ) . length ) return
28
35
36
+ this . $options . asyncComputed = asyncComputed
37
+
29
38
if ( ! this . $options . computed ) this . $options . computed = { }
30
39
31
40
for ( const key in asyncComputed ) {
You can’t perform that action at this time.
0 commit comments