mokkabonna / inquirer-autocomplete-prompt

Autocomplete prompt for inquirer
ISC License
354 stars 82 forks source link

Split source parameter into two functions #75

Closed Jameskmonger closed 4 years ago

Jameskmonger commented 6 years ago

At the moment, the source parameter is a function that takes in two parameters: answers and input

That means that if I want to use answers to decide which choices are available and input to sort them, I have to do it like this:

source: (answers, input) => {
    const choices = getChoicesFromAnswers(answers);

    return filterChoices(choices, input);
}

There is no way to set this up so that getChoicesFromAnswers doesn't get called every time input changes (without implementing caching myself)

It would be nice to have it split into two functions, the first takes in answers and returns another function which takes in input, the result of which is the filtering

source: (answers) => {
    const choices = getChoicesFromAnswers(answers);

    return (input) => filterChoices(choices, input);
}

That way getChoicesFromAnswers isn't called every time input changes

mokkabonna commented 4 years ago

Probably not a bad idea. Although I am reluctant to change it now.

You are better off doing some kind of caching yourself.