import { Initialized , Success } from '@abraham/remotedata' ; import { Dispatch } from 'redux' ; import { Member } from '../../models/member' ; import { subscribeToCollectionGroup , Subscription } from '../../utils/firestore' ; import { FETCH_MEMBERS , FETCH_MEMBERS_FAILURE , FETCH_MEMBERS_SUCCESS , MembersActions , } from './types' ; let subscription = new Initialized ( ) ; export const unsubscribe = ( ) => { if ( subscription instanceof Success ) { subscription . data ( ) ; } } ; export const fetchMembers = async ( dispatch ) => { if ( subscription instanceof Initialized ) { subscription = subscribeToCollectionGroup ( 'members' , ( ) => dispatch ( { type : FETCH_MEMBERS } ) , ( payload ) => dispatch ( { type : FETCH_MEMBERS_SUCCESS , payload } ) , ( payload ) => dispatch ( { type : FETCH_MEMBERS_FAILURE , payload } ) ) ; } } ;