Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polymer. Way to dynamically add or remove observer

Tags:

polymer

Is there a way to add or remove observer not in the moment of element initing? I can define observer this way:

observers: ['dataChanged(data.*)']

Can i remove this observer later or can I set this observer different way than that?

like image 797
Fyodor Khruschov Avatar asked Sep 22 '16 20:09

Fyodor Khruschov


1 Answers

You can easily add an observer dynamically, either by:

this._addObserverEffect("property", observerFunction);

or

this._addComplexObserverEffect("dataChanged(data.*)");

Removing is harder and Polymer does not provide a function to do this. Although you could search for it in the _propertyEffects array, I wouldn't recommend it. Maybe just check in your observer function whether it should still be active, and return if not.

like image 109
Tim Rogers Avatar answered Oct 21 '22 07:10

Tim Rogers