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
es6 classes with mixin - meantime solution #420
Comments
FYI: Reflux is seperated from react already by the reflux-core project. I think ListenerMixin to be used as es7 decorator would be nice to have. |
👍 Do you have some actual real solution waiting for reflux class support and alternative to mixin ? |
So I've been thinking about adding a var { RefluxComponent } from "reflux";
var { myStore } from "./stores";
/* ... */
render: () {
return (
<RefluxComponent connect={
(connector) => {
connector(myStore, "myVar");
// connect any number of stores to any variable
}
}>
{ /* use whatever from this.state.myVar */ }
</RefluxComponent>
);
} Using ES6 shorthand for the fat arrow you can do less boilerplate-y: <RefluxComponent connect={ (c) => c(myStore, "myVar") }>
{ /* use whatever from this.state.myVar */ }
</RefluxComponent> I was originally thinking about using React's contextType to trinkle down the store to anyone that wants to bind with them, however the context feature has some issues as in making the app a bit harder to manage (and in the end be more tightly coupled to flux stores than what my taste would allow). |
Why not simply use the following approach? ...
componentDidMount: function() {
this.unsubscribe = fooStore.listen(this.onChange);
},
componentWillUnmount: function() {
this.unsubscribe();
},
... |
For ES6 support, I have simple set of classes in Influx that should do the trick |
Finally it's out - an es7 decorator to connect to a store - it's part of my The important thing - it controls |
@yonatanmn I have this error; Uncaught TypeError: (0 , h.default) is not a function |
hey @juandav - what are you running exactly? ( |
@yonatanmn This is my store import Reflux from 'reflux';
import MenuActions from '../actions/MenuActions.jsx';
import StateMixin from 'reflux-state-mixin';
import $ from 'jquery';
let MenuStore = Reflux.createStore({
mixins : [ StateMixin.store ],
listenables : [ MenuActions ],
url : 'http://localhost:7000/menu',
menuList : [],
getInitialState: function() {
return {
menu: null
};
},
init : function() {
this.fetchMenu();
},
fetchMenu : function() {
$.ajax({
type : 'GET',
url : this.url,
context: this
})
.done(function(data) {
// console.log(data.payload);
// this.menuList = data.payload;
// this.trigger(this.menuList);
this.setState({ menu: data.payload });
})
.fail(function(err) {
console.log('Error loading data');
});
}
});
export default MenuStore; and this is my component 'use strict';
/*
* Module dependencies
*/
import React, { Component } from 'react';
import DataTable from '../components/datatable/datatable.jsx';
import MenuStore from '../stores/MenuStore.jsx';
import {connector} from 'reflux-state-mixin';
@connector(MenuStore, 'menu')
export default class MenuContainer extends Component {
render() {
let { menu } = this.state;
return (
<h1> Test Menu { menu } </h1>
)
}
} |
It seems the data you fetch is an Object, and you should render is correctly - choosing the right property of this object, or somehow mapping it. |
yeah my problem is react. thank you |
As soon as I try to use the decorator like so:
I get
and my state doesn't get bound from the store |
hey @juandav , first - please report issues in reflux-state-mixin repo, |
But I don't get that problem until I import your plugin and try to use it..., i'll file a issue at the repo |
hey @mgenev , maybe your problem is due to the use of decorators to make sure you use it on your webpack have something. module: {
loaders: [
{
test: /\.jsx$/,
exclude: /node_modules\/(?!(stardust))/,
loader: ['babel'],
query: {
cacheDirectory: true,
plugins: [
'transform-runtime',
'add-module-exports',
'transform-decorators-legacy',
],
presets: ['react', 'es2015', 'stage-1']
}
}
]
} |
What other changes do you guys think Reflux should have in order to push in to a final 0.5.x version? I'm up for helping on this! Is there a roadmap with changes? If not, maybe we should make one? |
We have ES6 now, so closing this. |
Can I use mixins in Reflux with ES6 now? Here is my code : and I get : Parsing error: Unexpected token, expected "," unless I use this, then it works : 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. |
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) :
now in the component (using es7 decorators - supported by babel)
Reflux's stores are the same (
Reflux.createStore({...})
)Please send feedback
The text was updated successfully, but these errors were encountered: