Skip to content

Fix JMVC 3.2 shims in jquerypp/model/list #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions model/list/list.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
steal('can/model/list','jquerypp/model').then(function() {
steal('can/util', 'can/model/list','jquerypp/model', function(can) {
// List.get used to take a model or list of models
var getList = $.Model.List.prototype.get;
$.Model.List.prototype.get = function(arg) {
Expand All @@ -9,17 +9,21 @@ steal('can/model/list','jquerypp/model').then(function() {
ids.push(this.attr('id'));
});
arg = ids;
return getList.apply(this,arg);
} else if(arg.attr && arg.constructor && (id = arg.attr(arg.constructor.id))) {
arg = id;
return getList.apply(this,[arg]);
} else {
return getList.apply(this,arguments);
}
return getList.apply(this,arguments);
};
// restore the ability to push a list!arg
var push = $.Model.List.prototype.push;
$.Model.List.prototype.push = function(arg) {
if(arg instanceof $.Model.List) {
arg = can.makeArray(arg);
return push.apply(this,can.makeArray(arg));
} else {
return push.apply(this,arguments);
}
return push.apply(this,arguments);
};
});
24 changes: 24 additions & 0 deletions model/list/list_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ test("create", function(){
equals(this.people.get("a2")[0].id,"a2" , "get works")
})

test("get", function(){
var listOfPeople = new Person.List([
new Person({ id: 1000, name: "Barry" }),
new Person({ id: 1001, name: "Colin" })
]);
var instanceMatch = listOfPeople.get(listOfPeople.attr('0'));
equals(instanceMatch[0].id, 1000, 'get works with model instance');
equals(instanceMatch.length, 1, 'result is correct length');

var listMatch = listOfPeople.get(new Person.List([listOfPeople.attr('0')]));
equals(listMatch[0].id, 1000, 'get works with model list instance');
equals(listMatch.length, 1, 'result is correct length');
})

test("push another list", function(){
var listOfPeople = new Person.List();
listOfPeople.push(
new Person({ name: "Barry" }),
new Person({ name: "Colin" })
);
equals(this.people.length, 20, 'started with 20 people');
this.people.push(listOfPeople);
equals(this.people.length, 22, 'pushed 2 more people');
})

test("splice", function(){
ok(this.people.get("a1").length,"something where a1 is")
Expand Down