React/Reflux:使用装饰器将带有mixins的类转换为ES6

Jea*_*eri 5 decorator ecmascript-6 reactjs refluxjs ecmascript-7

我正在尝试es6-ify以下React-Reflux代码:

var TimeStore = Reflux.createStore({
    listenables: [TimeActions],

    onTick: function(tick) {
        ....    
    }
})

var Watch = React.createClass({
    mixins: [Reflux.connect(TimeStore, 'tick')],
    ...
Run Code Online (Sandbox Code Playgroud)

资源

我不知道如何使用react-decorator转换它.这就是我将其转化为:

const SomeDecorator = MixinDecorator(
    'TimerActions',  // displayName
    Reflux.connect(TimeStore, 'tick')
);

@SomeDecorator
class Watch extends React.Component {
    ...
Run Code Online (Sandbox Code Playgroud)

它与babel编译(stage设置为0)但不能很好地工作.有任何建议如何解决这个问题?此外,是否有可能es6-ify商店?

J. *_*ens 8

完全跳过mixins.

    class AppCtrlRender extends Component {
        binder(...methods) { methods.forEach( (method) => this[method] = this[method].bind(this) ); }

        render() {
            var data = this.state.Data;
            data = JSON.stringify(data, null, 2);
            var data2 = this.state.Data2;
            data2 = JSON.stringify(data2, null, 2);
            var data3 = this.state.Data3;
            data3 = JSON.stringify(data3, null, 2);
            return (
                <div id='AppCtrlSty' style={AppCtrlSty}>
                    React 1.3 ReFlux with WebSocket<br/><br/>
                    {data}<br/><br/>
                    Data2: {data2}<br/><br/>
                    Data3: {data3}<br/><br/>
                </div>
            );
        }
    }

    function getState() {
        return {
            Data: BasicStore.getData(),
            Data2: BasicStore.getData2(),
            Data3: BasicStore.getData3()
        };
    };

    export default class AppCtrl extends AppCtrlRender {
        constructor() {
            super();
            this.state = getState();
            this.binder('storeDidChange');
        }

        componentDidMount() { this.unsubscribe = BasicStore.listen(this.storeDidChange); }
        componentWillUnmount() { this.unsubscribe(); }
        storeDidChange() { this.setState(getState()); }
    }
Run Code Online (Sandbox Code Playgroud)