Jer*_*ees 7 polymer object.observe
就像标题所说的那样.有没有办法在不触发Polymer中的观察者回调的情况下修改观察值?
例如
Polymer({
is: 'my-component',
properties: {
aValue: {
type: Number,
value: 0,
observer: '_valueChanged',
notify: true
},
ref: {
type: Object,
computed: '_computeRef(channel, channelNumber)'
}
},
_computeRef: function(channel, channelNumber) {
var ref = new Firebase("/*link*/");
ref.on("child_changed", function(data) {
this.aValue.setWithoutCallingObserver(data.val());
}.bind(this));
return ref;
},
_valueChanged: function() {
var message = { aValue: this.aValue };
if (this.ref) {
this.ref.set(message);
}
}
});
Run Code Online (Sandbox Code Playgroud)
这将是有用的,因为现在我遇到以下情况中的滞后:
aValue第三方应用程序更新:问题与firebase无关.我相信解决方案是控制如何将更新应用于Polymer中的观察值.部分原因是对firebase商店中的值的更改也可以由第3方(不一定是Web)应用程序进行.
Ala*_*los -1
只需将 _valueChangedMethod 更改为此
_valueChanged: function(newValue, oldValue) {
if(newValue == oldValue) return;
var message = { aValue: this.aValue };
if (this.ref) {
this.ref.set(message);
}
}
Run Code Online (Sandbox Code Playgroud)
这将使观察者仅在值实际发生变化时才执行其工作。