Skip to content

Commit

Permalink
fix: add timed buffer to tag and asset listener epics to prevent acti…
Browse files Browse the repository at this point in the history
…on spam on batch operations
  • Loading branch information
robinpyon committed Feb 11, 2021
1 parent 43fbe94 commit d982b0b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/modules/assets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {Selector} from 'react-redux'
import {StateObservable} from 'redux-observable'
import {from, empty, of, Observable} from 'rxjs'
import {
bufferTime,
catchError,
debounceTime,
filter,
Expand Down Expand Up @@ -1005,6 +1006,8 @@ export const assetsSortEpic = (action$: Observable<AssetsActions>): Observable<A
AssetsActionTypes.UPDATE_COMPLETE
])
),
bufferTime(1000),
filter(actions => actions.length > 0),
switchMap(() => {
return of(assetsSort())
})
Expand Down
4 changes: 3 additions & 1 deletion src/modules/tags/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import client from 'part:@sanity/base/client'
import {Selector} from 'react-redux'
import {StateObservable} from 'redux-observable'
import {Observable, from, of} from 'rxjs'
import {catchError, filter, mergeMap, switchMap, withLatestFrom} from 'rxjs/operators'
import {bufferTime, catchError, filter, mergeMap, switchMap, withLatestFrom} from 'rxjs/operators'
import {isOfType} from 'typesafe-actions'

import {TAG_DOCUMENT_NAME} from '../../constants'
Expand Down Expand Up @@ -681,6 +681,8 @@ export const tagsSortEpic = (action$: Observable<TagsActions>): Observable<TagsA
TagsActionTypes.LISTENER_CREATE
])
),
bufferTime(1000),
filter(actions => actions.length > 0),
switchMap(() => {
return of(tagsSort())
})
Expand Down

0 comments on commit d982b0b

Please sign in to comment.