Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View erikras's full-sized avatar

Erik Rasmussen erikras

View GitHub Profile
const startTime = Date.now();
function generatePermutations(dictionary) {
const results = [];
const permute = (array, position) => {
if (position === array.length - 1) {
results.push(array);
} else {
for (let i = position; i < array.length; i++) {
const swap = array[position];
array.splice(position, 1, array[i]);
@erikras
erikras / MyContainer.js
Last active April 27, 2016 10:22
The HOC Drill Pattern [BEFORE]
import React, { Component } from 'react'
import MyWrappedComponent from './MyWrappedComponent'
export default class MyContainer extends Component {
constructor() {
// bind handlers
this.handleLoad = this.handleLoad.bind(this)
this.handleSave = this.handleSave.bind(this)
this.handleClear = this.handleClear.bind(this)
}
v6.2.2
3.9.5
redux-form@6.0.1 /Users/erik/oss/redux-form
├── array-findindex-polyfill@0.1.0
├─┬ babel-cli@6.14.0
│ ├─┬ babel-polyfill@6.13.0
│ │ └── regenerator-runtime@0.9.5
│ ├── babel-runtime@6.11.6
│ ├─┬ bin-version-check@2.1.0
│ │ ├─┬ bin-version@1.0.4

Keybase proof

I hereby claim:

  • I am erikras on github.
  • I am erikras (https://keybase.io/erikras) on keybase.
  • I have a public key ASBKqAeWHhNv0eDi5m-_tjdje5Adf8HqJnK2FROuaIbdago

To claim this, I am signing this object:

@erikras
erikras / MyContainer.js
Created April 27, 2016 10:40
The HOC Drill Pattern [AFTER]
import React, { Component } from 'react'
import MyWrappedComponent from './MyWrappedComponent'
export default class MyContainer extends Component {
constructor() {
// bind handlers
this.handleCallback = this.handleCallback.bind(this)
}
handleCallback(load, save, clear) {
@erikras
erikras / attempt.js
Created August 11, 2017 09:28
React Performance Anti-Pattern: Creating Functions in render() - attempt.js
import MyCustomButton from './ui/MyCustomButton'
class MyClicker extends Component {
constructor() {
super()
this.state = { clicked: false }
}
handleClick() {
this.setState({ clicked: true })
@erikras
erikras / problem.js
Last active August 11, 2017 09:29
React Performance Anti-Pattern: Creating Functions in render() - problem.js
import MyCustomButton from './ui/MyCustomButton'
class MyClicker extends Component {
constructor() {
super()
this.state = { clicked: false }
}
render() {
return <div>
@erikras
erikras / solution1.js
Created August 11, 2017 09:31
React Performance Anti-Pattern: Creating Functions in render() - solution1.js
import MyCustomButton from './ui/MyCustomButton'
class MyClicker extends Component {
constructor() {
super()
this.state = { clicked: false }
this.handleClick = this.handleClick.bind(this) // Problem solved!
}
handleClick() {
@erikras
erikras / solution2.js
Created August 11, 2017 09:32
React Performance Anti-Pattern: Creating Functions in render() - solution2.js
import MyCustomButton from './ui/MyCustomButton'
class MyClicker extends Component {
constructor() {
super()
this.state = { clicked: false }
}
handleClick = () => {
// "this" is the right instance of this component
@erikras
erikras / mutators.js
Last active December 3, 2017 16:16
🏁 Final Form Mutator Example
/** Clears a form value */
const clear = ([name], state, { changeValue }) => {
changeValue(state, name, () => undefined)
}
/** Converts a form value to uppercase **/
const upper = ([name], state, { changeValue }) => {
changeValue(state, name, value => value && value.toUpperCase())
}