can-connect
Advanced tools
Comparing version 0.6.0-pre.13 to 0.6.0-pre.14
{ | ||
"name": "can-connect", | ||
"version": "0.6.0-pre.13", | ||
"version": "0.6.0-pre.14", | ||
"description": "Data connection middleware and utilities", | ||
@@ -12,3 +12,3 @@ "main": "can-connect.js", | ||
"can-observation": "^3.0.0-pre.5", | ||
"can-set": "^0.6.0-pre.6", | ||
"can-set": "^0.6.0-pre.8", | ||
"can-stache": "^3.0.0-pre.8", | ||
@@ -15,0 +15,0 @@ "can-stache-bindings": "^3.0.0-pre.9", |
@@ -229,3 +229,3 @@ "use strict"; | ||
if (prop !== 'data') { | ||
list.attr(prop, val); | ||
list[list.set ? "set" : "attr"](prop, val); | ||
} | ||
@@ -328,3 +328,5 @@ }); | ||
if(props && typeof props === 'object') { | ||
if("attr" in instance) { | ||
if("set" in instance) { | ||
instance.set(isFunction(props.get) ? props.get() : props, this.constructor.removeAttr || false); | ||
} else if("attr" in instance) { | ||
instance.attr(isFunction(props.attr) ? props.attr() : props, this.constructor.removeAttr || false); | ||
@@ -338,3 +340,2 @@ } else { | ||
} | ||
} | ||
@@ -341,0 +342,0 @@ |
@@ -229,2 +229,3 @@ | ||
list[this.listSetProp || "__listSet"] = set; | ||
copyMetadata(listData, list); | ||
return list; | ||
@@ -499,2 +500,4 @@ } | ||
idMerge(list, instanceList, this.id.bind(this), this.hydrateInstance.bind(this)); | ||
copyMetadata(listData, list); | ||
}, | ||
@@ -691,1 +694,17 @@ /** | ||
}); | ||
function copyMetadata(listData, list){ | ||
for(var prop in listData) { | ||
if(prop !== "data") { | ||
// this is map infultrating constructor, but it's alright here. | ||
if(typeof list.set === "function") { | ||
list.set(prop, listData[prop]); | ||
} else if(typeof list.attr === "function") { | ||
list.attr(prop, listData[prop]); | ||
} else { | ||
list[prop] = listData[prop]; | ||
} | ||
} | ||
} | ||
} |
@@ -309,1 +309,35 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
QUnit.asyncTest("pagination loses the bigger set (#126)", function(){ | ||
var todosAlgebra = new canSet.Algebra( | ||
canSet.props.offsetLimit("offset","limit") | ||
); | ||
var connection = connect([dataLocalStorage],{ | ||
name: "todos", | ||
algebra: todosAlgebra | ||
}); | ||
connection.updateListData( | ||
{ data: [{id: 0},{id: 1}] }, | ||
{ offset: 0, limit: 2}).then(function(){ | ||
return connection.updateListData( | ||
{ data: [{id: 2},{id: 3}] }, | ||
{ offset: 2, limit: 2}); | ||
}).then(function(){ | ||
connection.getListData({ offset: 0, limit: 2}).then(function(listData){ | ||
QUnit.deepEqual(listData, { data: [{id: 0},{id: 1}] }); | ||
QUnit.start(); | ||
}, function(){ | ||
QUnit.ok(false, "no data"); | ||
QUnit.start(); | ||
}); | ||
}).catch(function(e){ | ||
QUnit.ok(false, "something broke"); | ||
QUnit.start(); | ||
}); | ||
}); |
@@ -68,2 +68,4 @@ /** | ||
_instances: {}, | ||
// Returns the sets stored in localstorage like: | ||
// `{setKey: {set: set, setKey: setKey}}` | ||
getSetData: function(){ | ||
@@ -87,2 +89,3 @@ | ||
}, | ||
// returns an array of sets | ||
_getSets: function(setData){ | ||
@@ -92,3 +95,3 @@ var sets = []; | ||
for(var setKey in setData) { | ||
sets.push(setData[setKey].set); | ||
sets.push(JSON.parse(setKey)); | ||
} | ||
@@ -125,10 +128,9 @@ return sets; | ||
}, | ||
removeSet: function(setKey, noUpdate) { | ||
// Removes one particular set | ||
removeSet: function(setKey) { | ||
var sets = this.getSetData(); | ||
localStorage.removeItem(this.name+"/set/"+setKey); | ||
delete sets[setKey]; | ||
if(noUpdate !== true) { | ||
this.updateSets(sets); | ||
} | ||
}, | ||
// updates the available sets to what's provided in sets. | ||
updateSets: function(sets){ | ||
@@ -145,9 +147,12 @@ var setData = this._getSets(sets); | ||
if(newSetKey !== setDatum.setKey) { | ||
// add the new one | ||
// get current sets | ||
var sets = this.getSetData(); | ||
var oldSetKey = setDatum.setKey; | ||
sets[newSetKey] = setDatum; | ||
setDatum.setKey = newSetKey; | ||
// remove the old one | ||
this.removeSet(oldSetKey); | ||
localStorage.removeItem(this.name+"/set/"+setDatum.setKey); | ||
delete sets[setDatum.setKey]; | ||
// add the new one | ||
sets[newSetKey] = {setKey: newSetKey, set: newSet}; | ||
this.updateSets(sets); | ||
} | ||
@@ -397,3 +402,2 @@ } | ||
var self = this; | ||
for(var setKey in sets) { | ||
@@ -403,4 +407,5 @@ var setDatum = sets[setKey]; | ||
if(union) { | ||
// Get the data for the old set we can union with. | ||
return this.getListData(setDatum.set).then(function(setData){ | ||
// update the old set to the new set | ||
self.updateSet(setDatum, canSet.getUnion(setDatum.set, set, getItems(setData), items, this.algebra), union); | ||
@@ -407,0 +412,0 @@ }); |
@@ -286,1 +286,34 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
QUnit.asyncTest("pagination loses the bigger set (126)", function(){ | ||
var todosAlgebra = new canSet.Algebra( | ||
canSet.props.offsetLimit("offset","limit") | ||
); | ||
var connection = connect([memoryCache],{ | ||
name: "todos", | ||
algebra: todosAlgebra | ||
}); | ||
connection.updateListData( | ||
{ data: [{id: 0},{id: 1}] }, | ||
{ offset: 0, limit: 2}).then(function(){ | ||
return connection.updateListData( | ||
{ data: [{id: 2},{id: 3}] }, | ||
{ offset: 2, limit: 2}); | ||
}).then(function(){ | ||
connection.getListData({ offset: 0, limit: 2}).then(function(listData){ | ||
QUnit.deepEqual(listData, { data: [{id: 0},{id: 1}] }); | ||
QUnit.start(); | ||
}, function(){ | ||
QUnit.ok(false, "no data"); | ||
QUnit.start(); | ||
}); | ||
}).catch(function(e){ | ||
QUnit.ok(false, "something broke"); | ||
QUnit.start(); | ||
}); | ||
}); |
@@ -203,1 +203,30 @@ var QUnit = require("steal-qunit"); | ||
}); | ||
asyncTest("metadata transfered through fall through cache (#125)", function(){ | ||
var cacheConnection = { | ||
getListData: function(){ | ||
return testHelpers.asyncResolve({data: [{id: 1}]}); | ||
}, | ||
updateListData: function(){} | ||
}; | ||
var getDataBehavior = function(base, options){ | ||
return { | ||
getListData: function(){ | ||
return testHelpers.asyncResolve({data: [{id: 1}], count: 5}); | ||
} | ||
}; | ||
}; | ||
var connection = connect([getDataBehavior, constructor,fallThroughCache,constructorStore, dataCallbacks],{ | ||
cacheConnection: cacheConnection | ||
}); | ||
connection.getList({}).then(function(list){ | ||
setTimeout(function(){ | ||
QUnit.equal(list.count, 5, "expando added"); | ||
QUnit.start(); | ||
},10); | ||
}); | ||
}); |
436418
11548
Updatedcan-set@^0.6.0-pre.8