Options
All
  • Public
  • Public/Protected
  • All
Menu

@rocketbase/vue-extra-decorators

Index

Type aliases

AfterFunction

AfterFunction<T>: (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }) => any

Type parameters

  • T: TFunction

Type declaration

    • (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }): any
    • Parameters

      • this: ThisParameterType<T>
      • params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }
        • args: Parameters<T>
        • context: ThisParameterType<T>
        • result: ReturnType<T>

      Returns any

BeforeFunction

BeforeFunction<T>: (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T> }) => any

Type parameters

  • T: TFunction

Type declaration

    • (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T> }): any
    • Parameters

      • this: ThisParameterType<T>
      • params: { args: Parameters<T>; context: ThisParameterType<T> }
        • args: Parameters<T>
        • context: ThisParameterType<T>

      Returns any

ParamsTransformFunction

ParamsTransformFunction<T>: (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T> }) => any[]

Type parameters

  • T: TFunction

Type declaration

    • (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T> }): any[]
    • Parameters

      • this: ThisParameterType<T>
      • params: { args: Parameters<T>; context: ThisParameterType<T> }
        • args: Parameters<T>
        • context: ThisParameterType<T>

      Returns any[]

PropOpts

PropOpts<T>: Constructor<T> | Constructor<any>[] | RecordPropOpts<T>

Parameters of the {@link Prop | @Prop} decorator and its flavors

Type parameters

  • T

ResultTransformFunction

ResultTransformFunction<T>: (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }) => any

Type parameters

  • T: TFunction

Type declaration

    • (this: ThisParameterType<T>, params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }): any
    • Parameters

      • this: ThisParameterType<T>
      • params: { args: Parameters<T>; context: ThisParameterType<T>; result: ReturnType<T> }
        • args: Parameters<T>
        • context: ThisParameterType<T>
        • result: ReturnType<T>

      Returns any

RouteConfig

RouteConfig: { meta?: any; name?: undefined | string; path?: undefined | string } & any

Configuration for a route, stripped down version of the actial config used in "vue-router".

remarks

All options valid in the route config of vue-router except component are allowed and working.

RouteParam RouteQuery RouteName

Snowflake

Snowflake: string & { snowflake: never }

A unique ID generated from the current time, an incrementing counter and some random elements.

WrapperFunction

WrapperFunction<T, THIS>: TFunction<ReturnType<T>, [{ args: Parameters<T>; orig: T }], THIS>

Type parameters

  • T: TFunction

  • THIS: ThisParameterType<T>

Variables

Const Bus

Const snowflake

snowflake: SnowflakeFactory

A generator for {@link Snowflake | Snowflakes}

Decorator Functions

BProp

  • BProp(opts?: PropOpts<boolean>): TypedPropertyDecorator<boolean>
  • Declares a Vue property. Boolean flavor of {@link Prop | @Prop} decorator

    remarks

    There are various preconfigured flavors of this decorator for different types already available: SProp NProp DProp BProp

    example
      @BProp()                  private simpleFlag!: boolean;
      @BProp({default: null})   private defaultsToNull!: null | boolean;
      @BProp({default: false})  private defaultsToFalse!: boolean;
      @BProp({model: "change"}) private modelValue!: boolean;

    SProp NProp DProp BProp Prop

    Parameters

    • Optional opts: PropOpts<boolean>

      The property options to pass to vue, it can either be a constructor function like String or Number, an array of constructor functions or a property object RecordPropOpts. If a property object is given, in addition to the normal vue options some additional values can be provided.

    Returns TypedPropertyDecorator<boolean>

Blocking

  • Blocking(id?: undefined | string): TypedPropertyDecorator<AnyFunction>
  • Blocking(opts?: undefined | { global?: undefined | false | true; id?: undefined | string; parallel?: undefined | false | true }): TypedPropertyDecorator<AnyFunction>
  • Marks a function as blocking, setting a BusyState while in execution and automatically blocking other functions marked with {@Blocking}, supports both synchronous and asynchronous processes.

    remarks

    Calling this method with an options object allows for parallel execution of otherwise conflicting processes. It also allows for global / shared processes. The corresponding busy state, in case of parallel execution, will only be false if ALL started processes have finished.

    example
    @Component({})
    export default class FooBar extends Vue {
      @BusyState() private busy!: boolean;
      @Blocking()
      private async saveFoo() {
        // ... Implementation
      }
      @Blocking()
      private async resetFoo() {
        // ... Implementation
      }
    }

    BusyState

    Parameters

    • Optional id: undefined | string

      The id of the blocking process, if there are multiple non-conflicting processes.

    Returns TypedPropertyDecorator<AnyFunction>

  • Parameters

    • Optional opts: undefined | { global?: undefined | false | true; id?: undefined | string; parallel?: undefined | false | true }

    Returns TypedPropertyDecorator<AnyFunction>

BusyState

  • BusyState(id?: undefined | string): TypedPropertyDecorator
  • BusyState(opts?: undefined | { global?: undefined | true; id?: undefined | string }): TypedPropertyDecorator
  • Binds a busy state used by Blocking methods to a vue reactive variable.

    remarks

    Calling this method with an options object allows for global / shared processes. The busy state, in case of parallel execution, will only be false if ALL started processes have finished.

    example
    @Component({ template: `<div><span v-if="busy">Loading...</span></div>` })
    export default class FooBar extends Vue {
      @BusyState() private busy!: boolean;
      @Blocking()
      private async saveFoo() {
        // ... Implementation
      }
      @Blocking()
      private async resetFoo() {
        // ... Implementation
      }
    }

    Blocking

    Parameters

    • Optional id: undefined | string

      The identifier of a block state, if multiple exist.

    Returns TypedPropertyDecorator

  • Parameters

    • Optional opts: undefined | { global?: undefined | true; id?: undefined | string }

    Returns TypedPropertyDecorator

