import { createDecorator } from 'vue-class-component';
|
/**
|
* decorator of a watch function
|
* @param path the path or the expression to observe
|
* @param WatchOption
|
* @return MethodDecorator
|
*/
|
export function Watch(path, options) {
|
if (options === void 0) { options = {}; }
|
var _a = options.deep, deep = _a === void 0 ? false : _a, _b = options.immediate, immediate = _b === void 0 ? false : _b;
|
return createDecorator(function (componentOptions, handler) {
|
if (typeof componentOptions.watch !== 'object') {
|
componentOptions.watch = Object.create(null);
|
}
|
var watch = componentOptions.watch;
|
if (typeof watch[path] === 'object' && !Array.isArray(watch[path])) {
|
watch[path] = [watch[path]];
|
}
|
else if (typeof watch[path] === 'undefined') {
|
watch[path] = [];
|
}
|
watch[path].push({ handler: handler, deep: deep, immediate: immediate });
|
});
|
}
|