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
Codegen App Injector / remove ReflectiveInjector and Reflector for offline compile #8997
Comments
/cc @mhevery |
Other changes agreed upon:
|
Reviewed with @tbosch and agreeing with the approach. |
Please provide an illustration of how this affects the way I bootstrap my app and how I provide to components (especially Imagine this (partial) application (semi-pseudo-coded):
|
@wardbell |
That's what we all wanted to hear :-) |
The pattern of a config that combines a set of statically known providers with a set of unknown providers is also usable for defining the configuration of a library. E.g.
This corresponds to the pattern of creating provider functions like this
However, in this case, the config is only part of the total config of an application. The encapsulation into a
These benefits show more the more input tokens a library has The following proposes a way to compose configurations:
I.e. we support method injection to create Config objects and automatically include the static providers of these configs in the main injector as well. In components, configs can also be used as follows:
Configs can be included in other configs or providers of components / directives via |
Note from Igor: Right now we only have |
Maybe we can determine the argument to
|
This is jibberish to me. I have no idea what problem we're solving or what the consequences are. I'm getting feedback from community confirming that this mystifies ... and frightens ... that community. This proposal adds new terms and complexities that we were previously unaware of. Where do we go to find out whether this is important and what it means? |
The proposal provides better encapsulation and better static analysis for libraries/modules, the tradeoff is adding more depth into libraries making it harder to understand them which has an impact since their usually OS projects. The result might be simple library integration for the end user. I admit it looks complex and a lot of new terms for DI. |
This is just adding them, but not using them yet for bootstrap. Related to angular#8997
This is just adding them, but not using them yet for bootstrap. Related to angular#8997
This is just adding them, but not using them yet for bootstrap. Related to angular#8997
This is just adding them, but not using them yet for bootstrap. Related to angular#8997
@tbosch can you rewrite @wardbell 's example here #8997 (comment) with offline compilation. I think the only thing which needs to be change is the |
@wardbell's example would look like this with the current offline compilation:
After this issue, offline compilation would look like this:
I.e. calls to |
@tbosch I think we should change |
@mhevery The likely obstacle there is that there is already an |
Dear ReaderI you are like me, this issue was both confusing and frightening. What's it about? In the space of a month we went from @mhevery was kind enough to help me better understand (not fully understand) what this is about and the consequences for our code. My goal in this note is to corral the issue and reduce our (my?) degree of concern. _This is my interpretation of our conversation. I'll update this note if I learn that I've got it wrong._ This change matters only for offline compilationOur application does not have to change if it will always compile at runtime. See the app sample above and @mhevery's assurance on that score. Of course most of us want our apps to be compilable offline. We'd feel foolish if we deliberately wrote apps that couldn't use the offline compiler. So this point isn't all that comforting. Fortunately ... No change to providers for our componentsI'm not ready to describe the change yet. I'll get to that. What we need to know is that we keep writing components the way we've been taught. The
Notice that I'm specifying a provider here in the component metadata ... exactly as I did before! I'm not using that The
|
@wardbell Thank you so much for that, you answered exactly all the questions I had about this change. Thanks, seriously. (I know the +1 exists, but I can't express with it how much I appreciate your comment). PS: sorry for the noise. |
@ericmartinezr I wrote it for you ... and everyone like you ... which is to say ... everyone like me ;-) Glad you appreciated it. |
Since it is related to offline compilation context only, Can we call it |
@tapas4java It actually has other use cases that I have not covered and that are not limited to offline compiler. So I don't think that's a healthy move. |
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
We talked about this internally, and concluded that we don't do the part that allows to reuse |
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
@tbosch To clarify, the plan had been that we would be able to use the same
Are these use cases off the table? For now? Forever? |
@wardbell We needed this to code gen the injectors. The benefit would be faster startup and smaller payload. For now we decided to keep the reflective injectors. We may revisit this at some later point in time. |
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
This commit is just adding them, but not using them yet for bootstrap. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
Introduce @InjectorModule and generate `InjectorFactory`s out of them. Support using `@InjectorModule`s in any place where providers are supported. Related to angular#8997
We have |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Angular is already generating Injectors on elements for components. We would like to have the same approach for the injector used for bootstrapping and the injector used for dynamic component loading.
With this, we no longer need any metadata about classes / functions in offline compile mode, as all of the metadata (decorators) have been read during offline compile and converted into appropriate code. This means:
ReflectiveInjector
norReflector
/ReflectionCapabilities
reflect-metadata
polyfill anymore when during offline compile (2.1kb min gzipped)Impact for users:
Part of #6270
Input and output of the compilation
Declare injectors via a config class like this:
Via runtime or offline compile, we create a
InjectorFactory
that is usable like this:Usage with offline compilation
Usage with runtime compilation
Consequences
bootstrap(type, providers)
call in@angular/browser
as this uses theRuntimeCompiler
already, so it can also create a injector config class on the fly with the given providers. -> plunkers stay simpler.CompilerConfig
and maybe some other parameters.CompilerConfig
,and not provided via DI (this also unifies their configuration between offline and runtime compile).
Proposed changes to Angular besides the compiler changes
ReflectiveInjector
and move it to@angular/common
or into aseparate module as Angular itself does no more use it.
Reflector
andReflectionCapabilities
from@angular/core
to@angular/compiler
as thecompiler is the only place where these are used.
ComponentResolver
(anRuntimeCompiler
) part ofPlatformRef
and don't use DI to create the providers ofPlatformRef
. Still expose an injector inPlatformRef
which is just based on aMap
.CompilerConfig
and define them as arrays ofCompileIdentifierMetadata
so they can be used for offline and runtime compile.CompilerConfig
tobrowserPlatform()
as argument instead of getting it via DI.BrowserCompileConfig
class as some parts ofCompilerConfig
are implied by using the browser platform (e.g. that platform directives are always defined via their runtime types, i.e. the user only needs to provide an array of types instead ofCompileIdentifierMetadata
)The text was updated successfully, but these errors were encountered: