-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use
ReplaySubject
instead of BehaviorSubject
in RawConfigService
.
- Loading branch information
Showing
1 changed file
with
4 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,29 +18,21 @@ | |
*/ | ||
|
||
import { cloneDeep, isEqual, isPlainObject } from 'lodash'; | ||
import { BehaviorSubject, Observable } from 'rxjs'; | ||
import { distinctUntilChanged, filter, map } from 'rxjs/operators'; | ||
import { Observable, ReplaySubject } from 'rxjs'; | ||
import { distinctUntilChanged, map } from 'rxjs/operators'; | ||
import typeDetect from 'type-detect'; | ||
|
||
import { Config } from './config'; | ||
import { ObjectToConfigAdapter } from './object_to_config_adapter'; | ||
import { getConfigFromFiles } from './read_config'; | ||
|
||
// Used to indicate that no config has been received yet | ||
const notRead = Symbol('config not yet read'); | ||
|
||
export class RawConfigService { | ||
/** | ||
* The stream of configs read from the config file. Will be the symbol | ||
* `notRead` before the config is initially read, and after that it can | ||
* potentially be `null` for an empty yaml file. | ||
* The stream of configs read from the config file. | ||
* | ||
* This is the _raw_ config before any overrides are applied. | ||
* | ||
* As we have a notion of a _current_ config we rely on a BehaviorSubject so | ||
* every new subscription will immediately receive the current config. | ||
*/ | ||
private readonly rawConfigFromFile$ = new BehaviorSubject<any>(notRead); | ||
private readonly rawConfigFromFile$ = new ReplaySubject<number>(1); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
azasypkin
Author
Member
|
||
|
||
private readonly config$: Observable<Config>; | ||
|
||
|
@@ -50,7 +42,6 @@ export class RawConfigService { | |
new ObjectToConfigAdapter(rawConfig) | ||
) { | ||
this.config$ = this.rawConfigFromFile$.pipe( | ||
filter(rawConfig => rawConfig !== notRead), | ||
// We only want to update the config if there are changes to it. | ||
distinctUntilChanged(isEqual), | ||
map(rawConfig => { | ||
|
Kind of surprised TypeScript isn’t complaint about this being a ReplaySubject of numbers that is receiving rawConfig objects.