Polymer support for getFoo()/setFoo() style properties

32 views
Skip to first unread message

red...@gmail.com

unread,
Oct 25, 2017, 2:00:25 AM10/25/17
to Polymer
I'm using objects that only expose data through getFoo() and setFoo() methods. Would Polymer developers be supportive of amending Polymer to support this use case?

(The objects in question are JavaScript protocol buffer messages.)

From looking over lib/utils/path.html, it seems fairly straightforward to hook into the path code. For an inelegant example, consider this plnkr.

Karl Tiedt

unread,
Oct 25, 2017, 10:44:37 AM10/25/17
to red...@gmail.com, Polymer
First off, I highly doubt an API change is gonna happen at this point to support, yet another data access method, when you can most likely accomplish it via code extensions or a base element class that enables this feature in the elements that require it. Second off, I dont see anywhere in your example you actually use this prescribed notion of setFoo, getFoo other than extending the demo object to add those methods... Maybe I am missing something (it is early for me)? It could simply be that I do not see how you expect to leverage this since you don't appear to call any of these proposed APIs in your plnkr... Trying ele.getName() fails, ele.myThing.getName() works but ele.myThing.name does not... 

Can you more clearly elaborate on what your goal is here?

-Karl Tiedt

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/0d0af3dc-f58d-4502-b6e8-f8c48c130ec8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Red Daly

unread,
Oct 25, 2017, 1:35:47 PM10/25/17
to Karl Tiedt, Polymer
The use case is to support generated code from the protocol buffers library so that those objects can be used directly as property values. Protobuf objects use getFoo and setFoo style accessors. They are typically nested deeply and used for communication back and forth with the server. The idea is to use a protobuf object as the property value in my element and reference its numerous fields from the template without translating back and forth to an object with simple setters/getters.

The myThing object in the demo is a stand-in for a protobuf object. Access in JavaScript should be through the getFoo syntax.

What do you mean that this may be possible with a "code extension?" I'm happy to do this only in my own app through a mix-in, but I don't see how to accomplish that without an API for resolving paths.

Karl Tiedt

unread,
Oct 25, 2017, 1:59:08 PM10/25/17
to Red Daly, Polymer
Through mixins or extensions, I mean, you write a base element class that understands protobufs for example and mirrors their properties to proper Polymer properties when they are assigned to your property. It won't be pretty but, I can say, when I was at Google, we had no such convenience with Protobufs and they were used quite a bit. 

-Karl Tiedt
Reply all
Reply to author
Forward
0 new messages