Commit c1cfbfa8 authored by Sindre Sorhus's avatar Sindre Sorhus

Spine: Fix todos not updating when checked while on a route

parent b47026fd
// Generated by CoffeeScript 1.3.1
(function() { (function() {
var TodoApp, var TodoApp,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = Object.prototype.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
TodoApp = (function(_super) { TodoApp = (function(_super) {
...@@ -9,6 +10,8 @@ ...@@ -9,6 +10,8 @@
__extends(TodoApp, _super); __extends(TodoApp, _super);
TodoApp.name = 'TodoApp';
ENTER_KEY = 13; ENTER_KEY = 13;
TodoApp.prototype.elements = { TodoApp.prototype.elements = {
...@@ -30,11 +33,15 @@ ...@@ -30,11 +33,15 @@
function TodoApp() { function TodoApp() {
this.renderFooter = __bind(this.renderFooter, this); this.renderFooter = __bind(this.renderFooter, this);
this.toggleElems = __bind(this.toggleElems, this); this.toggleElems = __bind(this.toggleElems, this);
this.addAll = __bind(this.addAll, this); this.addAll = __bind(this.addAll, this);
this.addNew = __bind(this.addNew, this); TodoApp.__super__.constructor.apply(this, arguments);
this.addNew = __bind(this.addNew, this);
TodoApp.__super__.constructor.apply(this, arguments);
Todo.bind('create', this.addNew); Todo.bind('create', this.addNew);
Todo.bind('refresh', this.addAll); Todo.bind('refresh change', this.addAll);
Todo.bind('refresh change', this.toggleElems); Todo.bind('refresh change', this.toggleElems);
Todo.bind('refresh change', this.renderFooter); Todo.bind('refresh change', this.renderFooter);
Todo.fetch(); Todo.fetch();
...@@ -44,6 +51,7 @@ ...@@ -44,6 +51,7 @@
/* /*
TODO: Need to figure out why the route doesn't trigger `change` event TODO: Need to figure out why the route doesn't trigger `change` event
*/ */
Todo.trigger('refresh'); Todo.trigger('refresh');
return this.filters.removeClass('selected').filter("[href='#/" + this.filter + "']").addClass('selected'); return this.filters.removeClass('selected').filter("[href='#/" + this.filter + "']").addClass('selected');
} }
...@@ -97,7 +105,8 @@ ...@@ -97,7 +105,8 @@
/* /*
TODO: Model updateAttribute sometimes won't stick: TODO: Model updateAttribute sometimes won't stick:
https://github.com/maccman/spine/issues/219 https://github.com/maccman/spine/issues/219
*/ todo.updateAttribute('completed', e.target.checked); */
todo.updateAttribute('completed', e.target.checked);
return todo.trigger('update', todo); return todo.trigger('update', todo);
}); });
}; };
......
// Generated by CoffeeScript 1.3.1
(function() { (function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
__hasProp = Object.prototype.hasOwnProperty, __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
window.Todos = (function(_super) { window.Todos = (function(_super) {
...@@ -8,6 +9,8 @@ ...@@ -8,6 +9,8 @@
__extends(Todos, _super); __extends(Todos, _super);
Todos.name = 'Todos';
ENTER_KEY = 13; ENTER_KEY = 13;
TPL = Handlebars.compile($('#todo-template').html()); TPL = Handlebars.compile($('#todo-template').html());
...@@ -25,7 +28,8 @@ ...@@ -25,7 +28,8 @@
}; };
function Todos() { function Todos() {
this.render = __bind(this.render, this); Todos.__super__.constructor.apply(this, arguments); this.render = __bind(this.render, this);
Todos.__super__.constructor.apply(this, arguments);
this.todo.bind('update', this.render); this.todo.bind('update', this.render);
this.todo.bind('destroy', this.release); this.todo.bind('destroy', this.release);
} }
...@@ -60,7 +64,9 @@ ...@@ -60,7 +64,9 @@
}; };
Todos.prototype.finishEditOnEnter = function(e) { Todos.prototype.finishEditOnEnter = function(e) {
if (e.which === ENTER_KEY) return this.finishEdit(); if (e.which === ENTER_KEY) {
return this.finishEdit();
}
}; };
return Todos; return Todos;
......
// Generated by CoffeeScript 1.3.1
(function() { (function() {
var __hasProp = Object.prototype.hasOwnProperty, var __hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }; __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
window.Todo = (function(_super) { window.Todo = (function(_super) {
__extends(Todo, _super); __extends(Todo, _super);
Todo.name = 'Todo';
function Todo() { function Todo() {
Todo.__super__.constructor.apply(this, arguments); return Todo.__super__.constructor.apply(this, arguments);
} }
Todo.configure('Todo', 'title', 'completed'); Todo.configure('Todo', 'title', 'completed');
......
...@@ -19,7 +19,7 @@ class TodoApp extends Spine.Controller ...@@ -19,7 +19,7 @@ class TodoApp extends Spine.Controller
constructor: -> constructor: ->
super super
Todo.bind 'create', @addNew Todo.bind 'create', @addNew
Todo.bind 'refresh', @addAll Todo.bind 'refresh change', @addAll
Todo.bind 'refresh change', @toggleElems Todo.bind 'refresh change', @toggleElems
Todo.bind 'refresh change', @renderFooter Todo.bind 'refresh change', @renderFooter
Todo.fetch() Todo.fetch()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment