缓冲区,直到具有redux observable和rxjs

缓冲区,直到具有redux observable和rxjs,rxjs,redux-observable,Rxjs,Redux Observable,在存储的值为真之前,是否有一种模式可以使redux可观察到epic缓冲区 const uploadsCompleteEpic = (action$, store) => { return action$ .ofType(actionTypes.UPLOAD_SUCCESS) .bufferWhen(store => store.getState().remaining -1 === 0) .do(action => console.log(actio

在存储的值为真之前,是否有一种模式可以使
redux可观察到
epic缓冲区

const uploadsCompleteEpic = (action$, store) => {
  return action$
    .ofType(actionTypes.UPLOAD_SUCCESS)
    .bufferWhen(store => store.getState().remaining -1 === 0)
    .do(action => console.log(action))
    .ignoreElements();
};
上述操作不起作用,因为
bufferWhen
中的函数不可观察。我还尝试将缓冲区函数包装为
Observable.single
,但没有成功。

您可以使用正则表达式

公共缓冲区(closingNotifier:Observable):Observable

以数组形式收集过去的值,并且仅当
closingNotifier
Observable发出时才发出该数组

我不知道在什么具体情况下,
剩余的
值会发生变化或为零,因此您肯定需要进行额外的检查或等待,这样事情就不会发生冲突。e、 g.如果可能的话,排除空缓冲区

const uploadsCompleteEpic = (action$, store) => {
  // just used as a notifier, so we don't actually
  // care about what the value is, just when.
  // Since the state is only ever updated when an
  // action is received we can use that time to check.
  const notification$ = action$.filter(() => {
    return store.getState().remaining - 1 === 0;
  );

  return action$
    .ofType(actionTypes.UPLOAD_SUCCESS)
    .buffer(notification$)
    // Use this if you want to exclude empty buffers
    // .filter(buffer => buffer.length > 0) 
    .do(action => console.log(action))
    .ignoreElements();
};