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, Input, TemplateRef, ViewContainerRef } from '@angular/core'; | |
export type RepeatTimesContext = { | |
$implicit: number; | |
index: number; | |
} | |
@Directive({ | |
selector: '[repeatTimes]' | |
}) |
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 { NgxTeleportModule } from 'ngx-teleport'; | |
@NgModule({ | |
//... | |
imports: [ | |
//.. | |
NgxTeleportModule, | |
//.. | |
], | |
}) |
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
<!--This can be anwhere in your App--> | |
<ngx-teleport to="destination"> | |
<stuff>...</stuff> | |
</ngx-teleport> | |
<!--This can be anwhere in your App--> | |
<ngx-teleport-outlet name="destination"> | |
</ngx-teleport-outlet> | |
<!--content will be rendered here--> |
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
(async function () { | |
for await (const batch of batchTasks(tasks, 5)) { | |
console.log('batch', batch); | |
//Do something with the processed batch | |
renderPost(batch, appDiv); | |
} | |
loadingDiv.innerText = 'Loaded'; | |
})(); |
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
/** | |
* A fuction that returns a Promise | |
* @typedef {(<T = any>() => Promise<T>)} Task | |
*/ | |
/** | |
* | |
* @param {Array<Task>} tasks | |
*/ | |
export async function* batchTasks(tasks, limit, taskCallback = (r) => r) { |
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> | |
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
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
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; |