Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-connect

Package Overview
Dependencies
Maintainers
12
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-connect - npm Package Compare versions

Comparing version 4.0.3 to 4.0.4

61

constructor/constructor_test.js

@@ -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);
});

7

constructor/constructor.js

@@ -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 @@ });

2

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc