Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

docs(guide/Running in Production): ng-strict-di #9908

Closed
wants to merge 5 commits into from
Closed

docs(guide/Running in Production): ng-strict-di #9908

wants to merge 5 commits into from

Conversation

kentcdodds
Copy link

Adding note about Strict DI mode.

Adding note about Strict DI mode.

Using strict di mode in your production application will throw errors when a injectable
function is not
[annotated implicitly](https://docs.angularjs.org/guide/di#dependency-annotation#implicit-annotation).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use the {@link } helper?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure, I'll look at how to do that. Thanks!

This will force you to make sure that your injectable functions are implicitely annotated
which will improve angular's performance when injecting dependencies in your injectable
functions because it doesn't have to dynamically discover a function's dependencies.
It is recommended to automate the implicite annotation via a tool like
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: implicit

@mary-poppins
Copy link

I'm sorry, but I wasn't able to verify your Contributor License Agreement (CLA) signature. CLA signature is required for any code contributions to AngularJS.

Please sign our CLA and ensure that the CLA signature email address and the email address in this PR's commits match.

If you signed the CLA as a corporation, please let us know the company's name.

Thanks a bunch!

PS: If you signed the CLA in the past then most likely the email addresses don't match. Please sign the CLA again or update the email address in the commit of this PR.
PS2: If you are a Googler, please sign the CLA as well to simplify the CLA verification process.

I think this is how it works :-/ Not sure how to test it though...
Using strict di mode in your production application will throw errors when a injectable
function is not
{@link di#implicit-annotation annotated implicitly}.
This will force you to make sure that your injectable functions are implicitely annotated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: implicitly

@kentcdodds
Copy link
Author

Thanks @gkalpak. Hopefully we're good now!

This will force you to make sure that your injectable functions are implicitly annotated
which will improve angular's performance when injecting dependencies in your injectable
functions because it doesn't have to dynamically discover a function's dependencies.
It is recommended to automate the implicit annotation via a tool like
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't necessarily something we'd recommend, because these tools just don't do a very good job.

Also, I'd be questionable about the "performance benefit", we've never measured a performance benefit and that was never the intent of strict-DI --- it's really a debugging tool, that's about it. The main benefit of using it in production is so that you can be sure your minified scripts won't be broken terribly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've built countless apps in angular using ng-annotate. When you say they don't do a very good job, I'm a little lost... It works really well... Especially since the alternative is to either explicitly annotate yourself (just realized I was using the opposite word for what I meant, this should say "automate the explicit annotation" I'll fix that...) or go with implicit annotation which is less performant and not minification safe.

Also, strict-di mode is more than a debugging tool. It encourages (enforces) explicit annotation which does have pretty significant performance gains over implicit (see jsperf) so I think it's good to encourage the use of it in production.

I'm going to make some wording corrections, but I definitely feel like this is something that we should be recommending for use in production...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why they don't work very well, is that they only are able to figure out certain cases where it's clear that stuff can be annotated correctly. They work considerably less well for other constructs people like to use.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, and I use such constructs in many cases. But it's very easy to work around. Much easier than managing the annotations myself. Plus, on the di guide we're already recommending using ng-annotate..........

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright alright, but you should at least make a reference to the real reasons why we added strictDI --- it's there to help you make sure that your code will work when minified

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note added.

Kent C. Dodds added 2 commits November 5, 2014 11:46
Implicit annotation was the opposite of what we're going for here (explicit)
Adding note about the purpose of strict di mode.
@caitp
Copy link
Contributor

caitp commented Nov 5, 2014

alright, works for me

@caitp caitp closed this in da96054 Nov 5, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants