我一直在学习RxJs,我在尝试确定使用scan和combinelatest时看到的输出背后的逻辑时遇到了问题
我有这个示例应用程序
var subject = new Rx.Subject();
var stream = subject.map(function(x) {
return function(v) {
return v + " stream";
};
});
var state = Rx.Observable.merge(stream)
.startWith("StartWith")
.scan(function(x, f) {
console.log("scan");
return f(x);
});
var view1 = state.map(function(x) {
return "view1 " + x;
});
var view2 = state.map(function(x) {
return " view2 " + x;
});
Rx.Observable.combineLatest(view1, view2, function(x, y) {
return [x, y].join(",");
}).subscribe(function(x) {
console.log(x);
});
subject.onNext("Once");
subject.onNext("Twice");Run Code Online (Sandbox Code Playgroud)
当您查看应用程序的控制台日志时,它会输出以下内容
LOG: view1 StartWith, view2 StartWith,
LOG: scan
LOG: …Run Code Online (Sandbox Code Playgroud)