Last active
September 15, 2016 09:29
-
-
Save AllenFang/687e4bbcb621e550fec6 to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import DemoApp from './components/DemoApp.react'; | |
React.render( | |
<DemoApp />, | |
document.getElementById("example") | |
); |
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
import React from 'react'; | |
export default React.createClass({ | |
render() { | |
return ( | |
<div>Current value: {this.props.count}</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
import DemoDispatcher from '../dispatcher/DemoDispatcher'; | |
import DemoConstants from '../constants/DemoConstants'; | |
var DemoAction = { | |
increase: () =>{ | |
DemoDispatcher.dispatch({ | |
actionType: DemoConstants.DEMO_INCREASE | |
}); | |
}, | |
decrease: () =>{ | |
DemoDispatcher.dispatch({ | |
actionType: DemoConstants.DEMO_DECREASE | |
}); | |
} | |
}; | |
export default DemoAction; |
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
import React from 'react'; | |
import Header from './Header.react'; | |
import Content from './Content.react'; | |
import demoStore from '../stores/DemoStore'; | |
var DemoApp = React.createClass({ | |
getInitialState() { | |
return { | |
count: demoStore.getCount() | |
}; | |
}, | |
componentDidMount(){ | |
demoStore.addChangeListener(this._onChange); | |
}, | |
componentWillUnmount(){ | |
demoStore.removeChangeListener(this._onChange); | |
}, | |
render() { | |
return ( | |
<div> | |
<Header /> | |
<Content count={this.state.count}/> | |
</div> | |
) | |
}, | |
_onChange(){ | |
this.setState({ | |
count: demoStore.getCount() | |
}); | |
} | |
}); | |
export default DemoApp; |
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
export default { | |
DEMO_INCREASE: "INCREASE", | |
DEMO_DECREASE: "DECREASE" | |
}; |
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
import {Dispatcher} from 'flux'; | |
export default new Dispatcher(); |
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
import {EventEmitter} from 'events'; | |
import DemoDispatcher from '../dispatcher/DemoDispatcher' | |
import DemoConstants from '../constants/DemoConstants'; | |
const CHANGE_EVENT = "change"; | |
let count = 0; | |
function _increase() { | |
count++; | |
} | |
function _decrease(){ | |
count--; | |
} | |
class DemoStore extends EventEmitter{ | |
getCount(){ | |
return count; | |
} | |
emitChange(){ | |
this.emit(CHANGE_EVENT); | |
} | |
addChangeListener(callback){ | |
this.on(CHANGE_EVENT, callback); | |
} | |
removeChangeListener(callback){ | |
this.removeListener(CHANGE_EVENT, callback); | |
} | |
} | |
var demoStore = new DemoStore(); | |
DemoDispatcher.register((action) => { | |
switch(action.actionType){ | |
case DemoConstants.DEMO_INCREASE: | |
_increase(); | |
demoStore.emitChange(); | |
break; | |
case DemoConstants.DEMO_DECREASE: | |
_decrease(); | |
demoStore.emitChange(); | |
break; | |
default: | |
} | |
}); | |
export default demoStore; |
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
var gulp = require('gulp'); | |
var browserify = require('gulp-browserify'); | |
var rename = require('gulp-rename'); | |
gulp.task("default", ["build"]); | |
gulp.task('build', function(){ | |
gulp.src("js/*.js") | |
.pipe(browserify({ | |
transform: ["babelify"] | |
})) | |
.pipe(rename("bundle.js")) | |
.pipe(gulp.dest("./build")); | |
}); |
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
$ npm install gulp --save-dev | |
$ npm install gulp-browserify --save-dev | |
$ npm install gulp-rename --save-dev |
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
import React from 'react'; | |
import DemoAction from '../actions/DemoAction'; | |
export default React.createClass({ | |
handleIncrease(){ | |
DemoAction.increase(); | |
}, | |
handleDecrease(){ | |
DemoAction.decrease(); | |
}, | |
render() { | |
return( | |
<div> | |
<section> | |
<button onClick={this.handleIncrease}>Increase</button> | |
<button onClick={this.handleDecrease}>Decrease</button> | |
</section> | |
</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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<title>React demo with babel</title> | |
</head> | |
<body> | |
<div id="example"></div> | |
<script src="build/bundle.js"></script> | |
</body> | |
</html> |
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
$ npm install react --save | |
$ npm install flux --save | |
$ npm install browserify --save-dev | |
$ npm install babelify --save-dev |
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
{ | |
"name": "react-flux-babel", | |
"version": "1.0.0", | |
} |
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
"browserify": { | |
"transform": [ | |
"babelify" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment