Skip to content

Commit a61036e

Browse files
committed
feat: pipe only loads necessary dependencies
When using multiple scopes, Transloco pipe will derive scope from the key and only load dependencies for that scope. Closes jsverse#394
1 parent a04d1fb commit a61036e

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

projects/ngneat/transloco/src/lib/transloco.pipe.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,20 @@ export class TranslocoPipe implements PipeTransform, OnDestroy {
5555
active: activeLang
5656
});
5757

58-
return Array.isArray(this.providerScope)
59-
? forkJoin(
60-
(<TranslocoScope[]>this.providerScope).map(providerScope => this.resolveScope(lang, providerScope))
61-
)
62-
: this.resolveScope(lang, this.providerScope);
58+
let resolvedScope;
59+
60+
if (Array.isArray(this.providerScope)) {
61+
const keyPrefix = key.split('.')[0];
62+
const derivedScope = this.providerScope.find(s =>
63+
typeof s === 'string' ? s === keyPrefix : s.alias === keyPrefix || s.scope === keyPrefix
64+
);
65+
66+
resolvedScope = this.resolveScope(lang, derivedScope);
67+
} else {
68+
resolvedScope = this.resolveScope(lang, this.providerScope);
69+
}
70+
71+
return resolvedScope;
6372
}),
6473
listenOrNotOperator(this.listenToLangChange)
6574
)

0 commit comments

Comments
 (0)