This file contains 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-based Tree Shaking - HTTP203 @ Google Chrome Developers | |
// https://www.youtube.com/watch?v=lsd2-TCgHEs&t=599 | |
class Store { | |
/** | |
* Do the given action with the given parameters. | |
* | |
* @param {A => R} action Action to be taken. | |
* @param {A} args Arguments to be passed to the action. | |
* @returns {R} Returns the result of original action call. |
This file contains 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 callback(arg) { | |
setTimeout(console.log, 0, arg, ' # 4 timeout '); | |
setImmediate(console.log, arg, ' # 5 immediate'); | |
process.nextTick(console.log, arg, ' # 2 nextTick '); | |
(async () => { await undefined; console.log(arg, ' # 3 await '); })(); | |
console.log(arg, '# 1 sync '); | |
} | |
setTimeout(callback, 0, ' # 4 timeout '); | |
setImmediate(callback, ' # 5 immediate'); |
This file contains 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
/** | |
* @name compose | |
* @summary Composes Higher-Order-Functions from right to left so that they are executed from left to right. | |
* note: To compose Higher-Order-Components, use compose.ts | |
* | |
* | |
* @description | |
* Two overloads are available: | |
* A) Matches the composed signature of whole compose to the wrapped function. | |
* B) As an escape hatch, it is possible to explicitly define the resulting OuterSignature with a generic, ignoring the HOFs types. |
This file contains 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 CoreAPIService from './CoreAPIService'; | |
import { CommentInterface } from '../interfaces/requestInterface'; | |
class CommService { | |
// CREATE | |
addCommentToRequest = async (requestId: number, data: FormData) => | |
CoreAPIService.post(`comments/${requestId}`, data, { 'Content-Type': 'multipart/form-data' }) | |
.then<CommentInterface>(response => response.data); |
This file contains 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
/* Type guards */ | |
export function assertType<T>(obj: any, assertion: (obj: T) => boolean): asserts obj is T { | |
if (!assertion(obj)) throw new Error('Invalid type') | |
} | |
export function is<T>(obj: any, assertion: (obj: T) => boolean): obj is T { | |
return assertion(obj); | |
} |
This file contains 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 React from 'react'; | |
import PropTypes from 'prop-types'; | |
import { IMetricsServiceClient } from '@containers/App/model'; | |
export interface IWithMetricsServiceClient { | |
metricsServiceClient: IMetricsServiceClient; | |
} |
other gists
🔗 TypeScript type toolbelt
🔗 React utils
- accessTrap - Object and Array Proxy to count number of property accesses to map used/unused properties. It maintains referential stability using a caching mechanism to not disrupt React.js render flow.
other gists
🔗 TS/JS utility functions
🔗 React utils
- Deep Object Dot Path - Type support for deep objects with dot notation.
OlderNewer