Created
October 28, 2016 22:51
-
-
Save MikeRyanDev/7a745515e48aff2c7ed1469cb0340e47 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ApolloStore } from 'apollo-client'; | |
import { Store } from '@ngrx/store'; | |
import { skip } from 'rxjs/operator/skip'; | |
import { take } from 'rxjs/operator/take'; | |
export function toApolloStore(store: Store<any>): ApolloStore { | |
return { | |
subscribe(fn: () => void): () => void { | |
const futureStates$ = skip.call(store, 1); | |
const subscription = futureStates$.subscribe(() => fn()); | |
return () => subscription.unsubscribe(); | |
}, | |
getState(): any { | |
let lastState; | |
const lastState$ = take.call(store, 1); | |
lastState$.subscribe(state => lastState = state); | |
return lastState; | |
}, | |
dispatch(action: any) { | |
store.dispatch(action); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment