1

Given an element instance, how do I see how many observers it's maintaining?

I'm trying to figure if either of these implementations is more expensive.

Polymer({
  fooChanged: function() {
    this.bar = foo.baz;
  }
}

Polymer({
  computed: {
    'bar': 'foo.baz'
  }
}

I suspect they're equivalent (except that one is watching foo, the other is watching the path) but I want to be sure.

Dane O'Connor
  • 67,996
  • 36
  • 114
  • 164

2 Answers2

1

Internally, Polymer uses uses Node.bind() to bind the property changes. It will use PathObserver to watch 'foo.baz' and of course, it's slower to watch a computed object like that versus a single attribute.

https://www.polymer-project.org/docs/polymer/node_bind.html

ngduc
  • 1,357
  • 10
  • 16
  • The equivalent javascript for the computed is: `this.bind('bar', new PathObserver(foo, 'baz'));`. Do you know the equivalent javascript for the property changed? – Dane O'Connor Feb 11 '15 at 17:48
0

You can check all the event listeners in the chrome dev tools. Select the ID in the console and on the right you have the "event listeners" tab.

See: Using Chrome, how to find who's binded to an event?

But I doubt this will show you anything performance wise. I think it is better to use the CPU profile in the profiles tab in the chrome dev tools.

Community
  • 1
  • 1
Luc Hendriks
  • 2,193
  • 10
  • 18