Skip to content

Commit

Permalink
Use fold function for template context
Browse files Browse the repository at this point in the history
  • Loading branch information
fboeller committed Mar 8, 2021
1 parent d8ca804 commit 1410317
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ViewChild,
ViewContainerRef,
} from '@angular/core';
import { fold } from '../../functions/fold.function';
import { idle } from '../../loadable.constructors';
import {
getLoadingState,
Expand All @@ -34,13 +35,15 @@ export function setComponentInputs(
}

function loadableTemplateContext(loadable: Loadable<unknown>): object {
if (isLoaded(loadable)) {
return { value: loadable.value };
} else if (hasErrored(loadable)) {
return { error: loadable.error };
} else {
return {};
}
return fold(
{
idle: () => ({}),
loading: () => ({}),
loaded: (value) => ({ value }),
error: (error) => ({ error }),
},
loadable
);
}

export type TemplateRefs = {
Expand Down

0 comments on commit 1410317

Please sign in to comment.