Skip to content

Commit 7cf605d

Browse files
committed
fix(ivy): Update Todo app to take advantage of optional injector
1 parent 8e0d74b commit 7cf605d

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

packages/core/test/bundling/todo/bundle.golden_symbols.json

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
[
2+
{
3+
"name": "BLOOM_SIZE"
4+
},
25
{
36
"name": "CIRCULAR$2"
47
},
@@ -29,6 +32,12 @@
2932
{
3033
"name": "IterableChangeRecord_"
3134
},
35+
{
36+
"name": "IterableDiffers"
37+
},
38+
{
39+
"name": "NG_ELEMENT_ID"
40+
},
3241
{
3342
"name": "NG_HOST_SYMBOL"
3443
},
@@ -176,6 +185,9 @@
176185
{
177186
"name": "_c9"
178187
},
188+
{
189+
"name": "_currentInjector"
190+
},
179191
{
180192
"name": "_devMode"
181193
},
@@ -218,6 +230,12 @@
218230
{
219231
"name": "bindingUpdated"
220232
},
233+
{
234+
"name": "bloomFindPossibleInjector"
235+
},
236+
{
237+
"name": "bloomHashBit"
238+
},
221239
{
222240
"name": "cacheMatchingDirectivesForNode"
223241
},
@@ -275,9 +293,6 @@
275293
{
276294
"name": "currentView"
277295
},
278-
{
279-
"name": "defaultIterableDiffers"
280-
},
281296
{
282297
"name": "defineComponent"
283298
},
@@ -302,6 +317,9 @@
302317
{
303318
"name": "directiveCreate"
304319
},
320+
{
321+
"name": "directiveInject"
322+
},
305323
{
306324
"name": "domRendererFactory3"
307325
},
@@ -380,6 +398,9 @@
380398
{
381399
"name": "getOrCreateElementRef"
382400
},
401+
{
402+
"name": "getOrCreateInjectable"
403+
},
383404
{
384405
"name": "getOrCreateNodeInjector"
385406
},
@@ -428,6 +449,9 @@
428449
{
429450
"name": "initChangeDetectorIfExisting"
430451
},
452+
{
453+
"name": "inject"
454+
},
431455
{
432456
"name": "injectTemplateRef"
433457
},
@@ -572,6 +596,12 @@
572596
{
573597
"name": "scheduleTick"
574598
},
599+
{
600+
"name": "searchMatchesQueuedForCreation"
601+
},
602+
{
603+
"name": "setCurrentInjector"
604+
},
575605
{
576606
"name": "setHostBindings"
577607
},

packages/core/test/bundling/todo/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {CommonModule, NgForOf, NgIf} from '@angular/common';
10-
import {ChangeDetectionStrategy, Component, EventEmitter, InjectFlags, Injectable, Input, IterableDiffers, NgModule, Output, createInjector, defineInjector, inject, ɵComponentDef as ComponentDef, ɵComponentType as ComponentType, ɵDirectiveDef as DirectiveDef, ɵDirectiveType as DirectiveType, ɵNgOnChangesFeature as NgOnChangesFeature, ɵdefaultIterableDiffers as defaultIterableDiffers, ɵdefineDirective as defineDirective, ɵinjectTemplateRef as injectTemplateRef, ɵinjectViewContainerRef as injectViewContainerRef, ɵmarkDirty as markDirty, ɵrenderComponent as renderComponent} from '@angular/core';
10+
import {ChangeDetectionStrategy, Component, EventEmitter, InjectFlags, Injectable, Input, IterableDiffers, NgModule, Output, createInjector, defineInjector, inject, ɵComponentDef as ComponentDef, ɵComponentType as ComponentType, ɵDirectiveDef as DirectiveDef, ɵDirectiveType as DirectiveType, ɵNgOnChangesFeature as NgOnChangesFeature, ɵdefaultIterableDiffers as defaultIterableDiffers, ɵdefineDirective as defineDirective, ɵdirectiveInject as directiveInject, ɵinjectTemplateRef as injectTemplateRef, ɵinjectViewContainerRef as injectViewContainerRef, ɵmarkDirty as markDirty, ɵrenderComponent as renderComponent} from '@angular/core';
1111

1212

1313
export class Todo {
@@ -23,7 +23,7 @@ export class Todo {
2323
}
2424
}
2525

26-
@Injectable()
26+
@Injectable({providedIn: 'root'})
2727
export class TodoStore {
2828
todos: Array<Todo> = [
2929
new Todo('Demonstrate Components'),
@@ -108,12 +108,9 @@ export class TodoStore {
108108
// changeDetection: ChangeDetectionStrategy.OnPush
109109
})
110110
export class ToDoAppComponent {
111-
todoStore: TodoStore;
112111
newTodoText = '';
113112

114-
// TODO(misko) Fix injection
115-
// constructor(todoStore: TodoStore) { this.todoStore = todoStore; }
116-
constructor() { this.todoStore = new TodoStore(); }
113+
constructor(public todoStore: TodoStore) {}
117114

118115
stopEditing(todo: Todo, editedTitle: string) {
119116
todo.title = editedTitle;
@@ -157,10 +154,7 @@ export class ToDoAppComponent {
157154
type: NgForOf,
158155
selectors: [['', 'ngFor', '', 'ngForOf', '']],
159156
factory: () => new NgForOf(
160-
injectViewContainerRef(), injectTemplateRef(),
161-
// TODO(misko): inject does not work since it needs to be directiveInject
162-
// inject(IterableDiffers, defaultIterableDiffers)
163-
defaultIterableDiffers),
157+
injectViewContainerRef(), injectTemplateRef(), directiveInject(IterableDiffers)),
164158
features: [NgOnChangesFeature({
165159
ngForOf: 'ngForOf',
166160
ngForTrackBy: 'ngForTrackBy',

0 commit comments

Comments
 (0)