Created
September 22, 2015 10:04
-
-
Save motiz88/3db323f018975efce575 to your computer and use it in GitHub Desktop.
React lifecycle method grouping, using a decorator
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 methodGroups fom './method-groups-decorator'; | |
@methodGroups('lifecycle') | |
class Example extends React.Component { | |
static lifecycle = { | |
componentWillMount() {}, | |
componentDidMount() {}, | |
componentWillReceiveProps() {}, | |
shouldComponentUpdate() {}, | |
componentWillUpdate() {}, | |
componentDidUpdate() {}, | |
componentWillUnmount() {} | |
} | |
} | |
export default Example; |
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 function methodGroups(...groups) { | |
return function decorator(target) { | |
groups.forEach(group => Object.assign(target.prototype, target[group])); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment