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 { Directive, ElementRef, HostListener, Input, Renderer2 } from '@angular/core'; | |
import { ControlValueAccessor } from '@angular/forms'; | |
export function valueAccessor<T extends new (...args: any[]) => any>(component: T) { | |
return { | |
provide: NG_VALUE_ACCESSOR, | |
useExisting: forwardRef(() => component), | |
multi: true | |
}; | |
} |
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 { ChangeDetectionStrategy, Component, TemplateRef, ViewChild, ViewEncapsulation } from '@angular/core'; | |
@Component({ | |
selector: 'app-step', | |
template: '<ng-template><ng-content></ng-content></ng-template>', | |
encapsulation: ViewEncapsulation.None, | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) | |
export class StepComponent { | |
@ViewChild(TemplateRef, { static: true }) content!: TemplateRef<any>; |
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 inputMachine = Machine( | |
{ | |
id: 'input', | |
initial: 'pristine', | |
context: { | |
message: '', | |
}, | |
states: { | |
pristine: {}, | |
editing: {}, |
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
// T and E extends checking should be array for primitives support | |
// See https://mariusschulz.com/blog/conditional-types-in-typescript#distributive-conditional-types | |
type Exact<T, E> = T[] extends E[] | |
? E[] extends T[] | |
? T | |
: never | |
: never; | |
// Primitives | |
declare function exactStringOrBoolean<T>(input: Exact<T, string | boolean>): void; |
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
class SortedArray<T> { | |
static of<T>(array: Array<T>): SortedArray<T> { | |
return new SortedArray(array); | |
} | |
private readonly array: Array<T>; | |
private constructor(array: Array<T>, sortingWith?: (a: T, b: T) => number) { | |
this.array = Array.from(array).sort(sortingWith); | |
} |
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 interface MultiLanguage {} | |
export type Constructor<T> = new(...args: any[]) => T; | |
export type MultiLanguageCtor = Constructor<MultiLanguage>; | |
export interface TranslationAvailable extends PipeTransform, OnDestroy { | |
translate: TranslateService; | |
cd: ChangeDetectorRef; | |
} |
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 function convertFileToBase64(file: File): Promise<string> { | |
return new Promise((resolve, reject) => { | |
const reader: FileReader = new FileReader(); | |
reader.onload = () => { | |
if (typeof reader.result === 'string') { | |
resolve(reader.result); | |
} else { | |
reject(new Error(`Reading file result should be base64 string. Result: ${reader.result}`)); | |
} | |
}; |
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
div { | |
background: linear-gradient(0deg, scale-color($color, $alpha: -15%), scale-color($color, $alpha: -15%)), url(/assets/images/example.jpg) center / cover; | |
} | |
// or | |
div { | |
box-shadow: inset 0 0 0 200vw scale-color($accent-blue-color, $alpha: -15%); | |
background: url(/assets/images/example.jpg) center / cover; | |
} |
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
class Cancelable extends Promise { | |
// Symbol.species specifies a function-valued property that the constructor function uses to create derived objects. | |
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/species | |
static get [Symbol.species]() { | |
return Promise; | |
} | |
constructor(executor) { | |
let _reject; | |
super((resolve, reject) => { |
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
class Item { | |
constructor() { | |
return new Promise((resolve) => setTimeout(() => resolve(this), 1000)); | |
} | |
} | |
(async () => { | |
const test = await new Item(); | |
console.log(test); | |
})(); |
NewerOlder