Created
January 27, 2016 01:52
Personally I see the value of both. Depends on the codebase.
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
// mixins with createClass: | |
const Foo = createClass({ | |
...someMixin, | |
render: ({ onClick, children }) => ( | |
<div class="foo"> | |
<button onClick={onClick}>Click Me</button> | |
{ children } | |
</div> | |
) | |
}); | |
// mixins with class sugar + decorator (see below): | |
@mixes(someMixin) | |
class Foo extends Component { | |
render({ onClick, children }) { | |
return ( | |
<div class="foo"> | |
<button onClick={onClick}>Click Me</button> | |
{ children } | |
</div> | |
); | |
} | |
} | |
// Here's a simple decorator that satisfies the above usecase: | |
function mixes(...behaviors) { | |
return target => behaviors.forEach( b => Object.assign(target.prototype, b)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment