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
| console.log(length); // 25 and not 0 | |
| console.log(message); // "John" and not "" | |
| let length = 0; | |
| console.log(length || 99); // 99 | |
| console.log(length ?? 99); // 0 |
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 array = [1, 2, 2, 3,3, 4, 5, 5, 3, 6, 9] | |
| const uniqueArray = [...new Set(array)]; | |
| console.log(uniqueArray); //[1, 4, 6, 9] |
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
| function getImageURLById(imageId, asAttachment = false, asThumbnail = false, withCompression = false) { | |
| ... | |
| } | |
| // This is unreadable without checking function definition | |
| getImageURLById(25, true, false, 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
| function getImageURLById({imageId, asAttachment = false, asThumbnail = false, withCompression = false}) { | |
| ... | |
| } | |
| // This is more readable and doesn't require checking the function definition | |
| getImageURLById({imageId: 25, asAttachment: true, withCompression: 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
| const array = [1, 0 , {foo: 'bar'}, undefined, null]; | |
| const truthyArray = array.filter(Boolean); | |
| //or we can use the double bang !! to do the same thing | |
| const truthyArray = array.filter(value => !!value); | |
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 type ObservableSourceType<T = any> = Observable<T> | ((value: any) => Observable<T>); | |
| function* sourcesGen<T>(sources: ObservableSourceType[], a: T, i: number): Generator<Observable<any>, Observable<any>, undefined> { | |
| const length = sources.length; | |
| for (const [index, source] of sources.entries()) { | |
| const observableSource: Observable<any> = typeof source === 'function' ? source.call(null, [a, i]) : source; | |
| if (index <= length + 1) { | |
| yield observableSource; | |
| } else { | |
| return observableSource; |
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 type ObservableSourceType<T = any> = Observable<T> | ((value: any) => Observable<T>); | |
| function* sourcesGen<T>(sources: ObservableSourceType[], a: T, i: number): Generator<Observable<any>, Observable<any>, undefined> { | |
| const length = sources.length; | |
| for (const [index, source] of sources.entries()) { | |
| const observableSource: Observable<any> = typeof source === 'function' ? source.call(null, [a, i]) : source; | |
| if (index <= length + 1) { | |
| yield observableSource; | |
| } else { | |
| return observableSource; |
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 { PathLocationStrategy, APP_BASE_HREF, PlatformLocation } from '@angular/common'; | |
| import { Optional, Inject, Injectable } from '@angular/core'; | |
| import { UrlSerializer } from '@angular/router'; | |
| @Injectable() | |
| export class PreserveQueryParamsPathLocationStrategy extends PathLocationStrategy { | |
| private get search(): string { | |
| return this.platformLocation?.search ?? ''; | |
| } | |
| constructor( |
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, EventEmitter, HostListener, Input, OnDestroy, OnInit, Output } from '@angular/core'; | |
| import { Subject, Subscription } from 'rxjs'; | |
| import { debounceTime } from 'rxjs/operators'; | |
| @Directive({ | |
| selector: '[click.single],[click.double]', | |
| }) | |
| export class ClickDoubleDirective implements OnInit, OnDestroy { | |
| @Input() debounceTime = 300; | |
| @Output('click.double') doubleClick = new EventEmitter(); |
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
| // In some angular template bind to events `click.single` and `click.double` | |
| <div (click.single)="onSingleClick($event)" (click.double)="onDoubleClick(event)"> | |
| I got 99 problems but the click ain't one | |
| </div> | |