我使用redux-observable的史诗具有redux状态。
我需要解决在用户删除一个或多个对象后显示消息的问题。
有两种方法删除对象:
deleteObject(id: string)
调用deleteObjectFulfilled
动作deleteObjects(ids: Array<string>)
调用N * deleteObject(id: string)
动作我想在每次成功的“删除操作”之后显示已删除邮件的仅一个邮件,计数]。
我对这部史诗的最终解决方案是:
export const showDeleteInformationEpic = action$ => combineLatest( action$.pipe(ofType(DELETE_OBJECT_FULFILLED)), action$.pipe( ofType(DELETE_OBJECTS), switchMap(({ meta: { ids } }) => action$.pipe( ofType(DELETE_OBJECT_FULFILLED), skip(ids.length - 1), map(() => ids.length), startWith('BATCH_IN_PROGRESS'), take(2), ), ), startWith(1), ), ).pipe( startWith([null, null]), pairwise(), map(([[, previousCount], [, currentCount]]) => (previousCount === 'BATCH_IN_PROGRESS') ? currentCount : isNumber(currentCount) ? 1 : currentCount), filter(isNumber), map((count) => throwInfo('objectDeleted', { count })), );
您能看到更好的解决方案吗?
我使用redux-observable的史诗具有redux状态。我需要解决在用户删除一个或多个对象后显示一条消息的问题。有两种删除对象的方法:通过操作...
如果两种情况下我都只使用deleteObjects(Array<string>)
,则有一个更简单的解决方案。
代替触发多个动作,您可以创建和调度单个动作DELETE_MULTIPLE
,并在有效负载中传递所有id
。