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

add Flux section #3

Merged
merged 3 commits into from
Mar 8, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

Imaginary flux implementation.

- less trick
- debuggable
- ECMAScript6 compatible
- Class syntax

## Installation

- [ ] Describe the installation process
Expand Down Expand Up @@ -67,6 +72,67 @@ Update `this.state` and dispatch change.

- `object` is any object.

### Flux

How to connect Action and Store?
=> Create connection object. it is called `Flux` in this context.

```js
import UserAction from "./UserAction.js"
import UserStore from "./UserStore.js"
import {Flux} from 'material-flux';

export default class UserFlux extends Flux {
constructor() {
this.userAction = new UserAction();
// TODO: dependent the order?
this.userStore = new UserStore(this);
}
}
```

### View(Component)

How to connect to View like React?
=> Pass an instance of `Flux` to React's Component.

```js
import React from 'react';
import UserFlux from './UserFlux';
import App from './AppComponent.jsx';
var userFlux = new UserFlux();
React.render(
React.createElement(App, { flux }),
document.getElementById('main')
);
```

AppComponent:

```js
import React from 'react';
export default AppComponent extends React.Component {
constructor(props) {
super(props);
var { flux } = this.props;
this.state = {
userData : flux.userStore.getUserData()
};
}
onClick(event){
var { flux } = this.props;
flux.userAction.doSomething("clicked");
}
render() {
return (
<div onClick={this.onClick}>
userData: {this.state.userData}
</div>
);
},
}
```

## Contributing

1. Fork it!
Expand All @@ -78,3 +144,7 @@ Update `this.state` and dispatch change.
## License

MIT

## Inspiration and thanks

- [Flummox](https://github.com/acdlite/flummox/tree/63e1f13f26724aa1f97da449ea61a3abcbf45360 "Flummox")