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 { Component, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core'; | |
import { finalize } from 'rxjs/operators'; | |
@Component({ | |
selector: 'app-todos', | |
template: ` | |
<button (click)="loadTodos()">Load todos</button> | |
<app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
`, |
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 { Component, ChangeDetectionStrategy } from '@angular/core'; | |
@Component({ | |
selector: 'app-todos', | |
template: ` | |
<button (click)="loadTodos()">Load todos</button> | |
<app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
`, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) |
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 { Component } from '@angular/core'; | |
@Component({ | |
selector: 'app-todos', | |
template: ` | |
<app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
` | |
}) | |
export class TodosComponent { | |
public todos: Todo[] = []; |
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
// Save the original reference to setTimeout | |
const originalSetTimeout = window.setTimeout; | |
// Overwrite the API with a function which wraps callback in zone | |
window.setTimeout = function(callback, delay) { | |
// Invoke the original API but wrap the callback in zone | |
return originalSetTimeout( | |
// Wrap the callback method | |
Zone.current.wrap(callback), | |
delay | |
); |
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 'zone.js'; | |
import * as library from 'external-library'; | |
const zone = Zone.current.fork({ | |
name: 'myAwesomeZone', | |
onInvokeTask: (delegate, current, target, task, applyThis, applyArgs) => { | |
console.log('Preparing to run some "then" callback...'); | |
return delegate.invokeTask(target, task, applyThis, applyArgs); | |
}, | |
onInvoke: (delegate, current, target, callback, applyThis, applyArgs, source) => { |
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
const t0 = performance.now(); | |
for (let i = 0; i < 1e9; i++) {} | |
const t1 = performance.now(); | |
console.log(`"for" loop took ${t1 - t0}ms`); | |
setTimeout(() => { | |
const t0setTimeout = performance.now(); | |
for (let i = 0; i < 1e9; i++) {} | |
const t1setTimeout = performance.now(); | |
console.log(`"for" loop inside "setTimeout" took ${t1setTimeout - t0setTimeout}ms`); |
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
setTimeout(() => { | |
console.log('setTimeout.callback is invoked'); | |
}, 100); |
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 { ApplicationRef } from '@angular/core'; | |
const tick = ApplicationRef.prototype.tick; | |
ApplicationRef.prototype.tick = function() { | |
console.log(`I'm re-rendering the whole app...`); | |
return tick.call(this); | |
}; |
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 { NgModule } from '@angular/core'; | |
import { NgxsModule } from '@ngxs/store'; | |
import { NgxsSelectSnapshotModule } from '@ngxs-labs/select-snapshot'; | |
@NgModule({ | |
imports: [ | |
NgxsModule.forRoot(states), | |
NgxsSelectSnapshotModule.forRoot() | |
] | |
}) |
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 { SelectSnapshot } from '@ngxs-labs/select-snapshot'; | |
@Injectable({ providedIn: 'root' }) | |
export class UserService { | |
@SelectSnapshot(UserState.getUserId) | |
public id: number; | |
constructor(private http: HttpClient) {} | |
public getUser() { |