Skip to content

Commit

Permalink
Don’t call useless emojisToShowFilter when undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneLem committed Apr 18, 2017
1 parent 046d489 commit 4a9497d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
30 changes: 17 additions & 13 deletions src/components/picker.js
Expand Up @@ -59,23 +59,27 @@ export default class Picker extends React.Component {
let isExcluded = props.exclude == undefined ? false : props.exclude.indexOf(category.name.toLowerCase()) > -1
if (!isIncluded || isExcluded) { continue }

let newEmojis = []
if (props.emojisToShowFilter) {
let newEmojis = []

for (let emoji of category.emojis) {
let unified = data.emojis[emoji].unified
for (let emoji of category.emojis) {
let unified = data.emojis[emoji].unified

if (props.emojisToShowFilter(unified)) {
newEmojis.push(emoji)
if (props.emojisToShowFilter(unified)) {
newEmojis.push(emoji)
}
}
}

if (newEmojis.length) {
let newCategory = {
emojis: newEmojis,
name: category.name,
}
if (newEmojis.length) {
let newCategory = {
emojis: newEmojis,
name: category.name,
}

this.categories.push(newCategory)
this.categories.push(newCategory)
}
} else {
this.categories.push(category)
}
}

Expand Down Expand Up @@ -395,6 +399,6 @@ Picker.defaultProps = {
native: Emoji.defaultProps.native,
sheetSize: Emoji.defaultProps.sheetSize,
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
emojisToShowFilter: (codePoint) => true,
emojisToShowFilter: null,
autoFocus: false,
}
2 changes: 1 addition & 1 deletion src/components/search.js
Expand Up @@ -37,6 +37,6 @@ Search.propTypes = {
Search.defaultProps = {
onSearch: (() => {}),
maxResults: 75,
emojisToShowFilter: () => true,
emojisToShowFilter: null,
autoFocus: false,
}
13 changes: 7 additions & 6 deletions src/utils/emoji-index.js
Expand Up @@ -92,16 +92,17 @@ function search(value, emojisToShowFilter = () => true, maxResults = 75) {
}
}

let filteredResults = null

if (results) {
filteredResults = results.filter((result) => emojisToShowFilter(data.emojis[result.id].unified))
if (filteredResults && filteredResults.length) {
filteredResults = filteredResults.slice(0, maxResults)
if (emojisToShowFilter) {
results = results.filter((result) => emojisToShowFilter(data.emojis[result.id].unified))
}

if (results && results.length) {
results = results.slice(0, maxResults)
}
}

return filteredResults
return results
}

export default { search, emojis: emojisList, emoticons: emoticonsList }

0 comments on commit 4a9497d

Please sign in to comment.