Günter Zöchbauer
Günter Zöchbauer

Reputation: 658067

What is the difference between @observable and @published

Until Polymer 0.10.1 the @published annotation created an attribute on the Polymer element where it was declared.
This changed with Polymer 0.11.0. Since then @PublishedProperty(reflect: true) is needed to make the fields value available as an attribute.

It seems that since this update @published has just the same effect as @observable. Am I missing something?

Upvotes: 1

Views: 515

Answers (1)

Matt B
Matt B

Reputation: 6312

The @published attribute still allows you to use the value as an attribute itself in the HTML declaratively. That is you can still do:

<my-element myprop="{{hello}}"></my-element>

The change is that accessing the values procedurally via the attributes property, then you must include @PublishedProperty(reflect: true). (This does not seem to be the case if you're interactive with the CustomTag class directly.

Needs @PublishedProperty(reflect: true):

var x = querySelector('x-foo');
x.bar = "hi";
// ...
print(x.attributes["bar"]);

This also needs @PublishedProperty(reflect: true):

/* CSS */
x-foo[bar="hi"] { background-color: blue; }

This does not:

XFoo x = querySelector('x-foo');
x.bar = "hi";
...
print(x.bar);

This was inferred from the discussion group for New Polymer Release 0.12.0

Upvotes: 2

Related Questions