Skip to content

Instantly share code, notes, and snippets.

View formDataFrom.ts
function formDataFrom(obj: { [key: string]: string | number }) {
let formData = new FormData()
for (let key in obj) {
formData.append(key, String(obj[key]))
}
return formData
}
export default formDataFrom
View a.js
let scrollEnhanced = (Inner) => {
return class ScrollEnhanced extends Component {
render () {
return <Inner {...this.props} {...scrollEnhancedStuff} />
}
}
}
// ... later
View gist:8fd3d4a04247fa8be49a0092c22b3e7c
class A extends Component {
doSomething = async () => {
this.setState({pending: true})
try {
await doSomething()
} catch (err) {
} finally {
this.setState({pending: true})
View reducer.js
return (state: State = defaultState, action: Action) => {
let { _persist, ...rest } = state || {}
let restState: State = rest
switch (action.type) {
case PERSIST:
if (state._persist) {
console.warn(
'redux-persist: unexpected _persist state before PERSIST action is handled. If you are doing hmr or code-splitting this may be a valid use case. Please open a ticket, requires further review.'
)
View drive-markdown.md

Drive Markdown is a strict subset of markdown supporting the following syntax:

name syntax example
bold **bold** bold
heading1 # heading # heading
heading(N<5) ### heading (N=3) ### heading
link [link](https://google.com) link
ordered list ab ab
unordered list ab ab
View markdown-sample.md

An h1 header

Paragraphs are separated by a blank line.

2nd paragraph. Italic, bold, and monospace. Itemized lists look like:

  • this one
  • that one
View persist.js
// time iterator (read: debounce)
if (timeIterator === null) {
timeIterator = setInterval(processNextReducer, debounce)
}
function flush () {
storesToProcess.forEeach(processNextReducer)
}
function processNextReducer () {
View redux-persist-immutable.js
import { createTransform, getStoredState, purgeStoredState } from 'redux-persist'
import { autoRehydrate as baseAutoRehydrate, createPersistor as baseCreatePersistor, persistStore as basePersistStore }
export { createTransform, getStoredState, purgeStoredState }
import immutableConfig from './immutableConfig' // basically verbatim redux-persist-immutable-state but keys renamed: _stateInit, _stateGetter, ...
import stateReconciler from './stateReconciler'
// perhaps we should add some validation to make sure stateReconciler is not being overriden?
export const autoRehydrate = (config, ...args) => {
View async.js
import {getStoredState, createPersistor, autoRehydrate } from 'redux-persist'
export async function bootstrap () {
let initialState
try {
initialState = await getStoredState()
} catch (err) {
initialState = {}
}