can-connect
Advanced tools
Comparing version 4.0.2 to 4.0.3
{ | ||
"name": "can-connect", | ||
"version": "4.0.2", | ||
"version": "4.0.3", | ||
"description": "Data connection middleware and utilities", | ||
@@ -5,0 +5,0 @@ "main": "can-connect.js", |
@@ -15,2 +15,3 @@ var connect = require("../can-connect"); | ||
var canReflect = require("can-reflect"); | ||
var canSymbol = require("can-symbol"); | ||
@@ -653,1 +654,64 @@ QUnit.module("can-connect/real-time",{}); | ||
}); | ||
QUnit.test("Properly inserts in an empty list", function(assert){ | ||
var done = assert.async(); | ||
assert.expect(1); | ||
var todos = []; | ||
var connection = connect([ | ||
function(){ | ||
return { | ||
list: function(items) { | ||
var list = new DefineList(items.data); | ||
var oldSplice = list[canSymbol.for("can.splice")]; | ||
list[canSymbol.for("can.splice")] = function(index){ | ||
assert.equal(index, 0, "inserted in the 0 spot, not undefined"); | ||
oldSplice.call(this, arguments); | ||
}; | ||
// simulate the can-connet/can/map/map behaviour | ||
// adding the list to the listStore | ||
connection.addListReference(list, {}); | ||
return list; | ||
}, | ||
getListData: function(){ | ||
return Promise.resolve(todos); | ||
}, | ||
destroyData: function() { | ||
// simulate an empty object response from server | ||
return Promise.resolve({}); | ||
}, | ||
updateData: function(data){ | ||
return Promise.resolve(canReflect.serialize(data)); | ||
}, | ||
createData: function(data){ | ||
return Promise.resolve(canReflect.serialize({name: data.name, id: "xyz"})); | ||
} | ||
}; | ||
}, | ||
dataCallbacks, | ||
realTime, | ||
constructor, | ||
constructorStore | ||
], { | ||
queryLogic: new QueryLogic({ | ||
identity: ["id"] | ||
}) | ||
}); | ||
connection.getList({}).then(function(list){ | ||
list.on("length", function(){ | ||
assert.ok(true, "Length should change"); | ||
}); | ||
connection.save( {name: "new-item"} ); | ||
return list; | ||
}).then(function(){ | ||
done(); | ||
}, function(err){ | ||
setTimeout(function(){ | ||
throw err; | ||
},1); | ||
done(); | ||
}); | ||
}); |
@@ -139,2 +139,3 @@ "use strict"; | ||
function updateList(list, getRecord, currentIndex, newIndex) { | ||
if(currentIndex === -1) { // item is not in the list | ||
@@ -144,2 +145,4 @@ | ||
canReflect.splice(list, newIndex, 0, [getRecord()]); | ||
} else { | ||
canReflect.splice(list, 0, 0, [getRecord()]); | ||
} | ||
@@ -169,2 +172,6 @@ } | ||
function updateListWithItem(list, recordData, currentIndex, newIndex, connection, set){ | ||
// this is cleaning up a bug with QueryLogic.index where it can return undefined | ||
if( newIndex === undefined ) { | ||
newIndex = -1; | ||
} | ||
// we are inserting right where we already are. | ||
@@ -171,0 +178,0 @@ if(currentIndex !== -1 && (newIndex === currentIndex + 1 || newIndex === currentIndex)) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
526753
12326