Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function WithRouteStore(options: RouteStoreOptions) {
return createDecorator(componentOptions => {
// Store the options passed in.
componentOptions.routeStoreOptions = {
...componentOptions.routeStoreOptions,
...options,
};
// We unshift so that this always goes first before the RouteResolver
// callback.
componentOptions.mixins = componentOptions.mixins || [];
componentOptions.mixins.unshift({
beforeRouteEnter(route, _from, next) {
const options = componentOptions.routeStoreOptions;
if (options) {
const { store, routeStoreClass, routeStoreName } = options;
store.registerModule(routeStoreName, new routeStoreClass());
export function ValidationAction(action: 'validate' | 'reset' = 'validate') {
return createDecorator((componentOptions, key) => {
const actions = mapValidationActions([action]);
if (!componentOptions.methods) {
componentOptions.methods = {};
}
let originalMethod = componentOptions.methods[key];
if (action === 'validate') {
componentOptions.methods[key] = function() {
actions[action].call(this).then((result: boolean) => {
originalMethod.call(this, result);
});
};
return;
}
function makeDecorator(alias, namespace) {
return createDecorator((componentOptions, key) => {
let ns = namespace || componentOptions.namespace;
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {};
}
const mapObject = { [key]: alias };
componentOptions[bindTo][key] =
ns !== undefined ? mapFn(ns, mapObject)[key] : mapFn(mapObject)[key];
});
}
function makeDecorator(alias, namespace) {
return createDecorator((componentOptions, key) => {
let ns = namespace || componentOptions.namespace;
if (!componentOptions.computed) {
componentOptions.computed = {};
}
componentOptions.computed[key] =
ns !== undefined ? sync(`${ns}/${key}`) : sync(`${key}`);
});
}
export function Watch(path: string, options: WatchOptions = {}) {
const { deep = false, immediate = false } = options
return createDecorator((componentOptions, handler) => {
if (typeof componentOptions.watch !== 'object') {
componentOptions.watch = Object.create(null)
}
const watch: any = 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, deep, immediate })
})
}
function makeDecorator (map: any, namespace: string | undefined) {
return createDecorator((componentOptions, key) => {
if (!componentOptions[bindTo]) {
componentOptions[bindTo] = {}
}
const mapObject = { [key]: map }
componentOptions[bindTo]![key] = namespace !== undefined
? mapFn(namespace, mapObject)[key]
: mapFn(mapObject)[key]
})
}
export function Once(event?: string): MethodDecorator {
return createDecorator((componentOptions, k) => {
const key = hyphenate(k)
if (typeof componentOptions.created !== "function") {
componentOptions.created = function() {}
}
const original = componentOptions.created
componentOptions.created = function() {
original()
if (typeof componentOptions.methods !== "undefined") {
this.$once(event || key, componentOptions.methods[k])
}
}
})
}
function Call (path) {
if (typeof path !== 'string' || arguments.length > 1) { throw new Error('Property decorators can only be used for single property access') }
return createDecorator((options, key) => {
if (!options.methods) options.methods = {}
options.methods[key] = call(path)
})
}