question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

es6 classes with mixin - meantime solution

See original GitHub issue

There were few discussions regarding React’s new approach of using es6 classes. So at the future Reflux will be separated from React, but we need a solution today. Here is a first proposal for one! (example with ListenerMixin, could be copied to other mixins) :

import React from 'react';
import Reflux from 'reflux';

function ListenerMixin(ComposedComponent) {
    return React.createClass({
        mixins: [Reflux.ListenerMixin],

        render() {
            return <ComposedComponent {...this.props} listenTo={this.listenTo}/>;
        }

    });
}

export default ListenerMixin;

now in the component (using es7 decorators - supported by babel)

import Store from '../../stores/Store.js'
import ListenerMixin from './ListenerMixin.js';

@ListenerMixin
class SomeComp extends Component {
  componentDidMount() {
    this.props.listenTo(Store, msg=>{console.log(msg)});  //listenTo is a prop now
  }
  render()...
}

Reflux’s stores are the same (Reflux.createStore({...}))

Please send feedback

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Zebochcommented, Sep 29, 2015

👍

Do you have some actual real solution waiting for reflux class support and alternative to mixin ? I also have the same problem trying to use ListenerMixin in a Component …

0reactions
raboijacommented, Jul 24, 2019

We have ES6 now, so closing this.

Can I use mixins in Reflux with ES6 now?

Here is my code : mixins: [Reflux.connect(PopularStore, ‘popularstore’)], popularStore: null,

and I get : Parsing error: Unexpected token, expected “,” (near .connect)

unless I use this, then it works : const JSONViewerReflux = createReactClass({ mixins: [Reflux.connect(PopularStore, ‘popularstore’)],

popularStore: null,

But with normal react classes, it doesn’t work.

Any suggestions where to put mixins and to use them with ES6? I don’t wanna conver all my components code to ES5.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - es6 classes with mixin - meantime solution -
There were few discussions regarding React's new approach of using es6 classes. So at the future Reflux will be separated from React, but...
Read more >
How to add mixins to ES6 javascript classes? - Stack Overflow
I'm fine with using lodash for the solution, or even plain JS with no libraries to provide the mixin functionality. javascript · node.js...
Read more >
Mixins Are Dead. Long Live Composition | by Dan Abramov
The introductory post made it clear that mixins are on their way out: Unfortunately, we will not launch any mixin support for ES6...
Read more >
Mixins Considered Harmful – React Blog
Our answer has always been to use component composition for code reuse. ... don't need mixins, you can switch to ES6 classes if...
Read more >
Multiple inheritance and mixin classes in Python
we end up putting the features related to the review process in an object that shouldn't have them. The standard solution to this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found