Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOC alternative to the mixin #6

Closed
ksmth opened this issue May 19, 2015 · 2 comments
Closed

HOC alternative to the mixin #6

ksmth opened this issue May 19, 2015 · 2 comments

Comments

@ksmth
Copy link

ksmth commented May 19, 2015

Internally it could also reuse the mixin. It could look something like this:

function Cerebralize(Component, cerebralState) {
  return React.createClass({
    mixin : [ cerebralMixin ],
    displayName : `Cerebralized${Component.name}`,
    getCerebralState() {
      return cerebralState;
    },
    render() {
      return <Component signals={this.signals} {...this.props} {...this.state}>;
    }
  });
};
// ES5
var MyComponent = React.createClass({ ... });
MyComponent = Cerebralize(MyComponent, [ ... ]);
// ES6
class MyComponent extends React.Component { }
MyComponent = Cerebralize(MyComponent, [ ... ]);
// ES7
@Cerebralize([ ... ])
class MyComponent extends React.Component { }
@christianalfoni
Copy link
Member

Thanks for the input, will make this part of next release! Change to props instead.

@christianalfoni
Copy link
Member

This should be ready for next release, though I chose the name "decorator" on the file. so import WhatEver from 'cerebral/decorator. Will also activate decorators on the cerebral boilerplate by default. Still got cerebral/mixin available though. So the ES6 version uses the decorator version as that is likely to become the standard and the behaviour is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants