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
export class CountriesService implements Mutateble<Country> { | |
public mutateSource( | |
countries: Country[], | |
key: keyof Country, | |
value: Country[keyof Country] | |
): Country[] { | |
countries.forEach((country) => { | |
country[key] = value; | |
}); // BAD | |
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 userToRemoveIndex = this.users.indexOf(user); | |
this.users = this.users.filter((_, index) => { | |
return index !== userToRemoveIndex; | |
}); // BAD | |
this.users = [ | |
...this.users.slice(0, userToRemoveIndex), | |
...this.users.slice(userToRemoveIndex + 1) | |
]; // BAD |
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
function reducer(state: number[]) { | |
const newState = [...state]; // BAD | |
const newState = [].concat(state); // BAD | |
const newState = state.slice(); // BEST | |
} |
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
export class ChartComponent { | |
public async ngOnInit(): Promise<void> { | |
const { Chart } = await import('chart.js'); | |
this.zone.runOutsideAngular(() => { | |
new Chart(...); | |
}); | |
} | |
} |
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
{ | |
"extends": "../tsconfig.json", | |
"compilerOptions": { | |
"module": "esnext" | |
} | |
} |
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
@Injectable() | |
export class TodosResolver implements Resolve<Todo[]> { | |
private todos: Todo[] = []; | |
constructor(private todoService: TodoService) {} | |
public resolve(): Todo[] | Observable<Todo[]> { | |
if (this.todos.length) { | |
return this.todos; | |
} |
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 routes: Routes = [ | |
{ | |
path: 'todos', | |
component: TodosComponent, | |
resolve: { | |
todos: TodosResolver | |
} | |
} | |
]; |
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
@Injectable() | |
export class TodosResolver implements Resolve<Todo[]> { | |
constructor(private todoService: TodoService) {} | |
public resolve(): Observable<Todo[]> { | |
return this.todoService.getTodos(); | |
} | |
} |
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'; | |
import { ActivatedRoute } from '@angular/router'; | |
@Component({ | |
selector: 'app-todos', | |
template: ` | |
<app-todo *ngFor="let todo of todos" [todo]="todo"></app-todo> | |
` | |
}) | |
export class TodosComponent { |