class ComputedProperty


Use this to create computed properties that are updated automatically. The annotation includes a polymer expression that describes how this property value can be expressed in terms of the values of other properties. For example:

class MyPlaybackElement extends PolymerElement {
  @observable int x;

  // Reading xTimes2 will return x * 2.
  @ComputedProperty('x * 2')
  int get xTimes2 => readValue(#xTimes2);

If the polymer expression is assignable, you can also define a setter for it. For example:

  // Reading c will return a.b, writing c will update a.b.
  @ComputedProperty('a.b')
  get c => readValue(#c);
  set c(newValue) => writeValue(#c, newValue);

The expression can do anything that is allowed in a polymer expresssion, even making calls to methods in your element. However, dependencies that are only used within those methods and that are not visible in the polymer expression, will not be observed. For example:

  // Because `x` only appears inside method `m`, we will not notice
  // that `d` has changed if `x` is modified. However, `d` will be
  // updated whenever `c` changes.
  @ComputedProperty('m(c)')
  get d => readValue(#d);

  m(c) => c + x;

Constructors

ComputedProperty(String expression)

const

Properties

expression → String

A polymer expression, evaluated in the context of the custom element where this annotation is used.

read-only
hashCode → int

Get a hash code for this object.

read-only, inherited
runtimeType → Type

A representation of the runtime type of the object.

read-only, inherited

Operators

operator ==(other) → bool

The equality operator.

inherited

Methods

noSuchMethod(Invocation invocation) → dynamic

Invoked when a non-existent method or property is accessed.

inherited
toString() → String

Returns a string representation of this object.

inherited