Skip to content

Commit

Permalink
(optim): debounce the search input handler
Browse files Browse the repository at this point in the history
- so it doesn't fire for every character and have lagging output,
  debounce it for a better user experience and less wasteful
  network activity
  - also fixes some consistency errors that happen when requests
    finish out-of-order, like when you backspace out completely but
    there are still some manga showing

- tried to do it in the MST action initially, but this caused MST
  flow errors, so did it in the view instead
  - and, on second thought, that makes more sense, as the action
    could be used outside of this UI interaction and probably
    shouldn't be so closely coupled to it

- (deps): add lodash.debounce to handle this
  • Loading branch information
agilgur5 committed Nov 24, 2019
1 parent 4d55f85 commit aadeec1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion components/mainView.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { StatusBar, View, Text, TextInput, SectionList } from 'react-native'
import { inject, observer } from 'mobx-react'
import debounce from 'lodash.debounce'

import MangaList from './mangaList.js'
import PageList from './pageList.js'
Expand Down Expand Up @@ -42,7 +43,7 @@ export default class MainView extends React.Component {
sections={[
{
title: 'Search...',
props: { onChangeText: submitQuery },
props: { onChangeText: debounce(submitQuery, 200) },
data: [{ mangas: searched, onSelect: selectManga }]
},
{
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dependencies": {
"cheerio-without-node-native": "^0.20.2",
"expo": "^33.0.0",
"lodash.debounce": "^4.0.8",
"mobx": "^5.9.4",
"mobx-react": "^5.2.5",
"mobx-state-tree": "^3.14.0",
Expand Down

0 comments on commit aadeec1

Please sign in to comment.