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

Add getAllNativeEmojis to database #293

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hpeebles
Copy link

We have a use case where we'd like to synchronously determine if a string is a single emoji.

By adding getAllNativeEmojis, we can load all of the emoji unicode strings into a Set, solving our problem.

@nolanlawson
Copy link
Owner

Thanks for the PR! I think though, that this is not quite the implementation I would propose to solve this problem.

One of my main design decisions with emoji-picker-element was to use IndexedDB, to avoid having all emoji in memory. With getAllNativeEmojis, we are encouraging people to read the entire database into memory, which obviates a major benefit of IndexedDB.

Lookig at your code, it seems that originally you implemented isSingleEmoji() using (await emojiDatabase.getEmojiByUnicodeOrName(text)) !== null. This seems to me to be the appropriate, IDB-friendly approach. You're not reading the whole DB into memory, but instead leveraging the database's built-in index.

Why did you find that you needed synchronous access instead?

@hpeebles
Copy link
Author

We are building a chat app and we want to increase the size of messages which contain only a single emoji.

So each time we render a message we check if its text matches with an emoji from the emoji picker db.

The first implementation of this was async where we would render the message, then check if it was a single emoji, and resize it if so. But obviously that caused issues where users would end up in slightly the wrong scroll position after the resizing.

We could get around this though by performing the isSingleEmoji check higher up within the code where the messages are fetched which is already async. I'll give that a try a bit later and see how it looks / performs.

@dumptyd
Copy link

dumptyd commented Nov 1, 2022

We have a use case for this too. I'm implementing an input rule for adding emojis with colon wrapped shortcodes and I have to determine whether the typed shortcode matches any emojis; but handling this in ProseMirror requires synchronous processing which is not possible with the current API.

With getAllNativeEmojis, I can get the emoji list before rendering the editor and that should solve my issue.

@nolanlawson
Copy link
Owner

@dumptyd I still feel this is the wrong way to go about it. Or at the very least, the IndexedDB query should only query the keys (unicode/shortcode) rather than the values (full-fat emoji data).

I can maybe picture an API like getAllShortcodes(). Then you can build a Trie data structure out of it or something (outside of the scope of this project). Note that for unicode, you can use emoji-regex, so I don't see much need to expose that.

Or open a PR on ProseMirror to support async processing. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants