This file contains hidden or 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
class WidgetService { | |
constructor(private auth: AuthService, private apollo: Apollo){} | |
// 1. BAD PRACTICE: keeps a separate member variable as the | |
// subject that will get exposed to users | |
// of this class. This creates opportunity to simply | |
// call `next` whenever it is convenient instead of | |
// pipelining from the _source of truth_ observable to | |
// create the intended behavior. This creates | |
// misdirection away from the source of truth |
This file contains hidden or 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
export class WidgetService { | |
constructor( | |
private auth: AuthService, | |
private apollo: Apollo, | |
) {} | |
// 1. We still have a memoized member variable | |
// but this time it is an Observable (not a subject) | |
// and it gets created from piplining from our |
This file contains hidden or 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
// Fires immediately and then on an interval | |
timer(0, REFRESH_INTERVAL) | |
.pipe( | |
mergeMap(() => apollo.query({ query: gql`...` })), | |
map(result => result.data) | |
) | |
.subscribe(() => { | |
// fires once per http request | |
}); |
This file contains hidden or 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
const query = gql`...`; | |
timer(0, REFRESH_INTERVAL) | |
.pipe( | |
mergeMap(() => apollo.watchQuery({ query }).valueChanges), | |
map(result => result.data) | |
) | |
.subscribe(() => { | |
// ... | |
}); |
This file contains hidden or 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
const query = gql`...`; | |
apollo.watchQuery({ | |
query, | |
pollInterval: REFRESH_INTERVAL | |
}).valueChanges | |
.pipe( | |
map(result => result.data) | |
) | |
.subscribe(() => { | |
// ... |
This file contains hidden or 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
const query = gql`...`; | |
const watchQuery = apollo.watchQuery({ query }); | |
watchQuery.valueChanges | |
.pipe( | |
map(result => result.data) | |
) | |
.subscribe(() => { | |
// ... | |
}); |