Last active
October 1, 2017 16:24
-
-
Save jprivillaso/59d81d7d5fe7cf1864fe05eb05d1eb4f to your computer and use it in GitHub Desktop.
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
const DEFAULT_METHODS = ['constructor', 'render', 'componentDidMount', 'componentDidUpdate']; | |
class App extends React.Component { | |
constructor() { | |
super(); | |
this.bindMethodsWithContext(this); | |
} | |
componentDidMount() { | |
//... | |
} | |
componentDidUpdate() { | |
//... | |
} | |
bindMethodsWithContext($this) { | |
Object.getOwnPropertyNames(App.prototype).forEach((func) => { | |
if (DEFAULT_METHODS.indexOf(func) === -1) { | |
$this[func] = $this[func].bind($this); | |
} | |
}); | |
} | |
methodA() { | |
//... | |
} | |
methodB() { | |
//... | |
} | |
methodC() { | |
//... | |
} | |
render() { | |
//... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment