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

backbone-relations

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backbone-relations - npm Package Compare versions

Comparing version 0.7.5 to 0.7.6

54

backbone-relations.js

@@ -17,14 +17,14 @@ (function (root, factory) {

var Relation = function (owner, key, options) {
_.extend(this, options);
this.owner = owner;
this.key = key;
if (this.via) {
var split = this.via.split('#');
this.via = split[0];
this.viaKey = split[1] || key;
}
};
var Relation = herit({
constructor: function (owner, key, options) {
_.extend(this, options);
this.owner = owner;
this.key = key;
if (this.via) {
var split = this.via.split('#');
this.via = split[0];
this.viaKey = split[1] || key;
}
},
_.extend(Relation.prototype, {
get: function () { return this.instance(); },

@@ -58,12 +58,30 @@

var fk = this.fk;
var key = this.key;
var reverse = this.reverse;
var instance = this._instance = new Collection({id: owner.get(fk)});
var idAttr = Model.prototype.idAttribute;
instance.on('add change:' + idAttr, function (model, __, options) {
owner.set(fk, model.id, options);
});
var attrs = {};
attrs[idAttr] = owner.get(fk);
var instance = this._instance = new Collection(attrs);
instance
.on('add change:' + idAttr, function (model, __, options) {
owner.set(fk, model.id, options);
})
.on('all', function (name, model) {
if (name.indexOf('change') !== 0) return;
var options = _.last(arguments);
if (!options.owners) {
options = _.clone(options);
options.owners = {};
options.owners[model.cid] = true;
}
if (options.owners[owner.cid]) return;
options.owners[owner.cid] = true;
name = name.replace(/^change/, 'change:' + key);
var args = [name].concat([].slice.call(arguments, 1, -1), options);
owner.trigger.apply(owner, args);
});
owner.on('change:' + fk, function (__, val, options) {
if (instance.first().id !== val) {
instance.set(new Model({id: val}), options);
}
if (instance.first().id === val) return;
attrs[idAttr] = val;
instance.set(new Model(attrs), options);
});

@@ -70,0 +88,0 @@ if (reverse) {

{
"name": "backbone-relations",
"version": "0.7.5",
"version": "0.7.6",
"main": "./backbone-relations.js",

@@ -5,0 +5,0 @@ "dependencies": {

{
"name": "backbone-relations",
"version": "0.7.5",
"version": "0.7.6",
"author": "Casey Foster <c@sey.me>",

@@ -5,0 +5,0 @@ "licence": "MIT",

Sorry, the diff of this file is not supported yet

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