constant published


published = const PublishedProperty()

Use this annotation to publish a property as an attribute.

You can also use PublishedProperty to provide additional information, such as automatically syncing the property back to the attribute.

For example:

class MyPlaybackElement extends PolymerElement {
  // This will be available as an HTML attribute, for example:
  //
  //     <my-playback volume="11">
  //
  // It will support initialization and data-binding via <template>:
  //
  //     <template>
  //       <my-playback volume="{{x}}">
  //     </template>
  //
  // If the template is instantiated or given a model, `x` will be
  // used for this field and updated whenever `volume` changes.
  @published
  double get volume => readValue(#volume);
  set volume(double newValue) => writeValue(#volume, newValue);

  // This will be available as an HTML attribute, like above, but it
  // will also serialize values set to the property to the attribute.
  // In other words, attributes['volume2'] will contain a serialized
  // version of this field.
  @PublishedProperty(reflect: true)
  double get volume2 => readValue(#volume2);
  set volume2(double newValue) => writeValue(#volume2, newValue);
}

Important note: the pattern using readValue and writeValue guarantees that reading the property will give you the latest value at any given time, even if change notifications have not been propagated.

We still support using @published on a field, but this will not provide the same guarantees, so this is discouraged. For example:

  // Avoid this if possible. This will be available as an HTML
  // attribute too, but you might need to delay reading volume3
  // asynchronously to guarantee that you read the latest value
  // set through bindings.
  @published double volume3;