PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/src/js-example/apps/commits/client.js

https://github.com/coltonTB/ezel
JavaScript | 46 lines | 29 code | 7 blank | 10 comment | 0 complexity | 487fa335a006cf9504d6c547b3e95f2d MD5 | raw file
Possible License(s): MIT
  1. //
  2. // The client-side code for the commits page.
  3. //
  4. // [Browserify](https://github.com/substack/node-browserify) lets us write this
  5. // code as a common.js module, which means requiring dependecies instead of
  6. // relying on globals. This module exports the Backbone view and an init
  7. // function that gets used in /assets/commits.js. Doing this allows us to
  8. // easily unit test these components, and makes the code more modular and
  9. // composable in general.
  10. //
  11. var Backbone = require('backbone'),
  12. $ = require('jquery'),
  13. sd = require('sharify').data,
  14. Commits = require('../../collections/commits.js'),
  15. listTemplate = function() {
  16. return require('./templates/list.jade').apply(null, arguments)
  17. };
  18. Backbone.$ = $;
  19. module.exports.CommitsView = CommitsView = Backbone.View.extend({
  20. initialize: function() {
  21. this.collection.on('sync', this.render, this);
  22. },
  23. render: function() {
  24. this.$('#commits-list').html(listTemplate({ commits: this.collection.models }));
  25. },
  26. events: {
  27. 'change .search-input': 'changeRepo'
  28. },
  29. changeRepo: function(e) {
  30. this.collection.repo = $(e.target).val();
  31. this.collection.fetch();
  32. }
  33. });
  34. module.exports.init = function() {
  35. new CommitsView({
  36. el: $('body'),
  37. collection: new Commits(sd.COMMITS, { owner: 'artsy', repo: 'flare' })
  38. });
  39. };