Created
November 20, 2019 14:51
-
-
Save tzachbon/21a5cc6d5113a379a5a3686d255e6c63 to your computer and use it in GitHub Desktop.
WithObservable
This file contains hidden or 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
| import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core'; | |
| import { BehaviorSubject } from 'rxjs'; | |
| import { ReRenderOnChange, SetChecker, WithObservable } from '@intelligo.ai/bonfire'; | |
| @ReRenderOnChange() | |
| @Component({ | |
| selector: 'app-test', | |
| styles: [ | |
| ` | |
| .container { | |
| margin: 1rem; | |
| color: white; | |
| } | |
| ` | |
| ], | |
| changeDetection: ChangeDetectionStrategy.OnPush, | |
| template: ` | |
| <div class="container"> | |
| <button (click)="initRandomNumber()"> | |
| <h1>{{ (changed$ | async).showChange ? (changed$ | async).changeText : 'Start' }}</h1> | |
| </button> | |
| </div> | |
| `, | |
| }) | |
| export class TestComponent implements OnInit { | |
| @WithObservable() changed = { | |
| showChange: false, | |
| changeText: '' | |
| }; changed$: BehaviorSubject<any>; | |
| constructor( | |
| private cd: ChangeDetectorRef | |
| ) { } | |
| ngOnInit() { | |
| } | |
| initRandomNumber() { | |
| setTimeout(() => { | |
| this.changed.showChange = true; | |
| this.changed.changeText = 'New text WOW!'; | |
| }, 2200); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment