【问题标题】:RxJS - Emit value after ever n receivedRxJS - 在收到 n 后发出值
【发布时间】:2017-07-26 01:12:50
【问题描述】:

是否存在可以通过计数限制排放的运算符?

我基本上想重复跳过呼叫。在下面的示例中,我想跳过 5,发出一个值并重复。

export default function errorHandler(action$){
  action$.ofType(types.ERROR)
  /* After every n emissions received, emit once */
  .map(someAction)
}

【问题讨论】:

    标签: javascript rxjs redux-observable


    【解决方案1】:

    您可以使用bufferCount,它会在缓冲了指定数量的操作后发出。

    使用 RxJS 的术语,限制将涉及发出的第一个缓冲操作:

    export default function errorHandler(action$){
      action$.ofType(types.ERROR)
        .bufferCount(5)
        .map((actions) => actions[0]);
    }
    

    在 RxJS 的术语中,发出最后一个缓冲的动作将被称为去抖动:

    export default function errorHandler(action$){
      action$.ofType(types.ERROR)
        .bufferCount(5)
        .map((actions) => actions[actions.length - 1]);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-03
      • 1970-01-01
      • 2021-12-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多