Skip to content

Allow select to work with promise #102

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bmooreitul
Copy link

@bmooreitul bmooreitul commented Apr 19, 2025

Modified the select method to work with promises while preserving the original functionality of inserting a string that wasn't a promise.

This allows for us to use the async prefix on the insert method when defining a custom insert method that gets passed to the options.

The reason this is necessary is because it enables us to execute an action asynchronously prior to inserting the new element. For example, creating a new tag, then modifying the insert content with the async response data.

Example Code:

mentions: {
  //OTHER CONFIG OPTIONS
  ...
  
  //USE A PROMISE TO CREATE A TAG BEFORE INSERTING
  insert: async function(item) {
  
    //CREATE A NEW TAG IF NEEDED
    item = await somePromise(item.name);

    //RETURN THE CONTENT
    return `<span>#${item.name}</span> `;
  },
},

Modified the select method to work with promises while preserving the original functionality of inserting a string that wasn't a promise.

This allows for us to use the `async` prefix on the insert method when defining a custom insert method that gets passed to the options. 

The reason this is necessary is because it enables us to execute an action asynchronously prior to inserting the new element. For example, creating a new tag, then modifying the insert content with the async response data.
Minified version that includes the promise support
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.

1 participant