Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

move refactorings - always deal with collections...

  • Loading branch information...
commit a1adde7c62a01186473a51edf7afc0a12923d8be 1 parent b6b55ca
Davis W. Frank authored
View
5 app/agents/router-agent.js
@@ -45,11 +45,8 @@
}
function updateWith(filterName) {
- var tasks = taskList[filterName](currentItem);
- var list = new bulldog.TaskList(tasks);
-
router.updateNavigationView();
- router.updateTaskListView(list);
+ router.updateTaskListView(taskList[filterName](currentItem));
}
function projectsFrom(tasks) {
View
15 app/collections/task-list.js
@@ -10,9 +10,9 @@
self.actionsForProject = function(projectName) {
if (projectName == 'All') {
- return this.models;
+ return self;
} else {
- return this.filter(byProjectName);
+ return filtered(byProjectName);
}
function byProjectName(task) {
@@ -21,7 +21,7 @@
};
self.actionsForContext = function(contextName) {
- return this.filter(byContextName);
+ return filtered(byContextName);
function byContextName(task) {
return task.get('context') == contextName;
@@ -29,7 +29,7 @@
};
self.nextActionsForContext = function(contextName) {
- return this.filter(forNextActionsByContextName);
+ return filtered(forNextActionsByContextName);
function forNextActionsByContextName(task) {
return task.get('context') == contextName && task.isNextAction();
@@ -44,5 +44,12 @@
}
return task.get('priority') || "ZZ";
}
+
+ function filtered(filterFn) {
+ var tasks = self.filter(filterFn);
+ return new namespace.TaskList(tasks);
+ }
+
+
};
}(jQuery, bulldog));
View
4 spec/app/agents/router-agent-spec.js
@@ -28,12 +28,10 @@ describe("bulldog.RouterAgent", function() {
expect(router.updateTaskListView).toHaveBeenCalled();
});
- it("should give the router all of the tasks, in priority order", function() {
+ it("should give the router all of the tasks", function() {
taskList = router.updateTaskListView.mostRecentCall.args[0];
expect(taskList.length).toEqual(5);
- expect(taskList.first().get('action')).toEqual('baz');
- expect(taskList.last().get('action')).toEqual('bar');
});
});
View
6 spec/app/collections/tasklist-spec.js
@@ -40,7 +40,7 @@ describe("bulldog.TaskList", function () {
describe("when the project is something", function() {
it("should return only the tasks for that project", function() {
expect(taskList.actionsForProject('Zip').length).toEqual(3);
- expect(taskList.actionsForProject('Zip')[0].get('action')).toEqual('corge');
+ expect(taskList.actionsForProject('Zip').first().get('action')).toEqual('quux');
});
});
});
@@ -48,14 +48,14 @@ describe("bulldog.TaskList", function () {
describe("#actionsForContext", function() {
it("should return only tasks for the requested context", function() {
expect(taskList.actionsForContext('pc').length).toEqual(2);
- expect(taskList.actionsForContext('pc')[0].get('action')).toEqual('baz');
+ expect(taskList.actionsForContext('pc').first().get('action')).toEqual('baz');
});
});
describe("#nextActionsForContext", function() {
it("should return only tasks for the requested context", function() {
expect(taskList.nextActionsForContext('pc').length).toEqual(1);
- expect(taskList.nextActionsForContext('pc')[0].get('action')).toEqual('baz');
+ expect(taskList.nextActionsForContext('pc').first().get('action')).toEqual('baz');
});
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.