This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Commit 7a1750a
robertmirro
fix(loader): module.decorator order of operations is now irrelevant
`module.decorator` is now processed via the configBlocks order of operations and:
1. no longer throws if declared before the provider being decorated
2. guarantees the correct provider will be decorated when multiple, same-name providers
are defined
(1) Prior to this fix, declaring `module.decorator` before the provider that it decorates
results in throwing an error:
```js
angular
.module('theApp', [])
.decorator('theFactory', theDecoratorFn)
.factory('theFactory', theFactoryFn);
// Error: [$injector:modulerr] Failed to instantiate module theApp due to:
// Error: [$injector:unpr] Unknown provider: theFactoryProvider
```
The result of this fix now allows for the declaration order above.
(2) Prior to this fix, declaring `module.decorator` before the final, same-named provider
results in that provider **not** being decorated as expected:
**NOTE:** Angular does not use provider name spacing, so the final declared provider is
selected if multiple, same-named providers are declared.
```js
angular
.module('theApp', [])
.factory('theFactory', theFactoryFn)
.decorator('theFactory', theDecoratorFn)
.factory('theFactory', theOtherFactoryFn);
// `theOtherFactoryFn` is selected as 'theFactory' provider but it is **not** decorated
// via `theDecoratorFn` as expected
```
The result of this fix ensures that `theOtherFactoryFn` will be decorated as expected when
using the declaration order above.
BREAKING CHANGE:
`module.decorator` declarations are now processed as part of the `module.config` queue
and may result in providers being decorated in a different order if `module.config` blocks
are also used to decorate providers via `$provide.decorator`.
For example, consider the following declaration order in which 'theFactory' is decorated by
both a `module.decorator` and a `$provide.decorator`:
```js
angular
.module('theApp', [])
.factory('theFactory', theFactoryFn)
.config(function($provide) {
$provide.decorator('theFactory', anotherDecoratorFn);
})
.decorator('theFactory', theDecoratorFn);
```
Prior to this fix, 'theFactory' provider would be decorated in the following order:
1. theDecoratorFn
2. anotherDecoratorFn
The result of this fix changes the order in which 'theFactory' is decorated because
now `module.decorator` declarations are processed in the same order as `module.config`
declarations:
1. anotherDecoratorFn
2. theDecoratorFn
Closes #123821 parent 1964620 commit 7a1750a
2 files changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
| 352 | + | |
| 353 | + | |
353 | 354 | | |
354 | 355 | | |
355 | | - | |
| 356 | + | |
356 | 357 | | |
357 | 358 | | |
358 | 359 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | 51 | | |
53 | 52 | | |
54 | 53 | | |
| |||
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
0 commit comments