Live data from Hacker News

Using ES7 Decorators as Mixins

raganwald.com

1–10 of 14 posts

Re: Using ES7 Decorators as Mixins

#5
One really useful pattern is React higher-order components, eg. https://github.com/elierotenberg/react-nexus#componentgetnex...

The pattern is

  function decorate(params) {
    return (Component) => class extends React.Component {
      ... // some code using params
      render() {
        return 
      }
    };
  }
my2c.

Re: Using ES7 Decorators as Mixins

#6

One really useful pattern is React higher-order components, eg. https://github.com/elierotenberg/react-nexus#componentgetnex... The pattern is function decorate(params) { return (Component) => class extends React.Component { ... // some code using params render() { return } }; } my2c.

I haven't seen that usage for higher-order components before. This is the pattern I've been following:

    function decorate (Component) {
      let HigherOrderComponent = React.createClass({
        render () {
          return 
        }
      })
      
      return HigherOrderComponent
    }
as explained here: https://medium.com/@dan_abramov/mixins-are-dead-long-live-hi...

Re: Using ES7 Decorators as Mixins

#7
post #6

One really useful pattern is React higher-order components, eg. https://github.com/elierotenberg/react-nexus#componentgetnex... The pattern is function decorate(params) { return (Component) => class extends React.Component { ... // some code using params render() { return } }; } my2c.

I haven't seen that usage for higher-order components before. This is the pattern I've been following: function decorate (Component) { let HigherOrderComponent = React.createClass({ render () { return } }) return HigherOrderComponent } as explained here: https://medium.com/@dan_abramov/mixins-are-dead-long-live-hi...

They are the same I think, only one has extra parameters. At least in Python, @fn(...args) evaluates the function first and uses the result as a decorator. The guy who wrote the blog post you mention actually uses the parent's pattern in react-dnd.

Re: Using ES7 Decorators as Mixins

#9

Kinda makes me feel incompetent. Just started using ES6 in nodejs and here are people already gunning for ES7. Amazing.

Don't get worked up over this. Let the dust settle and the smoke clear. Take a deep breath and relax. You'll need it in the JS community.

Re: Using ES7 Decorators as Mixins

#10

Kinda makes me feel incompetent. Just started using ES6 in nodejs and here are people already gunning for ES7. Amazing.

dude, es6 is way too mainstream for cutting edge web programming. If you're not using es7 already you might as well still be using table layouts
Post reply on HN