Skip to content

Commit 0e76b7b

Browse files
Merge pull request #88 from nwtgck/decorator
Add a decorator for vue-class-component
2 parents 066fc37 + 87e1ce5 commit 0e76b7b

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

Diff for: package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+3
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,8 @@
7676
"tape": "^4.12.0",
7777
"vue": "^2.5.21",
7878
"watch": "^1.0.2"
79+
},
80+
"dependencies": {
81+
"vue-class-component": "^7.1.0"
7982
}
8083
}

Diff for: src/index.js

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getGetterWithShouldUpdate,
1717
shouldNotUpdate,
1818
} from './shouldUpdate'
19+
import { createDecorator } from 'vue-class-component'
1920

2021
const prefix = '_async_computed$'
2122

@@ -178,6 +179,18 @@ function generateDefault (fn, pluginOptions) {
178179
}
179180
}
180181

182+
export function AsyncComputedProp (computedOptions) {
183+
return createDecorator((options, key) => {
184+
options.asyncComputed = options.asyncComputed || {}
185+
const method = options.methods[key]
186+
options.asyncComputed[key] = Object.assign(
187+
{ get: method },
188+
computedOptions
189+
)
190+
delete options.methods[key]
191+
})
192+
}
193+
181194
export default AsyncComputed
182195

183196
/* istanbul ignore if */

Diff for: types/index.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Vue, { PluginFunction } from "vue";
2+
import { VueDecorator } from 'vue-class-component';
23

34
export interface IAsyncComputedOptions {
45
errorHandler?: (error: string | Error) => void;
@@ -21,6 +22,10 @@ interface IAsyncComputedValue<T> {
2122
lazy?: boolean;
2223
}
2324

25+
export function AsyncComputedProp<T>(
26+
computedOptions?: IAsyncComputedValue<T>,
27+
): VueDecorator
28+
2429
interface AsyncComputedObject {
2530
[K: string]: AsyncComputedGetter<any> | IAsyncComputedValue<any>;
2631
}

0 commit comments

Comments
 (0)