From 853d62096de00d343129669f6e44106e851b6a07 Mon Sep 17 00:00:00 2001 From: Etienne Lemay Date: Mon, 5 Sep 2022 23:47:10 -0400 Subject: [PATCH] Log warning in console to hint about `init` not being called yet --- packages/emoji-mart/src/config.js | 9 ++++++++- packages/emoji-mart/src/helpers/search-index.js | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/emoji-mart/src/config.js b/packages/emoji-mart/src/config.js index 6103c2f1f..9423539d2 100644 --- a/packages/emoji-mart/src/config.js +++ b/packages/emoji-mart/src/config.js @@ -25,8 +25,9 @@ async function fetchJSON(src) { let promise = null let initCallback = null +let initialized = false -export function init(options) { +export function init(options, { caller } = {}) { promise || (promise = new Promise((resolve) => { initCallback = resolve @@ -34,12 +35,18 @@ export function init(options) { if (options) { _init(options) + } else if (caller && !initialized) { + console.warn( + `\`${caller}\` requires data to be initialized first. Promise will be pending until \`init\` is called.`, + ) } return promise } async function _init(props) { + initialized = true + let { emojiVersion, set, locale } = props emojiVersion || (emojiVersion = PickerProps.emojiVersion.value) set || (set = PickerProps.set.value) diff --git a/packages/emoji-mart/src/helpers/search-index.js b/packages/emoji-mart/src/helpers/search-index.js index e33c842c5..dc172d0d6 100644 --- a/packages/emoji-mart/src/helpers/search-index.js +++ b/packages/emoji-mart/src/helpers/search-index.js @@ -19,11 +19,11 @@ function reset() { Pool = null } -async function search(value, { maxResults } = {}) { +async function search(value, { maxResults, caller } = {}) { if (!value || !value.trim().length) return null maxResults || (maxResults = 90) - await init() + await init(null, { caller: caller || 'SearchIndex.search' }) const values = value .toLowerCase()