-
-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(transloco): support nested array of scopes #650
base: master
Are you sure you want to change the base?
feat(transloco): support nested array of scopes #650
Conversation
Run & review this pull request in StackBlitz Codeflow. |
provider: MaybeArray<TranslocoScope>; | ||
provider: TranslocoScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this was done unintentionally, scope resolver is not able to process array of scopes. There's no compilation error only because of isScopeObject
type guard, that is also not supposed to handle array of scopes
@@ -7,7 +7,7 @@ | |||
"declarationMap": true, | |||
"inlineSources": true, | |||
"types": [], | |||
"lib": ["dom", "es2018"] | |||
"lib": ["dom", "es2019"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be able to use Array.prototype.flat()
@shaharkazaz will you be able to look at this? An issue on our side appears to be quite serious. Appreciated in advance 🙏 |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Right now transloco is able to resolve only 1-level array of scopes. This works fine with straightforward approach when using
{ provide: TRANSLOCO_SCOPE, useValue: scope, multi: true }
. However, it might be needed to pass an array of scopes within single provider.What is the new behavior?
This change allows to use the following syntax
In my scenario there's a big amount of scopes that we're using. They're provided either as component or module providers. And there's a limitation related to Angular's injection hierarchy: it resolves ElementInjectors before ModuleInjectors and if TRANSLOCO_SCOPE is provided on the ElementInjector level, it won't grab module injectors at all. To overcome this I want to grab all parent scopes and provide them explicitly
This approach requires transloco to be able to work with nested arrays of scopes. This PR does not introduce any changes to existing behavior, only enhances it so that it is possible to provide arrays under
TRANSLOCO_SCOPE
Does this PR introduce a breaking change?
Setting
yes
as there's a change toMaybeArray
interface, that might not be compatible with all implementationsOther information