1 / 60

JavaScript

JavaScript. n a frontendu. Miho Tomić. 3. JavaScript Evolucija. JavaScript evolucija. JavaScript evolucija. jQuery je odličan. JavaScript evolucija. jQuery je odličan, ali. $.getJSON("/items", function (data) { var list = ""; $.each(data, function (index, value) {

birch
Download Presentation

JavaScript

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript na frontendu Miho Tomić

  2. 3 JavaScriptEvolucija

  3. JavaScript evolucija

  4. JavaScript evolucija • jQuery je odličan

  5. JavaScript evolucija • jQuery je odličan, ali... $.getJSON("/items", function (data) { var list = ""; $.each(data, function (index, value) { list += "<li id=\"item-" + value.Id + "\">" + value.Name + "</li>"; }); $("ul").append(list); $("li").click(function () { var $this = $(this); var id = $this.attr("id").replace("item-", ""); $.post("/items", { id: id }, function () { $this.fadeOut(function () { $this.remove(); }); }); }); });

  6. JavaScript evolucija • jQuery je odličan, ali... • callback hell $.getJSON("/items", function (data) { var list = ""; $.each(data, function (index, value) { list += "<li id=\"item-" + value.Id + "\">" + value.Name + "</li>"; }); $("ul").append(list); $("li").click(function () { var $this = $(this); var id = $this.attr("id").replace("item-", ""); $.post("/items", { id: id }, function () { $this.fadeOut(function () { $this.remove(); }); }); }); });

  7. JavaScript evolucija Što nam je potrebno? • Apstrakcija • Razdvajanje UI od podataka • Pojednostavniti callback

  8. JavaScript evolucija Što nam je potrebno? • RESTfulservis za rad s podacima • Eventi • Templatesustav • „Maleni” JavaScriptframework • Sustav za navigaciju stranicama

  9. Postoji rješenje  Javascript framework

  10. Angular.js Ember.js Fidel Sammy.js Cappucino Agility.js JavascriptMVC Sproutcore Batman.js CanJS Backbone.js Knockout.js

  11. Backbone.js

  12. Backbone.js Nudistrukturu web aplikaciji: • Model • Collection • View

  13. Backbone.js • jQuery • Underscore.js • Json2.js

  14. Backbone.js MVC Model / CollectionTemplate (View)View (Controller)Router

  15. Backbone.js MVC Model / Collection Template (View)View (Controller)Router

  16. Backbone.js MVC Model / CollectionTemplate (View) View (Controller)Router

  17. Backbone.js MVC Model / CollectionTemplate (View) View (Controller) Router

  18. Backbone.js MVC Model / CollectionTemplate (View) View (Controller) Router

  19. Model • Predstavlja podatke • Perzistencija • Eventi

  20. Backbone.js Model / Collection- View - Template - Router Model • Fetch HTTP GET /url • Save (novi) HTTP POST /url • Save HTTP PUT /url/id • Destroy HTTP DELETE /url/id

  21. Backbone.js Model / Collection- View - Template - Router var Item = Backbone.Model.extend({idAttribute: “id”, url: “/items”});

  22. Backbone.js Model / Collection- View - Template - Router var item = new Item(); item.set({ name: “Appstart” }); // trigger event change item.save(); // trigger event sync

  23. Collection • Lista modela • Underscore metode

  24. Backbone.js Model / Collection- View - Template - Router var Items = Backbone.Collection.extend({model: Item, url: "/items"});

  25. Backbone.js Model / Collection- View - Template - Router var items = new Items(); items.fetch(); // trigger reset

  26. View • Manipulacija DOM-a • Delegira DOM evente • Sadrži Model / Collection

  27. Backbone.js Model / Collection- View - Template - Router View View (Collection) View (Model)

  28. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({el: $("ul"), initialize: function () { this.collection.bind("reset", this.render,this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  29. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({ el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  30. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  31. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  32. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  33. Backbone.js Model / Collection- View - Template - Router varListView = Backbone.View.extend({el: $("ul"), initialize: function () { this.collection.bind("reset", this.render, this); }, render: function () { this.collection.each(this.addItem, this);return this; }, addItem: function (item) { varitemView = new ItemView({ varItemView = Backbone.View.extend({ model: item tagName: "li", }); render: function () { this.$el.append(itemView.el); this.$el.text(this.model.get("Name")); itemView.render(); return this; } } }); });

  34. Backbone.js Model / Collection- View - Template - Router var items = new Items(); varlistView = new ListView({collection: items }); items.fetch();

  35. Template (Underscore.js) JavaScript template služe za prikaz podataka modela. • Mustache • HandleBars

  36. Backbone.js Model / Collection- View - Template - Router <script type="text/template" id="item-template"><li> <%= name %></li> </script>

  37. Backbone.js Model / Collection- View - Template - Router varItemView = Backbone.View.extend({… template: _.template($("#item-template").html()), render: function () { this.$el.html(this.template(this.model.toJSON()));return this; } … });

  38. Router • Mapiranje url u funkcije • Omogućuje povijest

  39. Backbone.js Model / Collection- View - Template - Router varAppRouter = Backbone.Router.extend({routes: { "": "initialize“ }, initialize: function () {… } });

  40. Backbone.js Linkedin

  41. Backbone.js FourSquare

  42. Backbone.js Groupon

  43. Backbone.js + • Malen • Moćan • Kod je čist (lako se održava) - • Presložen (kod manjih aplikacija) • Nije pravi framework

  44. 3 AngularJS

  45. ANGULARJS • MVC framework

  46. ANGULARJS • MVC framework • namijenjen CRUD aplikacijama

  47. ANGULARJS • MVC framework • Namijenjen CRUD aplikacijama • Two – way povezivanje podataka

  48. ANGULARJS • MVC framework • Namijenjen CRUD aplikacijama • Two – way povezivanje podataka • Dependency injection

  49. ANGULARJS • MVC framework • Namijenjen CRUD aplikacijama • Two – way povezivanje podataka • Dependency injection • Direktive

More Related