Skip to content

Commit

Permalink
Fixed lazy loading cache
Browse files Browse the repository at this point in the history
  • Loading branch information
fboucquez committed Oct 20, 2020
1 parent 479a83c commit c1afc6d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/infrastructure/RepositoryFactoryHttp.ts
Expand Up @@ -80,11 +80,11 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
const networkRepo = this.createNetworkRepository();
this.url = url;
this.fetchApi = configs?.fetchApi;
this.networkType = configs?.networkType ? observableOf(configs.networkType) : this.cache(networkRepo.getNetworkType());
this.networkProperties = this.cache(this.createNetworkRepository().getNetworkProperties());
this.networkType = configs?.networkType ? observableOf(configs.networkType) : this.cache(() => networkRepo.getNetworkType());
this.networkProperties = this.cache(() => this.createNetworkRepository().getNetworkProperties());
this.epochAdjustment = configs?.epochAdjustment
? observableOf(configs.epochAdjustment)
: this.cache(
: this.cache(() =>
this.networkProperties.pipe(
map((property) => {
return DtoMapping.parseServerDuration(property.network.epochAdjustment ?? '-').seconds();
Expand All @@ -93,7 +93,7 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
);
this.generationHash = configs?.generationHash
? observableOf(configs.generationHash)
: this.cache(
: this.cache(() =>
this.createNodeRepository()
.getNodeInfo()
.pipe(map((b) => b.networkGenerationHashSeed)),
Expand All @@ -102,11 +102,11 @@ export class RepositoryFactoryHttp implements RepositoryFactory {
this.websocketInjected = configs?.websocketInjected;
this.networkCurrencies = configs?.networkCurrencies
? observableOf(configs.networkCurrencies)
: this.cache(new CurrencyService(this).getNetworkCurrencies());
: this.cache(() => new CurrencyService(this).getNetworkCurrencies());
}

cache<T>(delegate: Observable<T>): Observable<T> {
return defer(() => delegate).pipe(shareReplay(1));
cache<T>(delegate: () => Observable<T>): Observable<T> {
return defer(delegate).pipe(shareReplay(1));
}

createAccountRepository(): AccountRepository {
Expand Down

0 comments on commit c1afc6d

Please sign in to comment.