Can I observe additions to an array with rx.js?

前端 未结 4 1478
梦如初夏
梦如初夏 2020-12-30 00:34

fromArray Rx wiki on github

coffee> rext = require \'rx\'                                                 
coffee> arr = [1..5]                                 


        
4条回答
  •  时光取名叫无心
    2020-12-30 00:55

    How about this:

    var subject = new Rx.Subject();
    //scan example building an array over time
    var example = subject.scan((acc, curr) => { 
        return acc.concat(curr);
    }
    ,[]);
    
    //log accumulated values
    var subscribe = example.subscribe(val => 
        console.log('Accumulated array:', val)
    );
    
    //next values into subject
    subject.next(['Joe']);
    subject.next(['Jim']);
    

提交回复
热议问题