can-connect
Advanced tools
Comparing version 4.0.3 to 4.0.4
@@ -7,2 +7,5 @@ var QUnit = require("steal-qunit"); | ||
var assign = require("can-reflect").assignMap; | ||
var queues = require("can-queues"); | ||
var observe = require("can-observe"); | ||
var Observation = require("can-observation"); | ||
var QueryLogic = require("can-query-logic"); | ||
@@ -100,1 +103,59 @@ var testHelpers = require("../test-helpers"); | ||
}); | ||
QUnit.test("atomic saving for createdInstance and updateInstance (#5518)", function(assert) { | ||
var Person = function(values){ | ||
assign(this, values); | ||
}; | ||
var PersonList = function(people){ | ||
var listed = people.slice(0); | ||
listed.isList = true; | ||
return listed; | ||
}; | ||
var peopleConnection = constructor( persist( connect.base({ | ||
instance: function(values){ | ||
return new Person(values); | ||
}, | ||
list: function(arr){ | ||
return new PersonList(arr.data); | ||
}, | ||
url: "/constructor/people", | ||
queryLogic: new QueryLogic({ | ||
identity: ["id"] | ||
}) | ||
}) )); | ||
var done = assert.async(); | ||
var promises = []; | ||
var callArgs = []; | ||
var p = new Person({name: "ed"}); | ||
// Observer made to p | ||
var personObserver = observe(p); | ||
// Observation made on personObserver | ||
var nameAndDate = new Observation(function() { | ||
return personObserver.name + " " + personObserver.createdAt; | ||
}); | ||
nameAndDate.on(function(value) { | ||
callArgs.push(value); | ||
}); | ||
// The properties that are set are batched together | ||
queues.batch.start(); | ||
personObserver.name="edward"; | ||
personObserver.createdAt = "10-07-13"; | ||
queues.batch.stop(); | ||
// Saving p should be done once | ||
peopleConnection.save(p).then(function() { | ||
assert.deepEqual(callArgs, ["edward 10-07-13"]); | ||
assert.deepEqual(p, personObserver, "same instances"); | ||
}, testHelpers.logErrorAndStart(assert, done)); | ||
Promise.all(promises).then(done, done); | ||
}); | ||
@@ -126,2 +126,3 @@ | ||
var behavior = require("../behavior"); | ||
var queues = require("can-queues"); | ||
@@ -390,6 +391,7 @@ module.exports = behavior("constructor",function(baseConnection){ | ||
this.cidStore.addReference(cid, instance); | ||
// Call the data layer. | ||
// If the data returned is undefined, don't call `createdInstance` | ||
return this.createData(serialized, cid).then(function(data){ | ||
queues.batch.start(); | ||
// if undefined is returned, this can't be created, or someone has taken care of it | ||
@@ -400,2 +402,3 @@ if(data !== undefined) { | ||
self.cidStore.deleteReference(cid, instance); | ||
queues.batch.stop(); | ||
return instance; | ||
@@ -405,5 +408,7 @@ }); | ||
return this.updateData(serialized).then(function(data){ | ||
queues.batch.start(); | ||
if(data !== undefined) { | ||
self.updatedInstance(instance, data); | ||
} | ||
queues.batch.stop(); | ||
return instance; | ||
@@ -410,0 +415,0 @@ }); |
{ | ||
"name": "can-connect", | ||
"version": "4.0.3", | ||
"version": "4.0.4", | ||
"description": "Data connection middleware and utilities", | ||
@@ -5,0 +5,0 @@ "main": "can-connect.js", |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
528411
12380
1