import { ActionType , createAction } from '@ulangi/ulangi-action' ; import { SetStatus } from '@ulangi/ulangi-common/enums' ; import { ErrorBag , Set } from '@ulangi/ulangi-common/interfaces' ; import { EventBus , group , on , once } from '@ulangi/ulangi-event' ; export class FetchSetDelegate { private eventBus : EventBus ; public constructor ( eventBus ) { this . eventBus = eventBus ; } public fetchSets ( setStatus , callback ) { this . eventBus . pubsub ( createAction ( ActionType . SET__FETCH , { setStatus } ) , group ( on ( ActionType . SET__FETCHING , callback . onFetching ) , once ( ActionType . SET__FETCH_SUCCEEDED , ( { setList } ) : void => callback . onFetchSucceeded ( setList ) ) , once ( ActionType . SET__FETCH_FAILED , ( errorBag ) : void => callback . onFetchFailed ( errorBag ) ) ) ) ; } public fetchAllSets ( callback ) { this . eventBus . pubsub ( createAction ( ActionType . SET__FETCH_ALL , null ) , group ( on ( ActionType . SET__FETCHING_ALL , callback . onFetchingAll ) , once ( ActionType . SET__FETCH_ALL_SUCCEEDED , ( { setList } ) : void => callback . onFetchAllSucceeded ( setList ) ) , once ( ActionType . SET__FETCH_ALL_FAILED , ( errorBag ) : void => callback . onFetchAllFailed ( errorBag ) ) ) ) ; } }