Skip to content

Instantly share code, notes, and snippets.

View yannickglt's full-sized avatar

Yannick Galatol yannickglt

View GitHub Profile

Keybase proof

I hereby claim:

  • I am yannickglt on github.
  • I am yannickglt (https://keybase.io/yannickglt) on keybase.
  • I have a public key ASB8a75JKXkABO72ZSTU-no1rhw9XHcfvajybQJK4nye8wo

To claim this, I am signing this object:

@yannickglt
yannickglt / lazy-getter-usage.component.ts
Created May 27, 2020 09:55
Lazy getter in Angular components
// Avoid useless computations and combine the property and its initialization method
// Live demo at stackblitz.com/edit/angular-lazy-getter
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { LazyGetter } from 'lazy-get-decorator';
@Component({
selector: 'lazy-getter-usage',
template: `
<h1>{{ sayHelloWithLazyGetter }}</h1>
<h1>{{ sayHelloWithoutLazyGetter() }}</h1>
@yannickglt
yannickglt / map.pipe.ts
Created May 27, 2020 09:15
Generic pure Angular pipe
// A safe way to call methods in templates
// Live demo @ https://stackblitz.com/edit/angular-generic-map-pipe
import { Pipe, PipeTransform } from "@angular/core";
// Methods passed to the map pipe cannot (and should not) use the `this` keyword from components. Otherwise, it would not be a pure pipe.
@Pipe({ name: "map" })
export class MapPipe implements PipeTransform {
public transform<T, R>(
thisArg: T,
project: (t: T, ...others: any[]) => R,
@yannickglt
yannickglt / javascript-addition-vs-lodash-add.js
Created March 23, 2017 21:27
Pure javascript addition vs Lo-Dash add method
// With "+" operator
1 + undefined
// NaN
undefined + undefined
// NaN
"1" + "2"
// "12"