Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Javascript: One language to rule them all

Simon Wood
November 03, 2016

Javascript: One language to rule them all

Javascript, a love/hate language for some. It is our only choice for client side programming which has has seen a rise in recent years, but Javascript is also a successful server side language too. What is it about this language that make it a universal language? Simon will cover why the asynchronous nature of Javascript works well server side and how React and Single Page Web Applications have push Javascript on the client side.

Simon Wood

November 03, 2016
Tweet

More Decks by Simon Wood

Other Decks in Technology

Transcript

  1. / @hpoom 4 What I am going to cover Single

    Page Web Apps Javascript Language Future of Javascript Server Side Javascript
  2. @hpoom 5 "JavaScript: Good Parts vs. The Rest" by Nathan

    Smith. Licensed under Creative Commons.- https://flic.kr/p/8aGB5o
  3. @hpoom 6 Math.min() < Math.max(); // false typeof NaN; //

    “number” typeof null; // ”object” null instanceof Object; // false 0.1 + 0.2 == 0.3; // false
  4. @hpoom 17 $( document ).ready(function() { // Handler for .ready()

    called. }); $(function() { // Handler for .ready() called. });
  5. @hpoom 31 Actions – Helper methods that facilitate passing data

    to the Dispatcher Dispatcher – Receives actions and broadcasts payloads to registered callbacks Stores – Containers for application state & logic that have callbacks registered to the dispatcher Controller Views – React Components that grab the state from Stores and pass it down via props to child components.
  6. @hpoom 36 var Component = React.createClass({ render: function() { return

    ( <h1>Hello World</h1> ) } }) ReactDOM.render(<Component/>, document.body)
  7. @hpoom 37 var Component = React.createClass({ render: function() { return

    React.createElement( “h1", null, "Hello World” ) } }) ReactDOM.render(<Component/>, document.body)
  8. @hpoom 38 var Component = React.createClass({ render: function() { return

    ( <h1>Hello World</h1> ) } }) ReactDOM.render(<Component/>, document.body)
  9. @hpoom 40 var Component = React.createClass({ propTypes: { name: React.PropTypes.string.isRequired

    }, render: function() { return ( <h1>Hello {this.props.name}</h1> ) } }) ReactDOM.render(<Component name=“Jimmy”/>, document.body)
  10. @hpoom 41 var Component = React.createClass({ propTypes: { name: React.PropTypes.string.isRequired

    }, render: function() { return ( <h1>Hello {this.props.name}</h1> ) } }) ReactDOM.render(<Component name=“Jimmy”/>, document.body)
  11. @hpoom 43 var Counter = React.createClass({ getInitialState: function() { return

    { count: 0 } }, render: function() { return ( <button onClick={this.onButtonClick}> {this.state.count} </button> ) } onButtonClick: function() { this.setState({ count: ++this.state.count }) } }) ReactDOM.render(<Counter/>, document.body)
  12. @hpoom 44 var Counter = React.createClass({ getInitialState: function() { return

    { count: 0 } }, render: function() { return ( <button onClick={this.onButtonClick}> {this.state.count} </button> ) } onButtonClick: function() { this.setState({ count: ++this.state.count }) } }) ReactDOM.render(<Counter/>, document.body)
  13. @hpoom 45 var Counter = React.createClass({ getInitialState: function() { return

    { count: 0 } }, render: function() { return ( <button onClick={this.onButtonClick}> {this.state.count} </button> ) } onButtonClick: function() { this.setState({ count: ++this.state.count }) } }) ReactDOM.render(<Counter/>, document.body)
  14. @hpoom 46 var Counter = React.createClass({ getInitialState: function() { return

    { count: 0 } }, render: function() { return ( <button onClick={this.onButtonClick}> {this.state.count} </button> ) } onButtonClick: function() { this.setState({ count: ++this.state.count }) } }) ReactDOM.render(<Counter/>, document.body)
  15. @hpoom 67 asyncCall().then(function(data1){ // do something... return anotherAsyncCall(); }).then(function(data2){ //

    do something... return oneMoreAsyncCall(); }).then(function(data3){ // the third and final async response }).fail(function(err) { // handle any error from any of the above calls }).done();
  16. @hpoom 73 var express = require('express'); var app = express();

    var globalCount = 0; app.get('/', function (req, res) { var localCount = 0; globalCount++; localCount++; res.send('You visited #' + localCount + ' times! Total visits #' + globalCount); }); app.listen(8080);
  17. @hpoom 74 You visited #1 times! Total visits #1 You

    visited #1 times! Total visits #2 You visited #1 times! Total visits #3 You visited #1 times! Total visits #4 You visited #1 times! Total visits #5
  18. @hpoom 76 1.Close the server to stop accepting new connections.

    2.Wait for existing connections to finish and close normally. 3.Only exit the process once all clients have finished and disconnected happily. 4.Failsafe: before starting the shutdown, it’s advisable to set an exit time limit. If the shutdown hangs or takes too long, something else is probably wrong so exit the process anyway.
  19. @hpoom Thank you please contact me if you have any

    questions Twitter: @hpoom logo 92 By Simon Wood www.CTO-meetup.com