decorators

Object: esri/core/accessorSupport/decorators
Since: ArcGIS API for JavaScript 4.2

This module contains Accessor TypeScript decorators. Decorators allow us to define and/or modify behavior of existing properties, methods, and constructors at design time.

Method Overview

NameReturn TypeSummaryObject
Function

A property decorator that creates a two-way binding between the property it decorates and an inner property of one of its members.

more details
more detailsdecorators
Function

This parameter decorator is used to define the function or class for a parameter of a method.

more details
more detailsdecorators
Function

This method decorator is used to define the method that will cast a property from a class.

more details
more detailsdecorators
*

A function that can be used as a class.

more details
more detailsdecorators
Function

This convenience decorator is used to define an Accessor property.

more details
more detailsdecorators
Function

A class decorator that must be used together with the declared function to create a class compatible to dojo.declare.

more details
more detailsdecorators

Method Details

aliasOf(propertyName){Function}

A property decorator that creates a two-way binding between the property it decorates and an inner property of one of its members.

Parameter:
propertyName String

The aliased property name.

Returns:
TypeDescription
FunctionThe property decorator.
Examples:
// property example
@aliasOf("viewModel.name")
name: string = "name";
// method example
@aliasOf("viewModel.someMethod")
someMethod: () => string;
cast(classFunction){Function}

This parameter decorator is used to define the function or class for a parameter of a method.

Parameter:
classFunction Function

The function or class to cast the parameter

Returns:
TypeDescription
FunctionThe method descriptor.
See also:
Example:
/// <amd-dependency path="esri/core/tsSupport/declareExtendsHelper" name="__extends" />
/// <amd-dependency path="esri/core/tsSupport/decorateHelper" name="__decorate" />
import Accessor = require("esri/core/Accessor");
import { subclass, property, declared } from "esri/core/tsSupport/declare";

@subclass()
class QueryTask extends declared(Accessor) {

  execute(@cast(Query) query: Query): IPromise<FeatureSet> {
    return ...;
  }

}
cast(propertyName){Function}

This method decorator is used to define the method that will cast a property from a class.

Parameter:
propertyName String

The property name the function will cast.

Returns:
TypeDescription
FunctionThe method descriptor.
See also:
Example:
/// <amd-dependency path="esri/core/tsSupport/declareExtendsHelper" name="__extends" />
/// <amd-dependency path="esri/core/tsSupport/decorateHelper" name="__decorate" />
import Accessor = require("esri/core/Accessor");
import { subclass, property, declared, cast } from "esri/core/tsSupport/declare";

@subclass()
class Color extends declared(Accessor) {

  @property()
  r: number = 0;

  @property()
  g: number = 0;

  @property()
  b: number = 0;

  @property()
  a: number = 1;

  @cast("r")
  @cast("g")
  @cast("b")
  protected castComponent(value) {
    // cast method that clamp the value that
    // will be set on r, g or b between 0 and 255
    return Math.max(0, Math.min(255, value));
  }

  @cast("a")
  protected castAlpha(value) {
    // cast method that clamp the value that
    // will be set on a between 0 and 255
    return Math.max(0, Math.min(1, value));
  }
}
declared(baseClass, mixinClasses){*}

A function that can be used as a class. It extends expression and is used in conjunction with the @subclass decorator to create a class compatible to dojo.declare. Please refer to the subclass documentation for further information.

Parameters:
baseClass

The class to extend.

mixinClasses Object
repeatable

The mixin classes used to extend the base class.

Returns:
TypeDescription
*The first baseClass.
Example:
// typescript syntax which creates a subclass that extends the Accessor class.
@subclass("my.custom.class")
class MyCustomClass extends declared(Accessor) {
  // ...
}
property(propertyMetadata){Function}

This convenience decorator is used to define an Accessor property. Any property defined with this decorator can now be get and set. In addition, you can watch for any property changes. Many times this decorator is used in conjunction with the @renderable decorator.

Parameters:
propertyMetadata Object
optional

An object describing the property.

Specification:
dependsOn String[]
optional

Property names of dependencies.

optional

The constructor used to autocast the property.

optional

The function to use to autocast the property. Alternative to define the type. The function is called with the value set by the user and should return the cast value.

readOnly Boolean
optional
Default Value: false

Indicates whether the property is read-only.

constructOnly Boolean
optional
Default Value: false

Indicates whether the property can be set during construction but is otherwise read-only.

aliasOf String
optional

The property decorator that creates a two-way binding between the property it decorates and an inner property of one of its members.

value Object
optional

The default value for the property.

Returns:
TypeDescription
FunctionThe property descriptor.
See also:
Example:
// typescript syntax to specify the property.
@property()
title: string = "Awesome Title!"
subclass(declaredClass){Function}

A class decorator that must be used together with the declared function to create a class compatible to dojo.declare. It supports both single and multiple inheritance and can be considered the underlying functionality needed when creating 4.x classes.

Parameter:
declaredClass String
optional

The subclass name.

Returns:
TypeDescription
FunctionThe class decorator.
Examples:
// Single inheritance - typescript syntax which creates a subclass that extends the Accessor class.
@subclass("my.custom.class")
class MyCustomClass extends declared(Accessor) {
  // ...
}
// Multiple inheritance - typescript syntax which creates a subclass that extends multiple classes
// Use declaration merging to add mixins to the SceneLayer type
interface SceneLayer extends SceneService {
}

// provide a fully qualified namespace for the resulting subclass
@subclass("esri.layers.SceneLayer")
class SceneLayer extends declared(Layer, SceneService) {
  // do something
}

API Reference search results

NameTypeModule
Loading...