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

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

fromArray Rx wiki on github

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


        
4条回答
  •  执笔经年
    2020-12-30 01:02

    In RxJS what you are looking for is called a Subject. You can push data into it and stream it from there.

    • Subject getting started guide
    • Subject API docs.

    Example:

    var array = [];
    var arraySubject = new Rx.Subject();
    
    var pushToArray = function (item) {
      array.push(item);
      arraySubject.next(item);
    }
    
    // Subscribe to the subject to react to changes
    arraySubject.subscribe((item) => console.log(item));
    

提交回复
热议问题