import { ActionType , createAction } from '@ulangi/ulangi-action' ; import { ErrorBag } from '@ulangi/ulangi-common/interfaces' ; import { EventBus , group , on , once } from '@ulangi/ulangi-event' ; export class AuthDelegate { private eventBus : EventBus ; public constructor ( eventBus ) { this . eventBus = eventBus ; } public signIn ( email , password , callback ) { this . eventBus . pubsub ( createAction ( ActionType . USER__SIGN_IN , { email , password , } ) , group ( on ( ActionType . USER__SIGNING_IN , callback . onSigningIn ) , once ( ActionType . USER__SIGN_IN_SUCCEEDED , callback . onSignInSucceeded ) , once ( ActionType . USER__SIGN_IN_FAILED , ( errorBag ) : void => callback . onSignInFailed ( errorBag ) ) ) ) ; } public signInAsGuest ( callback ) { this . eventBus . pubsub ( createAction ( ActionType . USER__SIGN_IN_AS_GUEST , null ) , group ( on ( ActionType . USER__SIGNING_IN_AS_GUEST , callback . onSigningInAsGuest ) , once ( ActionType . USER__SIGN_IN_AS_GUEST_SUCCEEDED , callback . onSignInAsGuestSucceeded ) , once ( ActionType . USER__SIGN_IN_AS_GUEST_FAILED , ( errorBag ) : void => callback . onSignInAsGuestFailed ( errorBag ) ) ) ) ; } public signUp ( email , password , confirmPassword , callback ) { this . eventBus . pubsub ( createAction ( ActionType . USER__SIGN_UP , { email , password , confirmPassword , } ) , group ( on ( ActionType . USER__SIGNING_UP , callback . onSigningUp ) , once ( ActionType . USER__SIGN_UP_SUCCEEDED , callback . onSignUpSucceeded ) , once ( ActionType . USER__SIGN_UP_FAILED , ( errorBag ) : void => callback . onSignUpFailed ( errorBag ) ) ) ) ; } }