Skip to content

Instantly share code, notes, and snippets.

View nivrith's full-sized avatar
🎸
Recreational Mathemusician

Nivrith nivrith

🎸
Recreational Mathemusician
View GitHub Profile
@nivrith
nivrith / Truly Reactive Forms in Angular - Usage in Template.html
Created November 9, 2020 08:00
Truly Reactive Forms in Angular - Usage in Template
<ng-container *ngIf="form$ | async as form; else loading">
<form [formGroup]="form">
<div class="form-group">
<label for="">Title</label>
<input class="form-control" type="text" formControlName="title" />
</div>
<div class="form-group">
<label for="exampleFormControlSelect2">Body</label>
<textarea
class="form-control"
@nivrith
nivrith / Truly Reactive Forms in Angular - Observable of FormArray.ts
Last active November 9, 2020 10:50
Truly Reactive Forms in Angular - Observable of FormArray
export class AppComponent{
form: Observable<FormArray>;
constructor(private fb: FormBuilder) {}
ngOnInit() {
this.formArray$ = this.posts$.pipe(
map(posts => this.fb.array(posts.map(post => this.fb.group(post))))
<ng-container *ngIf="formArray$ | async as formArray; else loading">
<form>
<ng-container *ngFor="let formGroup of formArray.controls">
<div [formGroup]="formGroup">
<div class="form-group">
<label for="">Title</label>
<input class="form-control" type="text" formControlName="title" />
</div>
<div class="form-group">
<label for="exampleFormControlSelect2">Body</label>
@nivrith
nivrith / Truly Reactive Forms in Angular - Observables of User Input.ts
Last active November 9, 2020 09:21
Truly Reactive Forms in Angular - Observables of User Input
this.title$ = this.form$.pipe(
switchMap(form => form.controls.title.valueChanges.pipe(shareReplay(1)))
);
this.body$ = this.form$.pipe(
switchMap(form => form.controls.body.valueChanges.pipe(shareReplay(1))))
;
@nivrith
nivrith / Truly Reactive Angular Forms - Populating Forms with Async Default Values.ts
Last active November 9, 2020 10:40
Truly Reactive Angular Forms - Populating Forms with Async Default Values
...
form$: Observable<FormGroup>;
constructor(private fb: FormBuilder) {}
ngOnInit() {
post$ = this.store.select(postQuery.selectCurrentPost);
form$ = this.post$.pipe(map(post => this.fb.group(post)));
}
@nivrith
nivrith / Truly Reactive Forms - Observable of FormGroups.ts
Created November 9, 2020 09:38
Truly Reactive Forms - Observable of FormGroups
form$: Observable<FormGroup>;
@nivrith
nivrith / queue-1-of-7.ts
Created November 20, 2020 03:54
Make your own Custom Iterables in JavaScript
export class Queue<T> {
constructor(private length: number, private data: T[] = []) {}
}
@nivrith
nivrith / queue-2-of-7.ts
Last active November 20, 2020 03:57
Make your own iterables in javascript
export class Queue<T> {
constructor(private length: number, private data: T[] = []) {}
add(record) {
const length = this.data.unshift(record);
}
}
@nivrith
nivrith / queue-3-of-7.ts
Last active November 20, 2020 07:10
Make your own iterables in javascript
export class Queue<T> {
constructor(private length: number, private data: T[] = []) {}
add(record) {
const length = this.data.unshift(record);
if (length > this.length) {
this.remove();
}
}
@nivrith
nivrith / queue-4-of-7.ts
Created November 20, 2020 04:07
Make your own iterables in javascript
export class Queue<T> {
constructor(private length: number, private data: T[] = []) {}
add(record) {
const length = this.data.unshift(record);
if (length > this.length) {
this.remove();
}
}