Permalink
Browse files

Feature: Added support for adding multiple parsed items

  • Loading branch information...
Theo Cushion
Theo Cushion committed May 2, 2012
1 parent b713dd9 commit 91f132ca98d7015f8648ce870874b1dab8ffb724
Showing with 18 additions and 3 deletions.
  1. +5 −0 spec/javascripts/ParsedItemsSpec.js
  2. +13 −3 src/parser/parsed_items.js
@@ -51,6 +51,11 @@ describe("ParsedItems", function(){
expect(returned).toEqual({id: "23", nested: {foo: "bar", baz: "b"}});
expect(items.all()).toEqual([{id: "23", nested: {foo: "bar", baz: "b"}}]);
});
+ it("should add multiple items to the list and return item", function(){
+ var returned = items.add([{id: "23", foo: "bar"},{id:"24", a: "a"}]);
+ expect(returned).toEqual([{id: "23", foo: "bar"},{id:"24", a: "a"}]);
+ expect(items.all()).toEqual([{id: "23", foo: "bar"},{id:"24", a: "a"}]);
+ });
});
describe("all", function(){
View
@@ -23,8 +23,7 @@ Frabjous.ParsedItems = function(){
return obj1;
};
- // Privileged methods
- this.add = function(newItem){
+ var add_individual = function(newItem){
if(!Ember.none(newItem) && !Ember.none(newItem.id)){
var id = newItem.id;
var originalItem = data[id];
@@ -46,7 +45,18 @@ Frabjous.ParsedItems = function(){
data[id] = originalItem;
return originalItem;
- }
+ }
+ };
+
+ // Privileged methods
+ this.add = function(newItems){
+ if(newItems instanceof Array){
+ return $.map(newItems, function(newItem){
+ return add_individual(newItem);
+ });
+ } else {
+ return add_individual(newItems);
+ }
};
this.all = function(){

0 comments on commit 91f132c

Please sign in to comment.