-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Support extending differs from root
NgModule
(#39981)
Differs tries to inject parent differ in order to support extending. This does not work in the 'root' injector as the provider overrides the default injector. The fix is to just assume standard set of providers and extend those instead. PR close #25015 Issue close #11309 `Can't extend IterableDiffers` Issue close #18554 `IterableDiffers.extend is not AOT compatible` (This is fixed because we no longer have an arrow function in the factory but a proper function which can be imported.) PR Close #39981
- Loading branch information
Showing
9 changed files
with
105 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
packages/core/test/change_detection/differs/keyvalue_differs_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {KeyValueDiffer, KeyValueDifferFactory, KeyValueDiffers, NgModule} from '@angular/core'; | ||
import {TestBed} from '@angular/core/testing'; | ||
|
||
|
||
describe('KeyValueDiffers', function() { | ||
it('should support .extend in root NgModule', () => { | ||
const DIFFER: KeyValueDiffer<any, any> = {} as any; | ||
const log: string[] = []; | ||
class MyKeyValueDifferFactory implements KeyValueDifferFactory { | ||
supports(objects: any): boolean { | ||
log.push('supports', objects); | ||
return true; | ||
} | ||
create<K, V>(): KeyValueDiffer<K, V> { | ||
log.push('create'); | ||
return DIFFER; | ||
} | ||
} | ||
|
||
|
||
@NgModule({providers: [KeyValueDiffers.extend([new MyKeyValueDifferFactory()])]}) | ||
class MyModule { | ||
} | ||
|
||
TestBed.configureTestingModule({imports: [MyModule]}); | ||
const differs = TestBed.inject(KeyValueDiffers); | ||
const differ = differs.find('VALUE').create(); | ||
expect(differ).toEqual(DIFFER); | ||
expect(log).toEqual(['supports', 'VALUE', 'create']); | ||
}); | ||
}); |