Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Refactor implemention of setEmojiSelection #34

Open
justin0022 opened this issue Feb 1, 2019 · 0 comments
Open

Refactor implemention of setEmojiSelection #34

justin0022 opened this issue Feb 1, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@justin0022
Copy link
Member

justin0022 commented Feb 1, 2019

const setEmojiSelection = emoji => {
let selectedEmojis = state.responses.selectedEmojis
if (selectedEmojis.map(e => e.emojiId).includes(emoji.id)) {
state.responses.selectedEmojis = selectedEmojis.filter(e => e.emojiId !== emoji.id)
} else {
const emojiElem = document.getElementById(emoji.id)
const icon = emojiElem.childNodes[0].innerHTML
selectedEmojis.push({
emojiId: emoji.id,
emojicon: icon
})
}
}

I don't like this implementation. It's hard to read, and for some reason

selectedEmojis = selectedEmojis.filter(e => e.emojiId !== emoji.id)

doesn't work. There must be a more pure way of implementing this.

@justin0022 justin0022 added the enhancement New feature or request label Feb 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant