Commit 14f77b25 authored by Harry Brundage's avatar Harry Brundage

Batman: Make the list binding bind to an accessor which watches for when the...

Batman: Make the list binding bind to an accessor which watches for when the underlying set changes instead of setting it once in the controller action.
parent 45e277d8
class Alfred extends Batman.App class Alfred extends Batman.App
@root 'todos#all' @root 'todos#all'
@route '/completed', 'todos#completed' @route '/completed', 'todos#completed'
@route '/active', 'todos#active' @route '/active', 'todos#active'
class Alfred.TodosController extends Batman.Controller class Alfred.TodosController extends Batman.Controller
constructor: -> constructor: ->
super super
@set 'newTodo', new Alfred.Todo(completed: false) @set('newTodo', new Alfred.Todo(completed: false))
all: -> routingKey: 'todos'
@set 'currentTodos', Alfred.Todo.get('all') currentTodoSet: 'all'
@accessor 'currentTodos', -> Alfred.Todo.get(@get('currentTodoSet'))
all: ->
@set('currentTodoSet', 'all')
completed: -> completed: ->
@set 'currentTodos', Alfred.Todo.get('completed') @set 'currentTodoSet', 'completed'
@render source: 'todos/all' @render(source: 'todos/all')
active: -> active: ->
@set 'currentTodos', Alfred.Todo.get('active') @set 'currentTodoSet', 'active'
@render source: 'todos/all' @render(source: 'todos/all')
createTodo: -> createTodo: ->
@get('newTodo').save (err, todo) => @get('newTodo').save (err, todo) =>
......
// Generated by CoffeeScript 1.3.1 // Generated by CoffeeScript 1.3.3
(function() { (function() {
var Alfred, var Alfred,
__hasProp = {}.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; };
Alfred = (function(_super) { Alfred = (function(_super) {
__extends(Alfred, _super); __extends(Alfred, _super);
Alfred.name = 'Alfred';
function Alfred() { function Alfred() {
return Alfred.__super__.constructor.apply(this, arguments); return Alfred.__super__.constructor.apply(this, arguments);
} }
...@@ -28,8 +26,6 @@ ...@@ -28,8 +26,6 @@
__extends(TodosController, _super); __extends(TodosController, _super);
TodosController.name = 'TodosController';
function TodosController() { function TodosController() {
TodosController.__super__.constructor.apply(this, arguments); TodosController.__super__.constructor.apply(this, arguments);
this.set('newTodo', new Alfred.Todo({ this.set('newTodo', new Alfred.Todo({
...@@ -37,19 +33,27 @@ ...@@ -37,19 +33,27 @@
})); }));
} }
TodosController.prototype.all = function() { TodosController.prototype.routingKey = 'todos';
return this.set('currentTodos', Alfred.Todo.get('all'));
}; TodosController.prototype.currentTodoSet = 'all';
TodosController.accessor('currentTodos', function() {
return Alfred.Todo.get(this.get('currentTodoSet'));
});
TodosController.prototype.all = function() {};
TodosController.set('currentTodoSet', 'all');
TodosController.prototype.completed = function() { TodosController.prototype.completed = function() {
this.set('currentTodos', Alfred.Todo.get('completed')); this.set('currentTodoSet', 'completed');
return this.render({ return this.render({
source: 'todos/all' source: 'todos/all'
}); });
}; };
TodosController.prototype.active = function() { TodosController.prototype.active = function() {
this.set('currentTodos', Alfred.Todo.get('active')); this.set('currentTodoSet', 'active');
return this.render({ return this.render({
source: 'todos/all' source: 'todos/all'
}); });
...@@ -150,8 +154,6 @@ ...@@ -150,8 +154,6 @@
__extends(Todo, _super); __extends(Todo, _super);
Todo.name = 'Todo';
function Todo() { function Todo() {
return Todo.__super__.constructor.apply(this, arguments); return Todo.__super__.constructor.apply(this, arguments);
} }
......
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