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

What the web platform (and your app!) can learn...

What the web platform (and your app!) can learn from Node.js

The web platform has a ton of warts. They're the result of historical baggage, much of which could have been avoided.

As a frontend developer at Atlassian Bitbucket I've worked on apps big and small and have seen the benefits of composition and reuse of many small modules in the web browser. We compose together and compile over 1,000 JavaScript modules in Bitbucket's frontend and ship them to user's browsers many times a week.

Learn how small modules solve these problems and more, how the future of the web is bright, and how to bring modularization and composition to your web app.

Avatar for Will Binns-Smith

Will Binns-Smith

November 17, 2015

Other Decks in Technology

Transcript

  1. What the web platform can learn from Node.js and what

    your web frontend can learn too! Will Binns-Smith • Frontend Developer, Bitbucket • Atlassian • @wbinnssmith
  2. var request = new XMLHttpRequest(); request.addEventListener("load", function () { console.log(JSON.parse(this.responseText));

    }); request.addEventListener("error", function (e) { console.error("oh noes!!"); }); request.open("POST", "http://www.example.org/endpoint"); request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Content-Type", "application/json"); request.send(JSON.stringify({ my: 'data' }));
  3. $.ajax({ method: "POST", url: "http://example.com/endpoint", data: JSON.stringify({ my: "data" }),

    contentType: "application/json", dataType: "json", success: () => { console.log(JSON.parse(this.responseText)); }, failure: () => { console.error("oh noes!!"); } });
  4. $.ajax({ method: "POST", url: "http://example.com/endpoint", data: JSON.stringify({ my: "data" }),

    contentType: "application/json", dataType: "json" }).done(() => { console.log(JSON.parse(this.responseText)); }).fail(() => { console.error("oh noes!!"); }); PQVňTGCNʼn2TQOKUGU# $.postJSON KUPQVCTGCNVJKPI
  5. var request = require(‘request’); request.post('http://localhost:3000/endpoint', { json: true, body: {

    foo: 'bar' } }, (err, resp) => { if (err) throw Error(err); console.log(resp); });
  6. this happens a lot DOM Mutation Events -> DOM Mutation

    Observers Object.observe() -> Proxies, setters AppCache -> ServiceWorkers showModalDialog() -> <dialog>, Web Components QTQPGYC[FCVCHNQY 4GCEVHNWZUV[NG a lot of this is preventable.
  7. negative-zero 'use strict'; module.exports = function (x) { return x

    === 0 && 1 / x === -Infinity; }; DCUKECNN[QPGNKPGNQPI sindresorhus
  8. it says what it does, not how to do it

    (which in JavaScript often makes no sense anyway) why? var isNegativeZero = require(‘negative-zero’); isNegativeZero(5); // false isNegativeZero(-0); // true isNegativeZero(0); // false
  9. npm install the-future Object.assign -> require(‘object-assign’) Promise -> require(‘native-promise-only’) Map

    -> require(‘es6-map’) -> require(‘babel-core’) require(‘core-js’) PQVCEVWCNN[VJCVUOCNNDWV[QWECPRKEMCPFEJQQUG
  10. npm install emojilib { "100": "", "1234": "", "grinning": "",

    "grin": "", "joy": "", "smiley": "", "smile": "", "sweat_smile": "", "laughing": "",
  11. don’t like a module’s API? just npm install a different

    one single responsibilities make switching easy
  12. write a module with a terrible API? just fix it

    and bump the major version nobody’s apps break
  13. of course you can! take your pick. xhr superagent* axios*

    hyperquest* nets* CRKEQORCVKDNGYKVJTGSWGUV EJCKPCDNGCRK TGVWTPURTQOKUGU TGVWTPUUVTGCOUKPVJGDTQYUGT VJCPMUDTQYUGTKH[ WPKHKGUKPVGTHCEGHQTDTQYUGT CPFPQFG YQTMUKPDQVJPQFGCPFVJGDTQYUGTCUVJGUCOGOQFWNG
  14. fetch(‘http://example.com/endpoint', { method: ‘post’, headers: { 'Accept': 'application/json', 'Content-Type': 'application/json'

    }, body: JSON.stringify({ my: 'data', }) }).then(response => { return response.json(); }).then(reponse => { console.log(response); }); \QOITGCN2TQOKUGU
  15. fetch appears high-level and convenient but also comes with Request,

    Response, and WHATWG streams. let’s use these to build more things!