-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update withData.js (#3458) #3234 * Begun with-reflux example * Built with-reflux example * Built with-reflux example
- Loading branch information
1 parent
5bb710a
commit f2989c5
Showing
4 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Reflux from 'reflux' | ||
|
||
var Actions = Reflux.createActions([ | ||
'increment', | ||
'decrement' | ||
]) | ||
|
||
export default Actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "with-reflux", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"dev": "next", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"next": "latest", | ||
"react": "^16.0.0", | ||
"react-dom": "^16.0.0", | ||
"reflux": "^6.4.1" | ||
}, | ||
"license": "ISC" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import Reflux from 'reflux' | ||
import CounterStore from '../store/counterStore' | ||
import Actions from '../actions/actions' | ||
|
||
export default class Home extends Reflux.Component { | ||
constructor () { | ||
super() | ||
this.store = CounterStore | ||
} | ||
render () { | ||
return ( | ||
<div> | ||
<h1>Counter Value: {this.state.counter}</h1> | ||
<button onClick={Actions.increment}>Increment</button> | ||
<button onClick={Actions.decrement}>Decrement</button> | ||
</div> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Reflux from 'reflux' | ||
import Actions from '../actions/actions' | ||
|
||
export default class StatusStore extends Reflux.Store { | ||
constructor () { | ||
super() | ||
this.state = {counter: 0} | ||
this.listenTo(Actions.increment, this.onIncrement) | ||
this.listenTo(Actions.decrement, this.onDecrement) | ||
} | ||
onIncrement () { | ||
this.setState({counter: this.state.counter + 1}) | ||
} | ||
onDecrement () { | ||
this.setState({counter: this.state.counter - 1}) | ||
} | ||
} |