Property Type Hinting

74 views
Skip to first unread message

Clayton Watts

unread,
Jun 6, 2014, 1:12:34 AM6/6/14
to polym...@googlegroups.com
I think the docs (http://www.polymer-project.org/docs/polymer/polymer.html#attrhinting) could be clearer about the fact that to create an element like the x-name shown that can accept an array or object written in the DOM as a string, you must use a publish block and set reflect to true. (The word 'reflect' doesn't immediately seem to indicate its necessity for input as well as output).


This also means one has to include the property in the publish block AND in the created callback. Is there any way around that?

Clayton

Eric Bidelman

unread,
Jun 6, 2014, 1:26:53 AM6/6/14
to Clayton Watts, polym...@googlegroups.com
The property only needs to be published (and hint as an objected) for it to be [de]serialized correctly. For example, you can publish `fullName` in attributes="" and things work marvelously: http://jsbin.com/tecayaho/3/edit

From the docs, objects/arrays never reflect...even if you publish them with `reflect: true`:

The property value is serialized to a string based on its data type. A few types get special treatment:

  • If the property value is an object, array, or function, the value is never reflected, whether or not reflectis true.

Also note, your binding should be {{fullName.first}} in the template :)



Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CAGw__zFoqJraBuf6rmBCJnBoYWy1AFZ2pwxVG%3Dj%3DSGmN2FRMWQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Ian MacLeod

unread,
Jun 6, 2014, 10:14:12 AM6/6/14
to Eric Bidelman, Clayton Watts, polym...@googlegroups.com
However, you do have to hint objects via the value field:

publish: {myObj: {value: {}}

It's ambiguous with an options object otherwise :(

On Thu, Jun 5, 2014 at 10:26 PM, Eric Bidelman <ebi...@gmail.com> wrote:
The property only needs to be published (and hint as an objected) for it to be [de]serialized correctly. For example, you can publish `fullName` in attributes="" and things work marvelously: http://jsbin.com/tecayaho/3/edit

From the docs, objects/arrays never reflect...even if you publish them with `reflect: true`:

The property value is serialized to a string based on its data type. A few types get special treatment:

  • If the property value is an object, array, or function, the value is never reflected, whether or not reflectis true.

Also note, your binding should be {{fullName.first}} in the template :)
On Thu, Jun 5, 2014 at 4:39 PM, Clayton Watts <cle...@gmail.com> wrote:
I think the docs (http://www.polymer-project.org/docs/polymer/polymer.html#attrhinting) could be clearer about the fact that to create an element like the x-name shown that can accept an array or object written in the DOM as a string, you must use a publish block and set reflect to true. (The word 'reflect' doesn't immediately seem to indicate its necessity for input as well as output).


This also means one has to include the property in the publish block AND in the created callback. Is there any way around that?

Clayton

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev+unsubscribe@googlegroups.com.

Follow Polymer on Google+: plus.google.com/107187849809354688692
---
You received this message because you are subscribed to the Google Groups "Polymer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to polymer-dev+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/polymer-dev/CACGqRCCjcM6EY4Zed-TmuMx0a5s44zh-EH1UgfW71aAtWP5BOg%40mail.gmail.com.

Clayton Watts

unread,
Jun 6, 2014, 11:50:45 AM6/6/14
to Ian MacLeod, Eric Bidelman, polym...@googlegroups.com
Of course! I can't believe I forgot to list the property in the attributes list or the publish block. It wasn't the presence of "reflect" that was making it work in the second example, it was simply the fact that it was now listed in one of the places needed to publish a property. Thanks, Eric!

@Ian, it actually seems to work just with publish:{myObj:{}} even with the ambiguity: http://jsbin.com/tecayaho/7/edit?html,console,output
Reply all
Reply to author
Forward
0 new messages