On learning your first JavaScript Framework
@app.route('/submit')
def submit_form():
pass
@app.route('/process_form')
def process_profile():
pass
@app.route('/form')
def process_async_form():
pass
(Cont.)
(Cont.)
Kind of. jQuery and JavaScript encourage imperative programming.
var TextBox = React.createClass({
getInitialState: function(){
// pass
},
componentDidMount: function(){
// pass
},
componentShouldUpdate: function(){
// pass
},
render: function(){
// pass
}
});
var TextBox = React.createClass({
getInitialState: function(){
// pass
},
componentDidMount: function(){
// pass
},
componentShouldUpdate: function(){
// pass
},
render: function(){
return (<textarea></textarea>);
}
});
var TextBox = React.createClass({
getInitialState: function(){
// pass
},
componentDidMount: function(){
// pass
},
componentShouldUpdate: function(){
// pass
},
render: function() {
return (<textarea rows="5">
</textarea>
);
}
});
var MeggiesForm = React.createClass({
render: function(){
return (
<div>
<p>Howdy. Try typing in the text box below.</p>
<TextBox />
</div>
);
}
});
var TextBox = React.createClass({
getInitialState: function(){
count: 0
},
componentDidMount: function(){
// pass
},
componentShouldUpdate: function(){
// pass
},
countChars: function(evt){
var count = this.refs.input.value.length;
this.setState('count', count);
},
render: function() {
return (<textarea
ref="input"
onChange={this.countChars}
rows="5">
</textarea>
<StatusDiv count={this.state.count} />
);
}
});
var TextBox = React.createClass({
getInitialState: function(){
count: 0
},
componentDidMount: function(){
// pass
},
componentShouldUpdate: function(){
// pass
},
countChars: function(evt){
var count = this.refs.input.value.length;
this.setState('count', count);
},
render: function() {
return (<textarea
ref="input"
onChange={this.countChars}
rows="5">
</textarea>
<StatusDiv count={this.state.count} />
);
}
});
Audio Visualization Demo at http://localhost:8000/pronounce_gaelic/start
Reconciliation Algorithm: generating the minimum number of operations to transform one tree into another
JSX gotchas
/** @jsx React.DOM */
needs to be at the top of any file with React code (JSX) in it.type="text/jsx"
to the <script>
tag for any of YOUR JavaScript files that contain React code (JSX)class="blah"
in JSX because class
is a reserved word in JavaScript. Use className
instead.Component Lifecycle gotchas
componentDidMount
means the render function got called.React is hard on designer workflows.
JSX is hard to look at.
The error messages are cryptic.
- Facebook React developers, if you can hear me, please make this better.
Independent modules or units that have their own behaviors
An interest in fewer “pages”
- Single Page Applications
Faster development and faster onboarding
“Declarative is better than imperative.”
HTML, CSS, Bootstrap, and JQuery are still welcome to the party
“does the heavy lifting for you”.