Skip to content

Instantly share code, notes, and snippets.

@ZackDeRose
ZackDeRose / cars.facade.ts
Last active January 16, 2019 04:16
cars.facade.ts
export abstract class CarsFacade {
protected _source: string;
loaded$ = this.store.select(carsQuery.getLoaded);
allCars$ = this.store.select(carsQuery.getAllCars);
selectedCars$ = this.store.select(carsQuery.getSelectedCars);
constructor(private store: Store<CarsState>) {}
protected loadAll() {
@ZackDeRose
ZackDeRose / car-list-facade.ts
Last active January 16, 2019 04:16
car-list-facade.ts
@Injectable()
export class CarsListFacade extends CarsFacade {
_source = 'Cars List';
constructor(private store$: Store<any>) {
super(store$);
}
}
describe('Foo Class', () => {
describe('constructor', () => {
const fooClassRef = Foo as any; // to pass typechecking
beforeEach(() => {
console.log(`start of beforeEach: ${fooClassRef._count}`);
fooClassRef._count = 0;
console.log(`end of beforeEach: ${fooClassRef._count}`);
});
@ZackDeRose
ZackDeRose / foo.ts
Created January 13, 2019 23:50
foo.ts
export class Foo {
private static _count = 0;
id: number;
constructor() {
this.id = ++Foo._count; // starts with 1
}
}
@ZackDeRose
ZackDeRose / snippet.adjust-sort.table.component.ts
Created July 18, 2018 04:07
AdjustSort() for "Angular CDK Table" article
adjustSort(key: string) {
if (this.sortKey$.value === key) {
if (this.sortDirection$.value === 'asc') {
this.sortDirection$.next('desc');
} else {
this.sortDirection$.next('asc');
}
return;
}
@ZackDeRose
ZackDeRose / snippet.column-with-sorting.table.component.html
Created July 18, 2018 04:04
Column Sorting for "Angular CDK Tables" article
<!-- Hero Name Column -->
<ng-container cdkColumnDef="name">
<th cdk-header-cell *cdkHeaderCellDef (click)="adjustSort('name')">
Hero Name
<span *ngIf="sortKey$.value === 'name'">
{{ sortDirection$.value === 'asc' ? '↥' : '↧' }}
</span>
</th>
<td cdk-cell *cdkCellDef="let row"> {{row.name}} </td>
</ng-container>
@ZackDeRose
ZackDeRose / snippet.searching-sorting.table.component.ts
Created July 18, 2018 04:02
Searching then sorting for "Angular CDK Tables" article
combineLatest(this.heroes$, this.searchFormControl.valueChanges, this.sortKey$, this.sortDirection$)
.subscribe(([changedHeroData, searchTerm, sortKey, sortDirection]) => {
const heroesArray = Object.values(changedHeroData);
let filteredHeroes: any[];
if (!searchTerm) {
filteredHeroes = heroesArray;
} else {
const filteredResults = heroesArray.filter(hero => {
return Object.values(hero).reduce((prev, curr) => {
@ZackDeRose
ZackDeRose / snippet.search-and-pagination.table.component.html
Created July 18, 2018 03:55
Template for Search and Pagination for "Angular CDK Tables" article
<div class="row">
<div class="col-6">
<div class="form-inline">
<div class="form-group">
<div class="input-group mr-3">
<input
type="text"
class="form-control"
placeholder="Search…"
[formControl]="searchFormControl">
@ZackDeRose
ZackDeRose / snippet.initializing-for-searching.tables.components.ts
Created July 18, 2018 03:45
Initializing Subjects for Searching from "Angular CDK Tables" article
combineLatest(this.heroes$, this.searchFormControl.valueChanges)
.subscribe(([changedHeroData, searchTerm]) => {
const heroesArray = Object.values(changedHeroData);
if (!searchTerm) {
this.tableDataSource$.next(heroesArray);
return;
}
const filteredResults = heroesArray.filter(hero => {
@ZackDeRose
ZackDeRose / app.module.ts
Created July 18, 2018 03:38
App.Module for reactive forms for "Angular CDK Tables" article
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import {CdkTableModule} from '@angular/cdk/table';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {NgbModule} from '@ng-bootstrap/ng-bootstrap';
import { AppComponent } from './app.component';
import { TableComponent } from './table/table.component';