Classes

  • Classes(prefix?: undefined | string, infix?: undefined | string, converter?: TFunction<string, [string | [string, string], boolean]>): <T>(target: any, key: string, desc: CalculatedPropertyDescriptor<any>) => void
  • Prefixes a css classes getter keys with a given prefix and adds a css class to its body. supports transforming object keys for conventional class names.

    remarks

    This Decorator should be used on class getters. There are various favors of this decorator preconfigured for certain styles: ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    example
    const lower = (str: string) => str.toLowerCase();
    @Component({ template: `<div :class="classes">Hello World</div>` })
    class MyVueComponent extends Vue {
      @Classes("my-prefix", "--", composeConverter(lower, lower))
      private get classes() {
        return {
          alignLeft: true,
          alignRight: false,
          direction: "left"
        }
      }
    }

    Renders:

    <div class="my-prefix my-prefix--alignleft my-prefix--directionleft">Hello World</div>

    ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    Parameters

    • Optional prefix: undefined | string

      The class prefix to prefix object keys with. If none is given, it will default to the converted class name.

    • Optional infix: undefined | string

      The infix to insert between prefix and key. By default this will be an empty string.

    • Optional converter: TFunction<string, [string | [string, string], boolean]>

      The converter used to convert object keys with. By default it does nothing.

    Returns <T>(target: any, key: string, desc: CalculatedPropertyDescriptor<any>) => void

      • <T>(target: any, key: string, desc: CalculatedPropertyDescriptor<any>): void
      • Type parameters

        • T

        Parameters

        • target: any
        • key: string
        • desc: CalculatedPropertyDescriptor<any>

        Returns void

ClassesCamel

  • ClassesCamel(prefix?: undefined | string, infix?: undefined | string): ReturnType<typeof Classes>
  • Camel case specific flavor of Classes decorator. Prefixes a css classes getter keys with a given prefix and adds a css class to its body. transforms the class name to camelCase and all members to PascalCase.

    remarks

    This Decorator should be used on class getters. There are various favors of this decorator preconfigured for certain styles: ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    example
    @Component({ template: `<div :class="classes">Hello World</div>` })
    class MyVueComponent extends Vue {
      @ClassesCamel()
      private get classes() {
        return {
          alignLeft: true,
          alignRight: false,
          direction: "left"
        }
      }
    }

    Renders:

    <div class="myVueComponent myVueComponentAlignLeft myVueComponentDirectionLeft">Hello World</div>

    Classes ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    Parameters

    • Optional prefix: undefined | string

      The class prefix to prefix object keys with. If none is given, it will default to the converted class name.

    • Optional infix: undefined | string

      The infix to insert between prefix and key. By default this will be an empty string.

    Returns ReturnType<typeof Classes>

ClassesKebap

  • ClassesKebap(prefix?: undefined | string, infix?: undefined | string): ReturnType<typeof Classes>
  • Kebap case specific flavor of Classes decorator. Prefixes a css classes getter keys with a given prefix and adds a css class to its body. transforms the class name and all members to kebap-case.

    remarks

    This Decorator should be used on class getters. There are various favors of this decorator preconfigured for certain styles: ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    example
    @Component({ template: `<div :class="classes">Hello World</div>` })
    class MyVueComponent extends Vue {
      @ClassesKebap()
      private get classes() {
        return {
          alignLeft: true,
          alignRight: false,
          direction: "left"
        }
      }
    }

    Renders:

    <div class="my-vue-component my-vue-component--align-left my-vue-component--direction-left">Hello World</div>

    Classes ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    Parameters

    • Optional prefix: undefined | string

      The class prefix to prefix object keys with. If none is given, it will default to the converted class name.

    • Optional infix: undefined | string

      The infix to insert between prefix and key. By default this will be two dashes (--).

    Returns ReturnType<typeof Classes>

ClassesPascal

  • ClassesPascal(prefix?: undefined | string, infix?: undefined | string): ReturnType<typeof Classes>
  • Pascal case specific flavor of Classes decorator. Prefixes a css classes getter keys with a given prefix and adds a css class to its body. transforms the class name and all members to PascalCase.

    remarks

    This Decorator should be used on class getters. There are various favors of this decorator preconfigured for certain styles: ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    example
    @Component({ template: `<div :class="classes">Hello World</div>` })
    class MyVueComponent extends Vue {
      @ClassesPascal()
      private get classes() {
        return {
          alignLeft: true,
          alignRight: false,
          direction: "left"
        }
      }
    }

    Renders:

    <div class="MyVueComponent MyVueComponentAlignLeft MyVueComponentDirectionLeft">Hello World</div>

    Classes ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    Parameters

    • Optional prefix: undefined | string

      The class prefix to prefix object keys with. If none is given, it will default to the converted class name.

    • Optional infix: undefined | string

      The infix to insert between prefix and key. By default this will be an empty string.

    Returns ReturnType<typeof Classes>

ClassesSnake

  • ClassesSnake(prefix?: undefined | string, infix?: undefined | string): ReturnType<typeof Classes>
  • Snake case specific flavor of Classes decorator. Prefixes a css classes getter keys with a given prefix and adds a css class to its body. transforms the class name and all members to snake_case.

    remarks

    This Decorator should be used on class getters. There are various favors of this decorator preconfigured for certain styles: ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    example
    @Component({ template: `<div :class="classes">Hello World</div>` })
    class MyVueComponent extends Vue {
      @ClassesSnake()
      private get classes() {
        return {
          alignLeft: true,
          alignRight: false,
          direction: "left"
        }
      }
    }

    Renders:

    <div class="my_vue_component my_vue_component--align_left my_vue_component--direction_left">Hello World</div>

    Classes ClassesCamel ClassesKebap ClassesPascal ClassesSnake

    Parameters

    • Optional prefix: undefined | string

      The class prefix to prefix object keys with. If none is given, it will default to the converted class name.

    • Optional infix: undefined | string

      The infix to insert between prefix and key. By default this will be two dashes (--).

    Returns ReturnType<typeof Classes>

