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

knockout-sync

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

knockout-sync - npm Package Compare versions

Comparing version 0.1.2 to 0.1.4

2

package.json
{
"name": "knockout-sync",
"version": "0.1.2",
"version": "0.1.4",
"description": "A small backend using knockout mapping to sync entities with a RESTful Backend",

@@ -5,0 +5,0 @@ "main": "Gruntfile.js",

define(['knockout-mapping', './EntityModel', 'Amplify'], function(koMapping, EntityModel, amplify) {
/**
Events:
knockout-sync.entity-saved
triggered when an entity with an existing id was saved again
args: [entity, entityMeta]
knockout-sync.entity-created
triggered when an new entity without an id was saved. the entity has the new id applied
args: [entity, entityMeta]
*/
return function Backend(driver, entityModel) {

@@ -30,5 +43,18 @@ var that = this;

that.driver.dispatch(method, url, that.serializeEntity(entity), function(error, result) {
if (!error && !entity.id() && result.id) { // get persisted id
if (error) throw error;
var data;
if (result.id) {
data = result;
} else if (result[entityMeta.singular] && result[entityMeta.singular].id) {
data = result[entityMeta.singular];
} else {
throw "driver did returned an valid result set for a saved entity";
}
if (!entity.id()) { // set persisted id
entity.id(result.id);
amplify.publish('new-entity', entity, entityMeta);
amplify.publish('knockout-sync.entity-created', entity, entityMeta);
} else {
amplify.publish('knockout-sync.entity-saved', entity, entityMeta);
}

@@ -35,0 +61,0 @@ });

@@ -22,2 +22,3 @@ var chai = require('chai');

};
var amplify = requirejs('Amplify');

@@ -64,4 +65,13 @@ describe('Yield Deploy Backend', function() {

var published = false;
amplify.subscribe('knockout-sync.entity-created', function(eventEntity, eventEntityMeta) {
published = true;
expect(eventEntity).to.be.equal(user);
expect(eventEntity.id(), 'event user.id').to.be.equal(7);
expect(eventEntityMeta.fqn).to.be.eql(user.fqn);
});
backend.save(user);
expect(dispatched, 'dispatch is called').to.be.true;
expect(published, 'publishe is called').to.be.true;

@@ -85,4 +95,12 @@ expect(user.id(), 'user.id').to.be.equal(7);

var published = false;
amplify.subscribe('knockout-sync.entity-saved', function(eventEntity, eventEntityMeta) {
published = true;
expect(eventEntity).to.be.eql(user);
expect(eventEntityMeta.fqn).to.be.eql(user.fqn);
});
backend.save(user);
expect(dispatched, 'dispatch is called').to.be.true;
expect(published, 'published is called').to.be.true;
expect(user.id(), 'user.id').to.be.equal(7);

@@ -89,0 +107,0 @@ });

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