Skip to content

Commit

Permalink
refactor to reduce size of if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
jloleysens committed Jun 16, 2021
1 parent 65c0390 commit 01434af
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions x-pack/plugins/fleet/public/search_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ import { pagePathGetters } from './constants';

const packageType = 'package';

const createPackages$ = () =>
from(sendGetPackages()).pipe(
map(({ error, data }) => {
if (error) {
throw error;
}
return data?.response ?? [];
}),
shareReplay(1)
);

export const createPackageSearchProvider = (core: CoreSetup): GlobalSearchResultProvider => {
const coreStart$ = from(core.getStartServices()).pipe(
map(([coreStart]) => coreStart),
Expand All @@ -33,15 +44,7 @@ export const createPackageSearchProvider = (core: CoreSetup): GlobalSearchResult

const getPackages$ = () => {
if (!packages$) {
packages$ = from(sendGetPackages()).pipe(
map(({ error, data }) => {
if (error) {
throw error;
}
return data?.response ?? [];
}),
shareReplay(1)
);
packages$ = createPackages$();
}
return packages$;
};
Expand Down

0 comments on commit 01434af

Please sign in to comment.