Skip to content

Commit

Permalink
fix(core): disable getSources concurrent fix
Browse files Browse the repository at this point in the history
The fix doesn't work when multiple sources are used.
  • Loading branch information
francoischalifour committed Nov 20, 2020
1 parent 23e321b commit a558b5e
Showing 1 changed file with 20 additions and 27 deletions.
47 changes: 20 additions & 27 deletions packages/autocomplete-core/src/utils/getNormalizedSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,33 @@ import {
InternalAutocompleteSource,
} from '../types';

import { createConcurrentSafePromise } from './createConcurrentSafePromise';
import { noop } from './noop';

const runConcurrentSafePromiseForGetSources = createConcurrentSafePromise<
Array<AutocompleteSource<any>>
>();

export function getNormalizedSources<TItem>(
getSources: (
params: GetSourcesParams<TItem>
) => MaybePromise<Array<AutocompleteSource<TItem>>>,
options: GetSourcesParams<TItem>
): Promise<Array<InternalAutocompleteSource<TItem>>> {
return runConcurrentSafePromiseForGetSources(getSources(options)).then(
(sources) => {
return Promise.all(
sources.filter(Boolean).map((source) => {
const normalizedSource: InternalAutocompleteSource<TItem> = {
getItemInputValue({ state }) {
return state.query;
},
getItemUrl() {
return undefined;
},
onSelect({ setIsOpen }) {
setIsOpen(false);
},
onHighlight: noop,
...source,
};
return Promise.resolve(getSources(options)).then((sources) => {
return Promise.all(
sources.filter(Boolean).map((source) => {
const normalizedSource: InternalAutocompleteSource<TItem> = {
getItemInputValue({ state }) {
return state.query;
},
getItemUrl() {
return undefined;
},
onSelect({ setIsOpen }) {
setIsOpen(false);
},
onHighlight: noop,
...source,
};

return Promise.resolve(normalizedSource);
})
);
}
);
return Promise.resolve(normalizedSource);
})
);
});
}

0 comments on commit a558b5e

Please sign in to comment.