JavaScript Heavy Applications

JavaScript Heavy Applications

Thoughts on JavaScript heavy applications in Rails

Yehuda Katz

May 03, 2012

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

77 slides
  1. (function() { var load = function() { $.getJSON("/bootstrap", function(json) {

    // bootstrap }); }; $(document).ready(load); })(); BUILD.
  2. (function() { var load = function() { $.getJSON("/bootstrap", function(json) {

    // bootstrap }); }; $(document).ready(load); })(); BUILD.
  3. ▪ Every le gets a scratchpad scope. ▪ Setting or

    getting an unexpected global is an editor error. ▪ You can control "unexpected global" on a per-project or per- le scope. NET RESULT.
  4. (function() { var load = function() { $.getJSON("/bootstrap", function(json) {

    // bootstrap }); }; $(document).ready(load); })(); BUILD.
  5. register("app.js", "(function() {\nvar load = function() {\n $.getJSON("/bootstrap", function(json) {\n

    // bootstrap\n }); \n};\n\n$(document).ready(load);\n});\n//@ sourceURL=app.js"); BUILD.
  6. register("app.js", "(function() {\nvar load = function() {\n $.getJSON("/bootstrap", function(json) {\n

    // bootstrap\n }); \n};\n\n$(document).ready(load);\n});\n//@ sourceURL=app.js"); registered = { "app.js": ... }; BUILD.
  7. register("app.js", "(function() {\nvar load = function() {\n $.getJSON("/bootstrap", function(json) {\n

    // bootstrap\n }); \n};\n\n$(document).ready(load);\n});\n//@ sourceURL=app.js"); registered = { "app.js": ... }; require("app.js"); // jQuery.globalEval(registered["app.js"]); BUILD.
  8. Person = Model.extend({ fullName: function() { return this.firstName + '

    ' + this.lastName } }); data = { "firstName": "Yehuda", "lastName": "Katz" } IN YOUR HEAD.
  9. ▪ Include the root? ▪ Include other resources in a

    response? ▪ "Sideloading" ▪ How to represent associations? ▪ Avoiding duplication ▪ Lazily populated ▪ Bulk loading? IN REALITY.
  10. { "post": { "id": 1, "title": "First post", "body": "Body

    of the first post", "author_id": 1, "comments": [ 1, 2 ] }, "comments": [ { "id": 1, "body": "first!", "author_id": 1 }, { "id": 2, "body": "second", "author_id": 2 } }], "authors": [ { "id": 1, "name": "Yehuda Katz" }, { "id": 2, "name": "Tom Dale" } ] } MY OPINION.
  11. { "post": { "href": "/posts/1", "title": "First post", "body": "Body

    of the first post", "author_href": "/people/1", "comments": [ "/comments/1", "/comments/2" ] }, "comments": [ { "href": "/comments/1", "body": "first!", "author_href": "/people/1" }, { "id": "/comments/2", "body": "second", "author_href": "/people/2" } }], "authors": [ { "href": "/people/1", "name": "Yehuda Katz" }, { "href": "/people/2", "name": "Tom Dale" } ] } USING HREFS.
  12. { "posts": [{ "id": 1, "title": "First post", "body": "Body

    of the first post", "author_id": 1, }, { "id": 2, "title": "Second post", "body": "Body of the second post", "author_id": 2 }, { "id": 3, "title": "Third post", "body": "Body of the third post", "author_id": 1 }], "authors": [ { "id": 1, "name": "Yehuda Katz" }, { "id": 2, "name": "Tom Dale" } ] } MY OPINION.
  13. { "posts": [{ "href": "/posts/1", "title": "First post", "body": "Body

    of the first post", "author_href": "/people/1", }, { "href": "/posts/2", "title": "Second post", "body": "Body of the second post", "author_href": "/people/2" }, { "href": "/posts/3", "title": "Third post", "body": "Body of the third post", "author_id": "/people/1" }], "authors": [ { "href": "/people/1", "name": "Yehuda Katz" }, { "href": "/people/2", "name": "Tom Dale" } ] } USING HREFS.
  14. GETTING THIS FINISHED AND PACKAGED NICELY IS MY PASSION THESE

    DAYS. I hope I have illustrated that significant workflow improvements are possible and desirable. My biggest gripe with the Rails asset pipeline work so far is that it hasn't really tried to reach for the kinds of workflow improvements we have come to expect from Rails. Concatenating files is nice, but it barely scratches the surface.

More Decks by Yehuda Katz

Other Decks in Technology