Skip to content

Instantly share code, notes, and snippets.

@tzachbon
Last active November 20, 2019 14:43
Show Gist options
  • Select an option

  • Save tzachbon/f514e25dcf02c2bf95e2e4bf339a0913 to your computer and use it in GitHub Desktop.

Select an option

Save tzachbon/f514e25dcf02c2bf95e2e4bf339a0913 to your computer and use it in GitHub Desktop.
SetChecker
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>Click Here To Start!</h1></button>
<h3 *ngFor="let num of randomNumbers">
{{num.newNumber}}
</h3>
</div>
`,
})
export class TestComponent implements OnInit {
@SetChecker() randomNumbers = [];
constructor(
private cd: ChangeDetectorRef
) { }
ngOnInit() {
}
initRandomNumber() {
setTimeout(() => {
this.randomNumbers = [...new Array(5)].map(e => ({ newNumber: 0 }));
setTimeout(() => {
this.randomNumbers[0].newNumber = 40;
}, 2000);
}, 2200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment