- プログラミングの抽象化に関する精神論
- 厳密な定義はない
- いくつかの抽象化の手法をグループ化して名前をつけてあるだけ
- ソースコードのフレキシビリティを高めるためのソースコードのデザイン
- いいデザインにはセンスが必要
- 鍛える
- フレキシビリティ
| import { BrowserModule } from '@angular/platform-browser'; | |
| import { NgModule } from '@angular/core'; | |
| // Import NGSW module | |
| import { ServiceWorkerModule } from '@angular/service-worker'; | |
| import { AppComponent } from './app.component'; | |
| @NgModule({ | |
| declarations: [ | |
| AppComponent |
| <div *ngFor="let user of (users$ | async) as users; index as i"> | |
| <span>{{ i + 1 }} / users.length</span> | |
| <span>{{ user.name }}</span> | |
| </div> |
| <div *ngIf="user$ | async as user; else userNotFound"> | |
| <p>{{ user.name }}</p> | |
| <p>{{ user.age }}</p> | |
| <img [src]="user.icon"> | |
| </div> | |
| <ng-template #userNotFound> | |
| <p>not found</p> | |
| </ng-template> |
| <div *ngIf="user$ | async as user"> | |
| <p>{{ user.name }}</p> | |
| <p>{{ user.age }}</p> | |
| <img [src]="user.icon"> | |
| </div> |
| <div *ngIf="show; then thenBlock; else elseBlock"></div> | |
| <ng-template #thenBlock>show === true</ng-template> | |
| <ng-template #elseBlock>show === false</ng-template> |
| <div *ngIf="show; else elseBlock">show === true</div> | |
| <ng-template #elseBlock>show === false</ng-template> |
| @Component({ | |
| selector: 'ng-if-then', | |
| template: ` | |
| <button (click)="switchPrimary()">Switch Template</button> | |
| <div *ngIf="show; then thenBlock"></div> | |
| <ng-template #primaryBlock>Primary</ng-template> | |
| <ng-template #secondaryBlock>Secondary</ng-template> | |
| ` | |
| }) | |
| class NgIfThenElse implements OnInit { |
| <div *ngIf="show; then thenBlock">ignored</div> | |
| <ng-template #thenBlock>show === true</ng-template> |
| export class AwesomeCounter extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({mode: 'open'}); | |
| this.state = {}; | |
| } | |
| connectedCallback() { | |
| this.setState({count: 0}); |