bacon.js:holdWhen和onValue的奇怪行为
bacon.js: Strange behaviour with holdWhen and onValue
在这里查看工作的CodePen:http://codepen.io/djskinner/pen/JdpwyY
// Animation start events push here
var startBus = new Bacon.Bus();
// Animation end events push here
var endBus = new Bacon.Bus();
// Balance updates push here
var balanceBus = new Bacon.Bus();
// A Property that determines if animating or not
var isAnimating = Bacon.update(false,
[startBus], function() { return true; },
[endBus], function() { return false; }
);
// Only update the displayBalance when not animating
var displayBalance = Bacon.update(0,
[balanceBus.holdWhen(isAnimating)], function(previous, x) {
return x;
}
);
setTimeout(function() {
var streamTemplate = Bacon.combineTemplate({
balance: displayBalance
});
// Uncommenting this block changes the way the system behaves
// streamTemplate.onValue(function(initialState) {
// console.log(initialState);
//})();
// Print the displayBalance
streamTemplate.onValue(function(v) {
console.log(v.balance);
});
});
按下平衡按钮会生成一个新的随机数。创建一个使用holdWhen
限制余额更新的属性,直到isAnimating
属性变为false。
如果我有兴趣获得streamTemplate
的初始状态,我可能会获得该值并立即取消订阅:
streamTemplate.onValue(function(initialState) {
console.log(initialState);
})();
但是,一旦我这样做,displayBalance
属性的行为就不同了,我就不再接收更新。
为什么这种看似惰性的变化会使系统发生如此剧烈的变化?当然,系统的行为不应该取决于某人是否在过去的某个时候订阅和取消订阅了streamTemplate?
此行为已被确认为一个已在0.7.67中修复的错误。
请参阅此处了解详细信息。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 强制模板刷新ember.js
- 如何编写HTML输入的JS内联
- Angular JS IE9 Hashbang url rewriting
- 使用JS将数组转换为json对象
- Node.js v6.2.0类扩展不是函数错误
- 当js函数's已执行
- 要求未定义JS回调参数
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 无法在数据endVal中设置值=“”;{{ucount}}”;使用Angular JS的CountUp
- 如何从Java/scala调用js美化程序
- 如何更改<svg>标记为<img>用js标记
- 如何使用 node.js 比较两个 json 数组
- chrome扩展:尽管运行了at:documentidle,js脚本还是过早启动
- 节点Js:How to catch a“;没有这样的文件或目录“;读取线模块出错
- Bacon.js onValue() chain
- bacon.js:holdWhen和onValue的奇怪行为