diff --git a/examples/with-reflux/actions/actions.js b/examples/with-reflux/actions/actions.js new file mode 100644 index 00000000..281d7fe9 --- /dev/null +++ b/examples/with-reflux/actions/actions.js @@ -0,0 +1,8 @@ +import Reflux from 'reflux' + +var Actions = Reflux.createActions([ + 'increment', + 'decrement' +]) + +export default Actions diff --git a/examples/with-reflux/package.json b/examples/with-reflux/package.json new file mode 100644 index 00000000..dc493d74 --- /dev/null +++ b/examples/with-reflux/package.json @@ -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" +} diff --git a/examples/with-reflux/pages/index.js b/examples/with-reflux/pages/index.js new file mode 100644 index 00000000..015ef5d6 --- /dev/null +++ b/examples/with-reflux/pages/index.js @@ -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 ( +
+

Counter Value: {this.state.counter}

+ + +
+ ) + } +} diff --git a/examples/with-reflux/store/counterStore.js b/examples/with-reflux/store/counterStore.js new file mode 100644 index 00000000..d79105c5 --- /dev/null +++ b/examples/with-reflux/store/counterStore.js @@ -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}) + } +}