-
Notifications
You must be signed in to change notification settings - Fork 431
/
util.ts
53 lines (44 loc) · 1.95 KB
/
util.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import Vue, { ComponentOptions } from 'vue'
import { VueClass, DecoratedClass } from './declarations'
export const noop = () => {}
export const hasProto = { __proto__: [] } instanceof Array
export interface VueDecorator {
// Class decorator
(Ctor: typeof Vue): void
// Property decorator
(target: Vue, key: string): void
// Parameter decorator
(target: Vue, key: string, index: number): void
}
export function createDecorator (factory: (options: ComponentOptions<Vue>, key: string, index: number) => void): VueDecorator {
return (target: Vue | typeof Vue, key?: any, index?: any) => {
const Ctor = typeof target === 'function'
? target as DecoratedClass
: target.constructor as DecoratedClass
if (!Ctor.__decorators__) {
Ctor.__decorators__ = []
}
if (typeof index !== 'number') {
index = undefined
}
Ctor.__decorators__.push(options => factory(options, key, index))
}
}
export function mixins <A> (CtorA: VueClass<A>): VueClass<A>
export function mixins <A, B> (CtorA: VueClass<A>, CtorB: VueClass<B>): VueClass<A & B>
export function mixins <A, B, C> (CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>): VueClass<A & B & C>
export function mixins <A, B, C, D> (CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>): VueClass<A & B & C & D>
export function mixins <A, B, C, D, E> (CtorA: VueClass<A>, CtorB: VueClass<B>, CtorC: VueClass<C>, CtorD: VueClass<D>, CtorE: VueClass<E>): VueClass<A & B & C & D & E>
export function mixins <T> (...Ctors: VueClass<Vue>[]): VueClass<T>
export function mixins (...Ctors: VueClass<Vue>[]): VueClass<Vue> {
return Vue.extend({ mixins: Ctors })
}
export function isPrimitive (value: any): boolean {
const type = typeof value
return value == null || (type !== "object" && type !== "function")
}
export function warn (message: string): void {
if (typeof console !== 'undefined') {
console.warn('[vue-class-component] ' + message)
}
}