turbodombuilder - v0.9.22
    Preparing search index...

    Function auto

    • Function

      Parameters

      • Optionaloptions: AutoOptions

        Options object to define custom behaviors.

      Returns <Type extends object, Value>(
          value:
              | {
                  get?: (this: Type) => Value;
                  set?: (this: Type, value: Value) => void;
              }
              | ((initial: Value) => Value)
              | ((this: Type) => Value)
              | ((this: Type, v: Value) => void),
          context:
              | ClassFieldDecoratorContext<Type, Value>
              | ClassGetterDecoratorContext<Type, Value>
              | ClassSetterDecoratorContext<Type, Value>
              | ClassAccessorDecoratorContext<Type, Value>,
      ) => any

      auto

      Stage-3 decorator that augments fields, getters, setters, and accessors. Useful to quickly create a setter and only define additional functionality on set. The decorator takes an optional object as parameter to configure it, allowing you to, among other things:

      • Preprocess the value when it is set,
      • Specify callbacks to call before/after the value is set,
      • Define a default value to return instead of undefined when calling the getter, and
      • Fire the setter when the underlying value is undefined.

      Note: If you want to chain decorators, place @auto closest to the property to ensure it runs first and sets up the accessor for other decorators.

      @auto() public set color(value: string) {
      this.style.backgroundColor = value;
      }

      Is equivalent to:

      private _color: string;
      public get color(): string {
      return this._color;
      }

      public set color(value: string) {
      this._color = value;
      this.style.backgroundColor = value;
      }