DProp

  • DProp(opts?: PropOpts<Date>): TypedPropertyDecorator<Date>
  • Declares a Vue property. Date flavor of {@link Prop | @Prop} decorator

    remarks

    There are various preconfigured flavors of this decorator for different types already available: SProp NProp DProp BProp

    example
      @DProp()                            private simpleDate!: Date;
      @DProp({default: null})             private defaultsToNull!: null | Date;
      @DProp({default: () => new Date()}) private defaultsToNow!: Date;
      @DProp({model: "change"})           private modelValue!: Date;

    SProp NProp DProp BProp Prop

    Parameters

    • Optional opts: PropOpts<Date>

      The property options to pass to vue, it can either be a constructor function like String or Number, an array of constructor functions or a property object RecordPropOpts. If a property object is given, in addition to the normal vue options some additional values can be provided.

    Returns TypedPropertyDecorator<Date>

DWatch

  • DWatch(property: string): TypedPropertyDecorator<AnyFunction>
  • Watch a property for changes, deeply

    remarks

    This decorator is synonymous to using Watch with deep set to true. There are also flavors for these uses: Watch, IWatch, IDWatch

    example
    @Data({ default: {} }) private value!: any;
    @DWatch("value")
    private onValueChange(newValue: any, oldValue: any) {
      // ...Implementation
    }

    Watch, IWatch, DWatch, IDWatch

    Parameters

    • property: string

      The property to watch

    Returns TypedPropertyDecorator<AnyFunction>

Data

  • Data<T>(opts?: DataOpts<T>): TypedPropertyDecorator<T>
  • Declares a Vue data property.

    remarks

    There are various preconfigured flavors of this decorator for different types already available:

    example
      @Data()                    private defaultsToNull!: string | null;
      @Data({default: 0})        private numberWithDefault!: number;
      @Data({literal: parseInt}) private parser!: (str: string) => number;
      @Data({sync: "value"})     private syncsWithPropertyValue!: string;
      @SProp({default: ""})      private value!: string;

    SProp NProp DProp BProp Prop

    Type parameters

    • T

    Parameters

    • Optional opts: DataOpts<T>

      The data property options.

    Returns TypedPropertyDecorator<T>

Debounce

  • Debounce(ms?: undefined | number): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>
  • Debounce function calls by a specified amount of time The function will only be executed ms milliseconds after the last invocation. If it is invoked again within this timeframe, the timeframe is reset. Useful for search completion.

    remarks

    If you want calls to execute the function immediately, then block subsequent calls until a specific time is over, use Debuffer instead.

    example
      @Debounce(1000)
      onSearchLiveChange(ev: Event) {
        // Only ever executed every 1000 ms, 1000 ms after last invocation
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Parameters

    • Optional ms: undefined | number

      The amount of milliseconds to debounce it by

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): TypedPropertyDescriptor<TFunction<any, any[], any>>
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns TypedPropertyDescriptor<TFunction<any, any[], any>>

Debuffer

  • Debuffer(ms?: undefined | number): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>
  • Debuffer function calls by a specified amount of time The function will only be executed every ms milliseconds Every call within this timeframe are blocked and the timeframe reset. Useful for possible multiple event triggersn.

    remarks

    If you want calls to execute the function after the specified time block subsequent calls, use Debounce instead.

    example
      @Debuffer(1000)
      onSearchLiveChange(ev: Event) {
        // Only ever executed every 1000 ms, immediately after first invocation
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Parameters

    • Optional ms: undefined | number

      The amount of milliseconds to debuffer it by

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): TypedPropertyDescriptor<TFunction<any, any[], any>>
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns TypedPropertyDescriptor<TFunction<any, any[], any>>

