3
votes

Apologies if this is a bit fuzzy.

I have my own FRP based library for building my application models. It has a concept of components which have state which is changed via Streams.

This encapsulates the behaviour of the UI minus the actual views. I am starting to integrate this with Polymer 1.0 and would like some guidance as the the best approach.

Some things are easy (like binding changes to fields in my models to notifyPath).

For updates I'm considering having a single method with an Observe annotation like

@Observe('*')
void myHandler(Map changeRecord) => ... delegate to my adapters

Is it likely to be inefficient to listen to all (*) events like this? Is there a lower level way to register more specific paths that avoids the need for the Observe annotation?

Is using the PolymerRegister annotation the best way to register the components in this case? Is there lower level API to do it instead?

1

1 Answers

2
votes

Is it likely to be inefficient to listen to all (*) events like this?

The global * event is not actually supported unfortunately, the path must start with a property name. You could make a behavior which uses the properties getter to set up manual listeners on all properties.

Is there a lower level way to register more specific paths that avoids the need for the Observe annotation.

There is the listen(Node element, String eventName, String methodName) method. You can just pass this as the node and listen to {{property}}-changed events. You will need to make sure all your properties have notify: true so they fire the events. This is also going to be a little less efficient since it is using actual events instead of the magic hooks which observers use.

There are probably some other hacks to dynamically add regular observers, but I don't know of them off the top of my head :).

Is using the PolymerRegister annotation the best way to register the components in this case? Is there lower level API to do it instead?

This is the only way today, but if you wanted to control when the registration happens you could just create a const PolymerRegister(...) object and call initialize on it whenever your heart desires. Please file a feature request for a real imperative api if you would prefer that.