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
| /** | |
| * Adds retries to an async function. | |
| */ | |
| async function retry<T>(fn: () => Promise<T>, n: number): Promise<T> { | |
| let lastError: any; | |
| for (let index = 0; index < n; index++) { | |
| try { | |
| return await fn(); | |
| } | |
| catch (e) { |
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
| /** If true is returned it is used to prevent a nav away */ | |
| export type Check = () => true | false | undefined; | |
| /** Checks we need to do before leave */ | |
| let checks: Check[] = []; | |
| /** Only alert in browsers */ | |
| if (typeof window !== 'undefined') { | |
| const getMessageIfAny = () => { | |
| let message: ReturnType<Check> = false; |
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 { Validator } from 'formstate'; | |
| export const email: Validator<string | null | undefined> = (value: string | null | undefined) => { | |
| if (value == null || value == '') return null; | |
| value = value.trim(); | |
| // src : http://emailregex.com/ | |
| if (!/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/g.exec(value)) { | |
| return "Not a valid email address"; | |
| } | |
| return null; | |
| } |
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 Pre: React.SFC<{ children: any }> = (props) => { | |
| return <pre>{JSON.stringify(props.children, null, 2)}</pre> | |
| } |
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 * as crypto from 'crypto'; | |
| export const md5 = (contents: string) => crypto.createHash('md5').update(contents).digest("hex"); |
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 { observer } from 'mobx-react'; | |
| import * as field from './field'; | |
| import * as React from 'react'; | |
| import { InputStyles } from '../base/inputs'; | |
| import { classes, cssRaw } from 'typestyle'; | |
| import { FocusClassNames } from '../utils/dom'; | |
| import { Dates } from '../utils/validation'; | |
| import { Colors } from '../base/styles'; | |
| /** |
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 * as React from 'react'; | |
| import * as ReactDOM from 'react-dom'; | |
| import { App } from './app'; | |
| ReactDOM.render(<App/>, document.getElementById('root')) | |
| import {setStatefulModules} from 'fuse-box/modules/fuse-hmr'; | |
| setStatefulModules(name => { |
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 class AppState { | |
| @observable loggedIn = false; | |
| @action setLoggedIn(value: boolean){ | |
| this.loggedIn = value; | |
| } | |
| } | |
| // Don't want this executing again | |
| export const appState = new AppState(); |
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
| let listener = ()=>null | |
| // Don't want to execute this line again | |
| window.addEventListener("hashchange",()=>{ | |
| listener(); | |
| }); | |
| // You can call this as many times as you want | |
| export const onHashChange(_listener){ | |
| listener = _listener; |
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 foo = require('./foo'); | |
| console.log(foo.getFoo()); // hello | |
| foo.setFoo('world'); | |
| setTimeout(()=>{ | |
| const foo = require('./foo'); // You require it again. But you get the same instance! | |
| console.log(foo.getFoo()); // world | |
| }); |