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
export default class SomeSingleton { | |
private static privateShared: Api; | |
public static get shared(): Api { | |
if (!SomeSingleton.privateShared) { | |
SomeSingleton.privateShared = new SomeSingleton(); | |
} | |
return SomeSingleton.privateShared; | |
} |
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
// babel.config.js | |
module.exports = { | |
"presets": [ | |
"module:metro-react-native-babel-preset", | |
], | |
"plugins": [ | |
["module-resolver", { | |
"root": ["./src"], | |
"extensions": [".js", ".ts", ".tsx", ".ios.js", ".android.js"] | |
}], |
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 {Provider, Consumer} from 'react'; | |
// tslint:disable-next-line | |
type Curry<F extends Function> = F extends (arg1: infer T1, arg2: infer T2, arg3: infer T3) => any | |
? (arg3: T3) => ReturnType<F> | |
: never; | |
type RVSActionCreator<S, A> = (state: S, actions: A, arg: any) => any; | |
type ActionCreatorsMap<S, A> = {[actionName: string]: RVSActionCreator<S, A>}; |
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
Show hidden characters
{ | |
"compileOnSave": true, | |
"compilerOptions": { | |
"skipLibCheck": true, | |
/* Basic Options */ | |
"target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | |
"module": "es2015", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | |
"lib": ["es2017", "dom"], /* Specify library files to be included in the compilation. */ | |
// "allowJs": true, /* Allow javascript files to be compiled. */ | |
// "checkJs": true, /* Report errors in .js files. */ |
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 {Action as ReduxAction, Middleware as ReduxMiddleware, Store as ReduxStore} from 'redux'; | |
import {NavigationState, NavigationScreenProp} from 'react-navigation'; | |
import {ThunkAction, ThunkDispatch} from 'redux-thunk'; | |
import {StateType} from 'typesafe-actions'; | |
import {reducers} from 'store/reducers/root.reducer'; | |
export type AppState = StateType<typeof reducers>; | |
export interface Action<T = any, P extends object = any, M = any> extends ReduxAction<T> { | |
payload?: P; |
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 $Values<O extends object> = O[keyof O]; | |
const obj = { | |
RU: 'ru', | |
EN: 'en', | |
} as const; | |
type vals = $Values<typeof obj>; // vals === 'ru' | 'en'; |
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
// @flow | |
export async function retryPromise<T: Array<*>>(fn: (...T) => Promise<*>, args: T, tryCount: number = 3) { | |
try { | |
return await fn(...args); | |
} catch (e) { | |
console.log(`Promise retry error. Attempts left: ${tryCount}`, e); | |
if (tryCount > 1) { | |
return await retryPromise(fn, args, tryCount - 1); | |
} else { |
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 DraggerPosition = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right'; | |
const computeGeometryWhileDragging = ( | |
position: DraggerPosition, | |
preserveAspectRatio: boolean, | |
initialGeometry: SlideElementGeometry, | |
currentGeometry: SlideElementGeometry, | |
dx: number, | |
dy: number | |
): SlideElementGeometry => { |
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
// @flow | |
type Size = { width: number, height: number }; | |
function getFittedSlideSize(container: Size, target: Size): Size { | |
const targetAspectRatio = target.width / target.height; | |
const containerAspectRatio = container.width / container.height; | |
// if aspect ratio of target is "wider" then target's aspect ratio | |
const fit = targetAspectRatio > containerAspectRatio | |
? 'width' // fit by width, so target's width = container's width | |
: 'height'; // fit by height, so target's height = container's height |
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 getTextLinesFromElement(target) { | |
const originalHtml = target.innerHTML; | |
const lines = []; | |
let currentLine = []; | |
let prevWordTop; | |
target.innerHTML = target.textContent.split(' ').map(w => `<span>${w}</span>`).join(' '); | |
Array.from(target.querySelectorAll('span')).forEach((span, i , spans) => { | |
const text = span.textContent; | |
if (text === '') { |