other gists
🔗 TS/JS utility functions
🔗 React utils
- Deep Object Dot Path - Type support for deep objects with dot notation.
| // 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. |
| /* 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); | |
| } |
| import React from 'react'; | |
| import PropTypes from 'prop-types'; | |
| import { IMetricsServiceClient } from '@containers/App/model'; | |
| export interface IWithMetricsServiceClient { | |
| metricsServiceClient: IMetricsServiceClient; | |
| } |
| 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'); |
| /** | |
| * @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. |
| 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); |
other gists
🔗 TS/JS utility functions
🔗 React utils
Calculate and display pool ranges in USD
This repository contains a collection of bookmarklets and script snippets that can be used to enhance the browsing experience.