正如标题所说。有没有办法在不触发 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);
}
}
});
这将很有用,因为现在我在以下情况下遇到了滞后:
- 适配
aValue
第三方应用 - Firebase 更新所有客户端
- .on 回调设置值并触发观察者回调
- 导致 .set 到 firebase
- 回到 2。
更新:这个问题与火力无关。我相信解决方案是控制如何将更新应用于 Polymer 中的观察值。部分原因是第 3 方(不一定是 Web)应用程序也可以对 firebase 存储中的值进行更改。