Skip to content

Commit 416c5fd

Browse files
proper throttleTime and cleaning
1 parent 0fe5367 commit 416c5fd

File tree

3 files changed

+22
-307
lines changed

3 files changed

+22
-307
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
"redux-observable": "2.0.0-rc.2",
3232
"rxjs": "7.1.0",
3333
"styled-components": "^5.3.0",
34-
"tailwindcss": "^2.1.4",
35-
"twin.macro": "^2.4.2",
3634
"typescript": "^4.1.2"
3735
},
3836
"devDependencies": {

src/logic/store/book/book.epic.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { combineEpics } from 'redux-observable';
2-
import { from } from 'rxjs';
3-
import { debounceTime, filter, map, switchMap } from 'rxjs/operators';
2+
import { asyncScheduler, from } from 'rxjs';
3+
import { filter, map, switchMap, throttleTime } from 'rxjs/operators';
44
import { RootEpic } from '../../../app/app.epics.type';
55
import { AVOID_QUICK_MULTIPLY_API_CALLS_TIMEOUT_MS } from '../../const';
66
import { managed } from '../../operators/managed.operator';
@@ -11,7 +11,10 @@ import { bookSlice } from './book.slice';
1111
const fetchBooks$: RootEpic = (action$, state$) =>
1212
action$.pipe(
1313
filter(bookSlice.actions.fetchBooks.match),
14-
debounceTime(AVOID_QUICK_MULTIPLY_API_CALLS_TIMEOUT_MS),
14+
throttleTime(AVOID_QUICK_MULTIPLY_API_CALLS_TIMEOUT_MS, asyncScheduler, {
15+
leading: true,
16+
trailing: true,
17+
}),
1518
map(() => getSearchPhrase(state$.value)),
1619
managed(
1720
switchMap((searchPhrase) => from(bookApi.fetchBooks(searchPhrase)))

0 commit comments

Comments
 (0)