Skip to content

Instantly share code, notes, and snippets.

@MikeRyanDev
Created October 28, 2016 22:51
Show Gist options
  • Save MikeRyanDev/7a745515e48aff2c7ed1469cb0340e47 to your computer and use it in GitHub Desktop.
Save MikeRyanDev/7a745515e48aff2c7ed1469cb0340e47 to your computer and use it in GitHub Desktop.
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