简体   繁体   English

bacon.js-获取流/属性的值

[英]bacon.js - get value of stream/property

Probably it's simple question, but I can't resolve my problem. 可能这是一个简单的问题,但我无法解决问题。 I have two streams and want mapping second stream by negative value of first stream. 我有两个流,并希望通过第一流的负值映射第二个流。

jsfiddle - example jsfiddle- 示例

var price = change.map(1).scan(10, plus)
var money = buy.map(-price).merge(sale.map(price)).scan(100, plus);

This answer is basically what bergi said in the comments. 这个答案基本上就是伯格在评论中所说的。

var price = change.map(1).scan(10, plus)
var purchasePrice = price.map(function(p) { return -p }).sampledBy(buy)
var salePrice = price.sampledBy(sale)
var money = purchasePrice.merge(salePrice).scan(100, plus)

I used property.sampledBy(stream) instead of stream.map(property) - they do the same thing, but here I think it's clearer to use sampledBy . 我使用property.sampledBy(stream)而不是stream.map(property) -它们执行相同的操作,但是在这里,我认为使用sampledBy更清楚。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM