Skip to content

Commit

Permalink
feat: pipe only loads necessary dependencies
Browse files Browse the repository at this point in the history
When using multiple scopes, Transloco pipe will derive scope from the key and only load dependencies for that scope.

Closes jsverse#394
  • Loading branch information
kaitlynekdahl committed Jan 14, 2021
1 parent a04d1fb commit a61036e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions projects/ngneat/transloco/src/lib/transloco.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,20 @@ export class TranslocoPipe implements PipeTransform, OnDestroy {
active: activeLang
});

return Array.isArray(this.providerScope)
? forkJoin(
(<TranslocoScope[]>this.providerScope).map(providerScope => this.resolveScope(lang, providerScope))
)
: this.resolveScope(lang, this.providerScope);
let resolvedScope;

if (Array.isArray(this.providerScope)) {
const keyPrefix = key.split('.')[0];
const derivedScope = this.providerScope.find(s =>
typeof s === 'string' ? s === keyPrefix : s.alias === keyPrefix || s.scope === keyPrefix
);

resolvedScope = this.resolveScope(lang, derivedScope);
} else {
resolvedScope = this.resolveScope(lang, this.providerScope);
}

return resolvedScope;
}),
listenOrNotOperator(this.listenToLangChange)
)
Expand Down

0 comments on commit a61036e

Please sign in to comment.