Skip to content

Instantly share code, notes, and snippets.

View ziuniecki's full-sized avatar
👨‍💻

Wojciech Chociej ziuniecki

👨‍💻
View GitHub Profile
@ziuniecki
ziuniecki / function-decorator-observable.ts
Created August 28, 2020 13:42
Function decorator with params
import { Observable } from 'rxjs';
export const ExampleDecorator: () => MethodDecorator = () => (target: unknown, propertyKey: string, descriptor: PropertyDescriptor) => {
const original: () => Observable<unknown> = descriptor.value;
descriptor.value = function(): Observable<unknown> {
try {
return original.apply(this, arguments).pipe();
} catch {
return original.apply(this, arguments);
}
@ziuniecki
ziuniecki / how-much-pipe.ts
Last active July 20, 2020 11:26
HowMuchPipe
import {Pipe, PipeTransform} from '@angular/core';
/**
* Pipe do określania słów jakie mają się pojawić po cyfrze np: 1 marka; 2 marki; 12 marek
* @example
* {{ 20 | howMuch:['marka', 'marki', 'marek']}}
*/
@Pipe({name: 'howMuch'})
export class HowMuchPipe implements PipeTransform {
/**
@ziuniecki
ziuniecki / decorator-with-params.ts
Last active January 30, 2019 19:43
Angular component custom decorator boilerplate with parameters
import {OnInit, Type} from '@angular/core';
/**
* Decorator with params for Angular components.
* InterfaceName is name of interface that declare required fields, which component should have.
* How to use:
* `
@DecoratorName(params)
@Component({
selector: 'app-example',