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
| static batchPromise(proms: (() => Promise<any>)[], batchSize: number): Promise<void> { | |
| return this.chunck(proms, batchSize) | |
| .reduce((step: Promise<any>, chunck) => { | |
| return step.then(() => { | |
| return Promise.all(chunck.map(fp => fp())); | |
| }); | |
| }, Promise.resolve()); | |
| } | |
| private static chunck<T>(array: T[], batchSize = 5): T[][] { |
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 const DEFAULT_DEBOUNCE_MS = 500; | |
| export function debounce(ms: number = DEFAULT_DEBOUNCE_MS): Function { | |
| return function (target: any, propertyKey: string, descriptor: PropertyDescriptor): any { | |
| return { | |
| configurable: true, | |
| enumerable: descriptor.enumerable, | |
| get: function (): () => any { | |
| Object.defineProperty(this, propertyKey, { | |
| configurable: 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 MEMOIZED_VALUE_KEY = '_memoizedValue'; | |
| export function memoize(expirationTimeMs: number = 60000) { | |
| return (target: any, propertyName: string, descriptor: TypedPropertyDescriptor<any>) => { | |
| if (descriptor.value != null) { | |
| const originalMethod = descriptor.value; | |
| const fn: any = function (...args: any[]) { | |
| const key = MEMOIZED_VALUE_KEY + '_' + JSON.stringify(args); | |
| if (!fn[key]) { |
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 ISuccessError { | |
| success: boolean; | |
| result?: any; | |
| error?: any; | |
| } | |
| type PromFucn = (...args: any[]) => Promise<any>; | |
| promiseAllConcurrent(promFuncs: PromFucn[], | |
| concurrent: number = 1): Promise<ISuccessError[]> { |
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
| package oogaday.commons.enums | |
| enum class StatusCode(val code: Int) { | |
| Continue(100), | |
| SwitchingProtocols(101), | |
| Processing(102), | |
| OK(200), | |
| Created(201), | |
| Accepted(202), |
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 WidgetProvider { | |
| @after<WidgetProvider, Widget>({ | |
| func: () => { | |
| console.log('widget created') | |
| } | |
| }) | |
| createWidget(name: string): Widget { | |
| // some code | |
| } |
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 Data { | |
| @cancelPrevious() | |
| getReportData(data: IReportParams): IReportData { | |
| // some code | |
| } | |
| } |
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 MapView { | |
| @debounce(100); | |
| onScroll(): void { | |
| // some code | |
| } | |
| } |
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 EmailSender { | |
| @delay(1000); | |
| sendEmail(email: Email): Promise<void> { | |
| // some code | |
| } | |
| } |
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 Fibonacci { | |
| @memoize(10000) | |
| fibo(n: number): number { | |
| //some code | |
| } | |
| } |