import { mergeMap, map, tap } from 'rxjs/operators';
import { Observable, of, from } from 'rxjs';
import { ofType, ActionsObservable } from 'redux-observable';
import { ApolloClient } from 'apollo-client';
import { EXTENSION_ACTION_TYPES } from '../constants';

export const openDocumentEpic: (action$: ActionsObservable<any>, state$: Observable<any>, { apolloClient }: { apolloClient: ApolloClient<any> }) => any
    = (action$, state$, { apolloClient }) => action$
        .pipe(
            ofType(EXTENSION_ACTION_TYPES.OPEN_DOCUMENT_EPIC),
            tap(() => console.log('action of type ', EXTENSION_ACTION_TYPES.OPEN_DOCUMENT_EPIC)),
            mergeMap(() => of({
                type: EXTENSION_ACTION_TYPES.OPEN_DOCUMENT,
            })),
        );