Delay

  • Delay(ms?: undefined | number): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void
  • Delay function calls by a specified amount of time.

    remarks

    If you want to delay by one ms, a browser frame or a vue tick, look into NextMs, NextFrame or NextTick instead.

    example
      @Delay(500)
      delayed() {
        // Executed 500 ms after invocation
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Parameters

    • Optional ms: undefined | number

      The milliseconds to delay calls by.

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns void

DocumentEl

  • DocumentEl(selector?: undefined | string, multiple?: undefined | false | true): TypedPropertyDecorator<any, any, string | number | symbol>
  • Creates a computed property for {@link Document#querySelector} or {@link Document#querySelectorAll}

    remarks

    Preferably use Ref

    example
    <html><body><div id="foo"></div></body></html>
    @Component({})
    export default class FooBar extends Vue {
      @DocumentEl("#foo") private foo!: HTMLDivElement;
    }

    El DocumentEl ParentEl

    Parameters

    • Optional selector: undefined | string

      The css selector to pass to {@link Document#querySelector} or {@link Document#querySelectorAll}

    • Optional multiple: undefined | false | true

      If {@link Document#querySelectorAll} should be used

    Returns TypedPropertyDecorator<any, any, string | number | symbol>

El

  • El(selector?: undefined | string, multiple?: undefined | false | true): TypedPropertyDecorator<any, any, string | number | symbol>
  • Creates a computed property for {@link Vue#$el#querySelector | this.$el.querySelector} or {@link Vue#$el#querySelectorAll | this.$el.querySelectorAll}

    remarks

    Preferably use Ref

    example
    @Component({ template: `<div><div id="foo"></div></div>` })
    export default class FooBar extends Vue {
      @El("#foo") private foo!: HTMLDivElement;
    }

    El DocumentEl ParentEl

    Parameters

    • Optional selector: undefined | string

      The css selector to pass to {@link Vue#$el#querySelector | this.$el.querySelector} or {@link Vue#$el#querySelectorAll | this.$el.querySelectorAll}

    • Optional multiple: undefined | false | true

      If {@link Vue#$el#querySelectorAll | this.$el.querySelectorAll} should be used

    Returns TypedPropertyDecorator<any, any, string | number | symbol>

Emit

  • Emit(event?: undefined | string): (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>) => void
  • Emits a given vue event after execution with the return value being the event parameter.

    remarks

    If a promise is returned, it will trigger the event after the promise has completed successfully. Will never emit on error, use EmitError instead.

    example
    @Component({})
    export default class FooBar extends Vue {
      @Emit("save-success")
      private async saveFooBar() {
        // ... Implementation
        return { foobar: {} };
      }
    }

    Emit EmitError EmitOnStatusCode

    Parameters

    • Optional event: undefined | string

      The name of the event to trigger, defaults to the method name

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>

        Returns void

EmitError

  • EmitError(event?: undefined | string, rethrow?: undefined | false | true): (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>) => void
  • Emits a given vue event after failed execution with the error being the event parameter.

    remarks

    If a promise is returned, it will trigger the event after the promise was rejected. Will never emit on success, use Emit instead.

    example
    @Component({})
    export default class FooBar extends Vue {
      @EmitError("save-failure")
      private async saveFooBar() {
        // ... Implementation
        throw new Error("Error trying to save foobar");
      }
    }

    Emit EmitError EmitOnStatusCode

    Parameters

    • Optional event: undefined | string

      The name of the event to trigger, defaults to error:METHODNAME where METHODNAME is the name of the decorated method.

    • Optional rethrow: undefined | false | true

      If the error should be re-thrown after emitting the event

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<FunctionWithContext<Vue>>

        Returns void

EmitOnStatusCode

  • EmitOnStatusCode(code?: undefined | number, event?: undefined | string, rethrow?: undefined | false | true): TypedPropertyDecorator<FunctionWithContext<Vue>>
  • EmitOnStatusCode(codes?: number[], event?: undefined | string, rethrow?: undefined | false | true): TypedPropertyDecorator<FunctionWithContext<Vue>>
  • Emits a given vue event after the execution of the decorated method, if a status code can be extracted from its return value or error.

    remarks

    If a promise is returned, it will trigger the event after the promise was rejected or resolved.

    example
    @Component({})
    export default class FooBar extends Vue {
      @EmitOnStatusCode(200, "success")
      @EmitOnStatusCode([400, 500], "failure")
      private async saveFooBar() {
        // ... Implementation
        return axios.get("/foo/bar");
      }
    }

    Emit EmitError EmitOnStatusCode

    Parameters

    • Optional code: undefined | number

      The status code to match, if none is given, it will emit on every status code

    • Optional event: undefined | string

      The name of the event to trigger, defaults to status:STATUSCODE where STATUSCODE is the status code extracted from the return value or error of the decorated method.

    • Optional rethrow: undefined | false | true

      If the error should be re-thrown after emitting the event

    Returns TypedPropertyDecorator<FunctionWithContext<Vue>>

  • Parameters

    • Optional codes: number[]
    • Optional event: undefined | string
    • Optional rethrow: undefined | false | true

    Returns TypedPropertyDecorator<FunctionWithContext<Vue>>

Every

  • Every(ms?: undefined | number): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => any
  • Calls a function every ms milliseconds.

    remarks

    If you want to execute on every animation frame, use EveryFrame instead.

    example
      @Every(1000)
      updateCountdown() {
        // Executed every 1000 ms
        this.date = new Date();
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Parameters

    • Optional ms: undefined | number

      The milliseconds between executions

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => any

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): any
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns any

EveryFrame

  • EveryFrame(): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => any
  • Calls a function every animation frame.

    remarks

    If you want to execute in a specific interval, use Every instead.

    example
      @EveryFrame()
      render() {
        // on every animation frame
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => any

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): any
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns any

IDWatch

  • IDWatch(property: string): TypedPropertyDecorator<AnyFunction>
  • Watch a property for changes, deeply and immediately

    remarks

    This decorator is synonymous to using Watch with deep and immediate set to true. There are also flavors for these uses: Watch, IWatch, DWatch

    example
    @Data({ default: {} }) private value!: any;
    @IDWatch("value")
    private onValueChange(newValue: any, oldValue: any) {
      // ...Implementation
    }

    Watch, IWatch, DWatch, IDWatch

    Parameters

    • property: string

      The property to watch

    Returns TypedPropertyDecorator<AnyFunction>

IWatch

  • IWatch(property: string): TypedPropertyDecorator<AnyFunction>
  • Watch a property for changes, immediately

    remarks

    This decorator is synonymous to using Watch with immediate set to true. There are also flavors for these uses: Watch, DWatch, IDWatch

    example
    @Data({ default: "" }) private value!: string;
    @IWatch("value")
    private onValueChange(newValue: string, oldValue: string) {
      // ...Implementation
    }

    Watch, IWatch, DWatch, IDWatch

    Parameters

    • property: string

      The property to watch

    Returns TypedPropertyDecorator<AnyFunction>

If

  • If(...fns: TFunction<boolean>[]): (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>) => void
  • Wraps a function and only calls through if a given set of predicates return truthy

    remarks
    example
      @If(wasPrevented)
      private doSomething(ev: Event) {
        // only executed if wasPrevented returns true
      }

    IfNot or and not

    Parameters

    • Rest ...fns: TFunction<boolean>[]

      The predicates to check before executing the decorated function

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<TFunction>

        Returns void

IfNot

  • IfNot(...fns: TFunction<boolean>[]): (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>) => void
  • Wraps a function and only calls through if a given set of predicates return falsy

    remarks
    example
      @IfNot(wasPrevented)
      private doSomething(ev: Event) {
        // only executed if wasPrevented returns false
      }

    If or and not

    Parameters

    • Rest ...fns: TFunction<boolean>[]

      The predicates to check before executing the decorated function

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<TFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<TFunction>

        Returns void

LimitToFrames

  • LimitToFrames(): (target: any, propertyKey: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>
  • Limit function calls to browser frames. Useful for animations. Every subsequent call before the next frame is blocked.

    remarks

    If you want specific time frames, look at Debounce or Debuffer instead.

    example
      @LimitToFrame()
      render() {
        // Only executed on every frame at max
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Returns (target: any, propertyKey: string, desc: TypedPropertyDescriptor<AnyFunction>) => TypedPropertyDescriptor<TFunction<any, any[], any>>

      • (target: any, propertyKey: string, desc: TypedPropertyDescriptor<AnyFunction>): TypedPropertyDescriptor<TFunction<any, any[], any>>
      • Parameters

        • target: any
        • propertyKey: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns TypedPropertyDescriptor<TFunction<any, any[], any>>

NProp

  • NProp(opts?: PropOpts<number>): TypedPropertyDecorator<number>
  • Declares a Vue property. Number flavor of {@link Prop | @Prop} decorator

    remarks

    There are various preconfigured flavors of this decorator for different types already available: SProp NProp DProp BProp

    example
      @NProp()                       private simpleNumber!: number;
      @NProp({default: null})        private defaultsToNull!: null | number;
      @NProp({default: Math.random}) private defaultsToRandom!: number;
      @NProp({model: "change"})      private modelValue!: number;

    SProp NProp DProp BProp Prop

    Parameters

    • Optional opts: PropOpts<number>

      The property options to pass to vue, it can either be a constructor function like String or Number, an array of constructor functions or a property object RecordPropOpts. If a property object is given, in addition to the normal vue options some additional values can be provided.

    Returns TypedPropertyDecorator<number>

NextFrame

  • NextFrame(): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void
  • Delay function calls by a single browser frame.

    remarks

    If you want to delay by one ms, a specific time or a vue tick, look into NextMs, Delay or NextTick instead.

    example
      @NextFrame(500)
      delayed() {
        // Executed on next animation frame
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns void

NextMs

  • NextMs(): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void
  • Delay function calls by a millisecond.

    remarks

    If you want to delay by a specific amout of time, a browser frame or a vue tick, look into Delay, NextFrame or NextTick instead.

    example
      @NextMs
      delayed() {
        // Executed 1 ms after invocation
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns void

NextTick

  • NextTick(): (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void
  • Delay function calls by a vue tick using this.$nextTick.

    remarks

    If you want to delay by one ms, a browser frame or a specific amout of time, look into NextMs, NextFrame or Delay instead.

    example
      @NextTick
      delayed() {
        // Executed on this.$nextTick
      }

    Call limiting decorators: Debounce Debuffer LimitToFrames

    Delaying decorators: Delay NextFrame NextTick NextMs

    Interval decorators: Every EveryFrame

    Returns (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>) => void

      • (target: any, key: string, desc: TypedPropertyDescriptor<AnyFunction>): void
      • Parameters

        • target: any
        • key: string
        • desc: TypedPropertyDescriptor<AnyFunction>

        Returns void

On

  • On(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a vue event listener. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    This decorator doesn't work for dom events, only for vue events. If you want to attach to dom events, use OnElement instead.

    example
      @On("toggle-fade")
      private onToggleFade() {
        // Called when this.$emit("toggle-fade") is called
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

OnDocument

  • OnDocument(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a dom event listener for the document object. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    If you want to attach to window, use OnWindow instead.

    example
      @OnDocument("click")
      private onToggleFade(ev: MouseEvent) {
        // Called when document is clicked
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

OnElement

  • OnElement(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a dom event listener. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    This decorator doesn't work for dom events, only for dom events. If you want to attach to vue events, use On instead.

    example
      @OnElement("click")
      private onToggleFade(ev: MouseEvent) {
        // Called when this.$el is clicked
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

OnParent

  • OnParent(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a vue event listener of the parent vue component. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    This decorator doesn't work for dom events, only for vue events. If you want to attach to dom events, use OnParentElement instead.

    example
      @OnParent("toggle-fade")
      private onToggleFade() {
        // Called when this.$parent.$emit("toggle-fade") is called
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

OnParentElement

  • OnParentElement(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a dom event listener for the parent vue component. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    This decorator doesn't work for dom events, only for dom events. If you want to attach to vue events, use OnParent instead.

    example
      @OnParentElement("click")
      private onToggleFade(ev: MouseEvent) {
        // Called when this.$parent.$el is clicked
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

OnWindow

  • OnWindow(...events: string[]): TypedPropertyDecorator<AnyFunction>
  • Registers the decorated method as a dom event listener for the window object. if more than one event is given, it will listen for multiple events All event parameters are passed as arguments to the decorated method.

    remarks

    If you want to attach to document, use OnDocument instead.

    example
      @OnWindow("resize")
      private onToggleFade(ev: Event) {
        // Called when window is resized
      }

    On OnElement OnDocument OnWindow OnParent OnParentElement

    Parameters

    • Rest ...events: string[]

      The events to listen for

    Returns TypedPropertyDecorator<AnyFunction>

ParentEl

  • ParentEl(selector?: undefined | string, multiple?: undefined | false | true): TypedPropertyDecorator<any, any, string | number | symbol>
  • Creates a computed property for {@link Vue#$el#querySelector | this.$parent.$el.querySelector} or {@link Vue#$el#querySelectorAll | this.$parent.$el.querySelectorAll}

    remarks

    Preferably use Ref

    example
    @Component({ template: `<div><div id="foo"></div><foo-bar /></div>` })
    export class ParentComponent extends Vue {}
    
    @Component({})
    export class FooBar extends Vue {
      @ParentEl("#foo") private foo!: HTMLDivElement;
    }

    El DocumentEl ParentEl

    Parameters

    • Optional selector: undefined | string

      The css selector to pass to {@link Vue#$el#querySelector | this.$parent.$el.querySelector} or {@link Vue#$el#querySelectorAll | this.$parent.$el.querySelectorAll}

    • Optional multiple: undefined | false | true

      If {@link Vue#$el#querySelectorAll | this.$parent.$el.querySelectorAll} should be used

    Returns TypedPropertyDecorator<any, any, string | number | symbol>

Prop

  • Prop<T>(opts?: PropOpts<T>, typeOverride?: Constructor<T>): TypedPropertyDecorator<T>
  • Declares a Vue property.

    remarks

    There are various preconfigured flavors of this decorator for different types already available: SProp NProp DProp BProp

    example
      @Prop()                    private simpleFlag!: boolean;
      @Prop(Number)              private simpleNumber!: number;
      @Prop([String, Number])    private stringOrNumber!: string | number;
      @Prop({default: null})     private defaultsToNull!: null | string;
      @Prop({literal: parseInt}) private parser!: (str: string) => number;
      @Prop({model: "change"})   private modelValue!: string;

    SProp NProp DProp BProp

    Type parameters

    • T

    Parameters

    • Optional opts: PropOpts<T>

      The property options to pass to vue, it can either be a constructor function like String or Number, an array of constructor functions or a property object RecordPropOpts. If a property object is given, in addition to the normal vue options some additional values can be provided.

    • Optional typeOverride: Constructor<T>

      an optional type override if no type is specified using both provided options or reflected decorator metadata.

    Returns TypedPropertyDecorator<T>

Ref

  • Ref(ref: string): TypedPropertyDecorator<any>
  • Creates an accessor to a Vue reference.

    remarks

    If you need access to a dom node inside one of the children of this component or one outside of it, you can use El and its flavours instead.

    example
    @Component({ template: `<div><div ref="example">Hello World</div></div>` })
    class MyVueComponent extends Vue {
      @Ref("example") private example!: HTMLDivElement;
      private someMethod() {
        const {scrollLeft, clientWidth} = this.example;
        this.example.scrollTo({ left: scrollLeft + clientWidth * .6, behavior: "smooth" });
      }
    }

    Parameters

    • ref: string

      The reference to bind to.

    Returns TypedPropertyDecorator<any>

Route

  • Route(route?: string | Partial<RouteConfig>): (target: any) => any
  • Registers a route for a given component Decorator for components

    remarks

    If you want to use all registered routes, use {@link getRoutes} as the value for routes of your router.

    Only works if the file is imported before the router is initialized. Requires "vue-router"

    If you're looking for binding route parameters or queries to memgers Use RouteParam RouteQuery RouteName.

    example
    // pages/HelloPage.ts
    @Route("/hello")
    @Component({ template: `<div>Hello World</div>` })
    export class HelloPage extends Vue {}
    
    // router.ts
    import "./pages/HelloPage.ts"
    import Vue from "vue";
    import Router from "vue-router";
    import { getRoutes } from "@propero/vue-extra-decorators";
    Vue.use(Router);
    export const router = new Router({
      mode: "history",
      base: process.env.BASE_URL,
      routes: getRoutes(),
    });

    RouteParam RouteQuery RouteName

    Parameters

    • Optional route: string | Partial<RouteConfig>

      A route string or vue route config

    Returns (target: any) => any

      • (target: any): any
      • Parameters

        • target: any

        Returns any

RouteName

  • RouteName(): TypedPropertyDecorator<string | undefined>
  • Binds the current route name to a class member. Decorator for properties. On setting the decorated property, a navigation will occur to the set route name using {@link Router#replace}.

    remarks

    If you want to bind a route param or query instead, use RouteParam or RouteQuery If you want to bind a route to a component, use Route

    Requires "vue-router"

    example
    @Route({ name: "hello", path: "/" })
    @Component({ template: `<div>Hello World</div>` })
    export class HelloPage extends Vue {
    
      @RouteName()
      private routeName!: string; // Should be hello
    
      private nav() {
        this.routeName = "otherView"; // Navigates to otherView
      }
    }

    RouteParam RouteQuery RouteName Route

    Returns TypedPropertyDecorator<string | undefined>

RouteParam

  • RouteParam(name: string, props?: RouteParamOptions<any>): TypedPropertyDecorator<string | undefined>
  • Binds a route param to a class member. Decorator for properties. On setting the decorated property, a navigation will occur to the current route with new params using {@link Router#replace}.

    remarks

    If you want to bind a route name or query instead, use RouteName or RouteQuery If you want to bind a route to a component, use Route

    Requires "vue-router"

    example
    @Route({ name: "hello", path: "/:firstName" })
    @Component({ template: `<div>Hello {{thename || "World"}}</div>` })
    export class HelloPage extends Vue {
    
      @RouteParam("firstName")
      private thename!: string; // Inferred from URL
    
      private nav() {
        this.thename = "Gustav"; // Navigates to '/Gustav'
      }
    }

    RouteParam RouteQuery RouteName Route

    Parameters

    Returns TypedPropertyDecorator<string | undefined>

RouteQuery

  • RouteQuery<T>(name: string, props?: RouteQueryOptions<T>): TypedPropertyDecorator<T>
  • Binds a route query to a class member. Decorator for properties. On setting the decorated property, a navigation will occur to the current route with new query using {@link Router#replace}.

    remarks

    If you want to bind a route name or query instead, use RouteName or RouteQuery If you want to bind a route to a component, use Route

    Requires "vue-router"

    example
    @Route({ name: "hello", path: "/" })
    @Component({ template: `<div>Hello {{thename || "World"}}</div>` })
    export class HelloPage extends Vue {
    
      @RouteQuery("firstName")
      private thename!: string; // Inferred from URL
    
      private nav() {
        this.thename = "Gustav"; // Navigates to '/?firstName=Gustav'
      }
    }

    RouteParam RouteQuery RouteName Route

    Type parameters

    • T

    Parameters

    Returns TypedPropertyDecorator<T>

SProp

  • SProp(opts?: PropOpts<string>): TypedPropertyDecorator<string>
  • Declares a Vue property. String flavor of {@link Prop | @Prop} decorator

    remarks

    There are various preconfigured flavors of this decorator for different types already available: SProp NProp DProp BProp

    example
      @SProp()                      private simpleString!: string;
      @SProp({default: null})       private defaultsToNull!: null | string;
      @SProp({default: () => "hi"}) private defaultsToHi!: string;
      @SProp({model: "change"})     private modelValue!: string;

    SProp NProp DProp BProp Prop

    Parameters

    • Optional opts: PropOpts<string>

      The property options to pass to vue, it can either be a constructor function like String or Number, an array of constructor functions or a property object RecordPropOpts. If a property object is given, in addition to the normal vue options some additional values can be provided.

    Returns TypedPropertyDecorator<string>

Watch

  • Watch(property: string): TypedPropertyDecorator<AnyFunction>
  • Watch(opts: WatchOptionsWithProp): TypedPropertyDecorator<AnyFunction>
  • Watch a property for changes

    remarks

    You can also pass an options object instead of just a property to set it to watch immediately or deeply. There are also flavors for these uses: IWatch, DWatch, IDWatch

    example
    @Data({ default: "" }) private value!: string;
    @Watch("value")
    private onValueChange(newValue: string, oldValue: string) {
      // ...Implementation
    }

    Watch, IWatch, DWatch, IDWatch

    Parameters

    • property: string

      The property to watch

    Returns TypedPropertyDecorator<AnyFunction>

  • Parameters

    Returns TypedPropertyDecorator<AnyFunction>

Other Functions

State

  • State<T>(opts: { default?: T | (() => T); literal?: T }): PropertyDecorator
  • State(proto: InstanceType<any>, key: string | symbol): void
  • Creates an observable state for the decorated property. Every decorated property can then be used reactively in a vue context.

    remarks

    This is intended to be used outside of vue contexts in separate classes. You can never set a decorated value to undefined, it will always be set to null for reactivity reasons. This is meant to be used when vuex is too much for what you are trying to accomplish but some form of shared state is necessary. For vue components, you should use Data instead.

    example
    export class MySimpleStore {
      @State public firstName?: string;
      @State public lastName = "foo";
      @State({ default: () => new Date() }) public creationDate!: Date;
      @State({ literal: parseInt }) public parser!: (str: string) => number;
    }
    catecory

    Decorator

    Type parameters

    • T

    Parameters

    • opts: { default?: T | (() => T); literal?: T }

      The state options, default being the default value or a factory returning it, literal being the absolute default value, functions being passed as is.

      • Optional default?: T | (() => T)
      • Optional literal?: T

    Returns PropertyDecorator

  • Parameters

    • proto: InstanceType<any>
    • key: string | symbol

    Returns void

composeConverter

  • composeConverter(className: TFunction<string, [string]>, memberName: TFunction<string, [string]>): (name: string | [string, string], member: boolean) => string
  • Creates a key converter function for use in Classes.

    Parameters

    Returns (name: string | [string, string], member: boolean) => string

      • (name: string | [string, string], member: boolean): string
      • Parameters

        • name: string | [string, string]
        • member: boolean

        Returns string

isPromiseLike

  • isPromiseLike(it: any): it is Promise<any>
  • Parameters

    • it: any

    Returns it is Promise<any>

isThenable

  • isThenable(it: any): it is PromiseLike<any>
  • Parameters

    • it: any

    Returns it is PromiseLike<any>

statusOf

  • statusOf(obj: any): number | undefined
  • Parameters

    • obj: any

    Returns number | undefined

Predicate Functions

and

  • and(...fns: TFunction<boolean>[]): TFunction<boolean>
  • Merges multiple predicates into one.

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @If(and(isInPath("drawer"), not(wasPrevented)))
      private doSomething(ev: Event) {
        // only executed if isInPath("drawer") and not(wasPrevented) return true
      }

    If IfNot or not

    Parameters

    • Rest ...fns: TFunction<boolean>[]

      The predicates to combine

    Returns TFunction<boolean>

    A predicate that returns true if all other predicates have returned true.

isEqual

  • isEqual(path: string, value: any): (data: any) => boolean
  • Create a predicate that checks if the first parameter of the returned function is equal to a given value at a certain json path.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check against a set of values, use isOneOf instead.

    example
      @If(isEqual("foo.bar", "baz"))
      private doSomething(foo: any) {
        // foo.bar is "baz"
      }

    If IfNot or and not

    Parameters

    • path: string

      the path to look up in the returned object.

    • value: any

      the value to check equality against.

    Returns (data: any) => boolean

    A predicate for use in @If and @IfNot

      • (data: any): boolean
      • Parameters

        • data: any

        Returns boolean

isFirstChild

  • isFirstChild(ev: Event): boolean | null
  • A predicate that checks if the first parameter (assumed event) is the first child of its parent node.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if a node is the first element child of its parent, use isFirstElementChild instead.

    example
      @If(isFirstChild)
      private doSomething(ev: Event) {
        // ev.target is it the first child of its parent
      }

    If IfNot or and not isFirstElementChild isLastChild isLastElementChild

    Parameters

    • ev: Event

      The event to check against

    Returns boolean | null

    true, if the event's target is the first child of its parent.

isFirstElementChild

  • isFirstElementChild(ev: Event): boolean | null
  • A predicate that checks if the first parameter (assumed event) is the first child element of its parent element.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if a node is the first child node of its parent, use isFirstChild instead.

    example
      @If(isFirstElementChild)
      private doSomething(ev: Event) {
        // ev.target is it the first child of its parent
      }

    If IfNot or and not isFirstChild isLastChild isLastElementChild

    Parameters

    • ev: Event

      The event to check against

    Returns boolean | null

    true, if the event's target is the first child of its parent.

isInPath

  • isInPath(...refs: string[]): (this: Vue, ev: Event) => boolean
  • Creates a predicate that checks if its first parameter (assumed event) has one or more given vue refs in its {@link Event#composedPath | composedPath}.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if one of many matches use isOneInPath instead.

    example
      @If(isInPath("drawer"))
      private doSomething(ev: Event) {
        // this.$refs["drawer"](.$el) is a member of ev.composedPath()
      }

    If IfNot or and not isOneInPath

    Parameters

    • Rest ...refs: string[]

      The vue refs to check against

    Returns (this: Vue, ev: Event) => boolean

    A predicate that returns true if all refs are part of the events composedPath.

      • (this: Vue, ev: Event): boolean
      • Parameters

        • this: Vue
        • ev: Event

        Returns boolean

isLastChild

  • isLastChild(ev: Event): boolean | null
  • A predicate that checks if the first parameter (assumed event) is the last child of its parent node.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if a node is the last element child of its parent, use isLastElementChild instead.

    example
      @If(isLastChild)
      private doSomething(ev: Event) {
        // ev.target is it the last child of its parent
      }

    If IfNot or and not isFirstElementChild isFirstChild isLastElementChild

    Parameters

    • ev: Event

      The event to check against

    Returns boolean | null

    true, if the event's target is the last child of its parent.

isLastElementChild

  • isLastElementChild(ev: Event): boolean | null
  • A predicate that checks if the first parameter (assumed event) is the last child element of its parent element.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if a node is the last child node of its parent, use isLastChild instead.

    example
      @If(isLastElementChild)
      private doSomething(ev: Event) {
        // ev.target is it the last child of its parent
      }

    If IfNot or and not isFirstChild isLastChild isFirstElementChild

    Parameters

    • ev: Event

      The event to check against

    Returns boolean | null

    true, if the event's target is the last child of its parent.

isOneInPath

  • isOneInPath(...refs: string[]): (this: Vue, ev: Event) => boolean
  • Creates a predicate that checks if its first parameter (assumed event) has one or more given vue refs in its {@link Event#composedPath | composedPath}.

    remarks

    This function is meant to be a condition for If alike methods. If you want to check if all match use isInPath instead.

    example
      @If(isOneInPath("drawer", "navbar"))
      private doSomething(ev: Event) {
        // this.$refs["drawer"](.$el) or this.$refs["navbar"](.$el) is a member of ev.composedPath()
      }

    If IfNot or and not isInPath

    Parameters

    • Rest ...refs: string[]

      The vue refs to check against

    Returns (this: Vue, ev: Event) => boolean

    A predicate that returns true if one of all refs are part of the events composedPath.

      • (this: Vue, ev: Event): boolean
      • Parameters

        • this: Vue
        • ev: Event

        Returns boolean

isOneOf

  • isOneOf(path: string, ...values: any[]): (data: any) => boolean
  • Create a predicate that checks if the first parameter of the returned function is equal to one of many a given values at a certain json path.

    remarks

    This function is meant to be a condition for If alike methods. If you only want to check against a single value, use isEqual instead.

    example
      @If(isOneOf("foo.bar", "baz", "qux"))
      private doSomething(foo: any) {
        // foo.bar is either "baz" or "qux"
      }

    If IfNot or and not

    Parameters

    • path: string

      the path to look up in the returned object.

    • Rest ...values: any[]

      the value to check equality against.

    Returns (data: any) => boolean

    A predicate for use in @If and @IfNot

      • (data: any): boolean
      • Parameters

        • data: any

        Returns boolean

keyMatches

  • keyMatches(...keys: string[]): (ev: KeyboardEvent) => boolean
  • Creates a predicate that checks if the first parameter (assumed event) is a key event matching one of a given set of keys.

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @If(keyMatches("Enter", "ArrowUp", "A"))
      private doSomething(ev: KeyboardEvent) {
        // ev.key is either "Enter", "ArrowUp" or "A"
      }

    If IfNot or and not mouseButtonMatches wasPrevented

    Parameters

    • Rest ...keys: string[]

      The keys to check against

    Returns (ev: KeyboardEvent) => boolean

    A predicate that returns true, if the event key is one of the given keys.

      • (ev: KeyboardEvent): boolean
      • Parameters

        • ev: KeyboardEvent

        Returns boolean

mouseButtonMatches

  • mouseButtonMatches(...buttons: MouseButton[]): (ev: MouseEvent) => boolean
  • Creates a predicate that checks if the first parameter (assumed event) is a key event matching one of a given set of mouse buttons.

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @If(mouseButtonMatches("LEFT", "MIDDLE"))
      private doSomething(ev: MouseEvent) {
        // ev is either left or middle click (or both!)
      }

    If IfNot or and not keyMatches wasPrevented

    Parameters

    • Rest ...buttons: MouseButton[]

      The mouse buttons to check against

    Returns (ev: MouseEvent) => boolean

    A predicate that returns true, if the event button is one of the given mouse buttons.

      • (ev: MouseEvent): boolean
      • Parameters

        • ev: MouseEvent

        Returns boolean

not

  • not(fn: TFunction<boolean>): TFunction<boolean>
  • Inverts a given predicate (negates its output)

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @If(not(wasPrevented))
      private doSomething(ev: Event) {
        // wasPrevented returns false
      }

    If IfNot or and

    Parameters

    • fn: TFunction<boolean>

      The predicate to invert

    Returns TFunction<boolean>

    The negated predicate.

or

  • or(...fns: TFunction<boolean>[]): TFunction<boolean>
  • Merges multiple predicates into one.

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @If(or(isInPath("drawer"), not(wasPrevented)))
      private doSomething(ev: Event) {
        // only executed if isInPath("drawer") or not(wasPrevented) return true
      }

    If IfNot and not

    Parameters

    • Rest ...fns: TFunction<boolean>[]

      The predicates to combine

    Returns TFunction<boolean>

    A predicate that returns true if one of the given predicates returns true.

wasPrevented

  • wasPrevented(ev: Event): boolean
  • A predicate that checks if the first parameter (assumed event) was prevented with {@link Event#preventDefault | preventDefault}.

    remarks

    This function is meant to be a condition for If alike methods.

    example
      @IfNot(wasPrevented)
      private doSomething(ev: Event) {
        // ev was not prevented!
      }

    If IfNot or and not keyMatches mouseButtonMatches

    Parameters

    • ev: Event

      The event to check against

    Returns boolean

    true, if event was prevented before.

Generated using TypeDoc