by @chrtze & @moklick
Data Visualizations and News Apps
PreviewList Component
Preview Component
PreviewImage Component
Ratingbutton Component
PreviewLink Component
PreviewTitle Component
var Preview = React.createClass({
...
toggle(){ ... },
render() {
return (
<div className="preview-card" onclick={this.toggle}>
<PreviewImage src={this.props.src} />
<PreviewTitle title={this.props.title} />
<RatingButton id={this.props.id} />
<PreviewLink href={this.props.href} />
</div>
)
}
});
Simplified Code of Preview.jsx
It's just JavaScript!
* If you think in a React way
var Headline = require('./headline.jsx');
var Header = React.createClass({
getInitialState: function() {
return { appName : 'React App' };
},
render(){
return(
<Headline title={this.state.appName} />
)
}
...
var Headline = React.createClass({
propTypes: {
appName : React.PropTypes.string
},
render(){
return(
<h1>{ this.props.appName }</h1>
)
}
...
Output: <h1>React App</h1>
render children
render children
(Not part of React)
╔═════════╗ ╔════════╗ ╔═════════════════╗
║ Actions ║──────>║ Stores ║──────>║ View Components ║
╚═════════╝ ╚════════╝ ╚═════════════════╝
^ │
└──────────────────────────────────────┘
*stolen from the Reflux repo.
*
...
componentDidMount() {
ItemActions.loadItems();
}
...
PreviewList.jsx
var ItemActions = Reflux.createActions([
'loadItems'
]);
itemActions.js
Kind of publisher
componentDidMount() {
this.unsubscribe = ItemStore.listen(this.onStatusChange.bind(this));
ItemActions.loadItems();
}
onStatusChange(state) {
this.setState(state);
}
previewList.jsx
var ItemStore = Reflux.createStore({
init() {
this.items = ['Foo', 'Bar', 'Test'];
this.listenTo(ItemActions.loadItems, this.loadItems);
},
loadItems() {
this.trigger({
items : this.items
});
}
});
itemStore.js
Kind of publisher and subscriber
Load Modules
var React = require('react');
var LibXY = require('libxy');
Load Files (css, images, json, etc.)
var css = require('css!./style.css');
var data = require('dsv!./data.csv');
Create Chunks
require.ensure(['some-module'], function(require){
var module = require('some-module');
}
Transform JSX
var Header = React.createClass({
render() {
return (
<header>
<Navigation />
</header>
)
}
});
Transform ES6
var items = this.props.items.map(item => <li key={ item }>{ item }</li>)
class ItemList extends React.Component {
constructor(){
super();
}
...
Arrow Functions
Class syntax
Flux Architecture
Routing
Module Loader
JSX and ES6 Transformer
Building Tool
CSS Preprocessor
Github Acc: https://github.com/wbkd
Starterkit: https://github.com/wbkd/react-starterkit
DDJ Catalogue Repo: https://github.com/wbkd/ddj-catalogue
DDJ Catalogue: http://katalog.datenjournalismus.net