Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable7] perf(NcEmojiPicker): decrease mounting time and memory by moving large constants initialization and storing out from instance's reactive data #4493

Merged
merged 1 commit into from Aug 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
56 changes: 37 additions & 19 deletions src/components/NcEmojiPicker/NcEmojiPicker.vue
Expand Up @@ -189,6 +189,29 @@ import { t } from '../../l10n.js'
import { Picker, Emoji, EmojiIndex } from 'emoji-mart-vue-fast'
import data from 'emoji-mart-vue-fast/data/all.json'

// Shared emoji index for all NcEmojiPicker instances
// Will be initialized on the first NcEmojiPicker creating
let emojiIndex

const i18n = {
search: t('Search emoji'),
notfound: t('No emoji found'),
categories: {
search: t('Search results'),
recent: t('Frequently used'),
smileys: t('Smileys & Emotion'),
people: t('People & Body'),
nature: t('Animals & Nature'),
foods: t('Food & Drink'),
activity: t('Activities'),
places: t('Travel & Places'),
objects: t('Objects'),
symbols: t('Symbols'),
flags: t('Flags'),
custom: t('Custom'),
},
}

export default {
name: 'NcEmojiPicker',
components: {
Expand Down Expand Up @@ -261,28 +284,23 @@ export default {
'select-data',
'unselect',
],

setup() {
// If this is the first instance of NcEmojiPicker - setup EmojiIndex
if (!emojiIndex) {
emojiIndex = new EmojiIndex(data)
}

return {
// Non-reactive constants
emojiIndex,
i18n,
}
},

data() {
return {
emojiIndex: new EmojiIndex(data),
search: '',
i18n: {
search: t('Search emoji'),
notfound: t('No emoji found'),
categories: {
search: t('Search results'),
recent: t('Frequently used'),
smileys: t('Smileys & Emotion'),
people: t('People & Body'),
nature: t('Animals & Nature'),
foods: t('Food & Drink'),
activity: t('Activities'),
places: t('Travel & Places'),
objects: t('Objects'),
symbols: t('Symbols'),
flags: t('Flags'),
custom: t('Custom'),
},
},
open: false,
}
},
Expand Down