Browse Source

Use OnPush change detection strategy

tags/part_2
Kevin C. Coram 1 year ago
parent
commit
8802b52e54
Signed by: kevin GPG Key ID: 0342351B3D61AD35
4 changed files with 40 additions and 26 deletions
  1. +10
    -6
      apps/static-factory-methods/src/app/address-list/address-list.component.ts
  2. +12
    -8
      apps/static-factory-methods/src/app/address/address.component.ts
  3. +10
    -10
      apps/static-factory-methods/src/app/app.component.ts
  4. +8
    -2
      apps/static-factory-methods/src/app/name/name.component.ts

+ 10
- 6
apps/static-factory-methods/src/app/address-list/address-list.component.ts View File

@@ -1,4 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
} from '@angular/core';
import { FormArray } from '@angular/forms';
import { Address } from '@nested-forms/contact';
import { AddressComponent } from '../address/address.component';
@@ -6,7 +11,8 @@ import { AddressComponent } from '../address/address.component';
@Component({
selector: 'nested-forms-address-list',
templateUrl: './address-list.component.html',
styleUrls: ['./address-list.component.css']
styleUrls: ['./address-list.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AddressListComponent implements OnInit {
@Input() addressArray: FormArray;
@@ -23,9 +29,7 @@ export class AddressListComponent implements OnInit {
return list;
}

constructor() { }

ngOnInit() {
}
constructor() {}

ngOnInit() {}
}

+ 12
- 8
apps/static-factory-methods/src/app/address/address.component.ts View File

@@ -1,15 +1,21 @@
import { Component, OnInit, Input } from '@angular/core';
import { FormGroup, FormControl } from '@angular/forms';
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
} from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { Address } from '@nested-forms/contact';

@Component({
selector: 'nested-forms-address',
templateUrl: './address.component.html',
styleUrls: ['./address.component.css']
styleUrls: ['./address.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AddressComponent implements OnInit {
@Input() addressGroup: FormGroup;
static buildForm(addr: Address): FormGroup {
return new FormGroup({
line1: new FormControl(addr ? addr.line1 : ''),
@@ -20,9 +26,7 @@ export class AddressComponent implements OnInit {
});
}

constructor() { }

ngOnInit() {
}
constructor() {}

ngOnInit() {}
}

+ 10
- 10
apps/static-factory-methods/src/app/app.component.ts View File

@@ -1,17 +1,20 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import {
Contact,
ContactService,
} from '@nested-forms/contact';
ChangeDetectionStrategy,
Component,
OnDestroy,
OnInit,
} from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Contact, ContactService } from '@nested-forms/contact';
import { Subscription } from 'rxjs';
import { NameComponent } from './name/name.component';
import { AddressListComponent } from './address-list/address-list.component';
import { NameComponent } from './name/name.component';

@Component({
selector: 'nested-forms-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AppComponent implements OnInit, OnDestroy {
contact: Contact;
@@ -19,10 +22,7 @@ export class AppComponent implements OnInit, OnDestroy {

private subscription: Subscription;

constructor(
private service: ContactService,
private fb: FormBuilder,
) {}
constructor(private service: ContactService, private fb: FormBuilder) {}

public ngOnInit() {
this.subscription = this.service


+ 8
- 2
apps/static-factory-methods/src/app/name/name.component.ts View File

@@ -1,11 +1,17 @@
import {
ChangeDetectionStrategy,
Component,
Input,
OnInit,
} from '@angular/core';
import { FormControl, FormGroup } from '@angular/forms';
import { Component, OnInit, Input } from '@angular/core';
import { Name } from '@nested-forms/contact';

@Component({
selector: 'nested-forms-name',
templateUrl: './name.component.html',
styleUrls: ['./name.component.css']
styleUrls: ['./name.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NameComponent implements OnInit {
@Input() nameGroup: FormGroup;


Loading…
Cancel
Save