backbone.rel
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -84,3 +84,5 @@ /** | ||
var collection = getOptions(this.self, 'belongsTo', this.key) | ||
, result; | ||
, eventBus = this.self.relEventBus | ||
, result | ||
, id; | ||
@@ -94,3 +96,8 @@ if (!collection) { | ||
} else { | ||
result = collection.get(this.findBelongsToIdAttribute()); | ||
id = this.findBelongsToIdAttribute(); | ||
result = collection.get(id); | ||
if (eventBus && !result) { | ||
eventBus.trigger && eventBus.trigger('backbone-rel:missing', this.key, id); | ||
} | ||
} | ||
@@ -204,5 +211,5 @@ | ||
_.extend(Backbone.Model.prototype, {rel: rel('Model'), relGet: relGet, relResult: relResult}); | ||
_.extend(Backbone.Collection.prototype, {rel: rel('Collection'), relGet: relGet, relResult: relResult}); | ||
_.extend(Backbone.Model.prototype, {rel: rel('Model'), relGet: relGet, relResult: relResult, relEventBus: null}); | ||
_.extend(Backbone.Collection.prototype, {rel: rel('Collection'), relGet: relGet, relResult: relResult, relEventBus: null}); | ||
}()); |
{ | ||
"name": "backbone.rel", | ||
"description": "Lightweight relationship assistant for your backbone applications", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"author": "Pau ramon <masylum@gmail.com>", | ||
"contributors": ["Maxim lolls <collsmaxim@gmail.com>"], | ||
"contributors": ["Maxim Colls <collsmaxim@gmail.com>", "Saimon Moore <saimonmoore@gmail.com>"], | ||
"keywords": ["backbone", "relations", "ender", "teambox"], | ||
@@ -8,0 +8,0 @@ "repository": {"type": "git", "url": "git://github.com/masylum/Backbone.Rel.git"}, |
@@ -5,2 +5,3 @@ module.exports = (function () { | ||
, Collections = {} | ||
, EventBus = {} | ||
, users, tasks, projects, comments; | ||
@@ -11,2 +12,7 @@ | ||
_.extend(EventBus, Backbone.Events); | ||
Backbone.Model.prototype.relEventBus = EventBus; | ||
Backbone.Collection.prototype.relEventBus = EventBus; | ||
Models.Task = Backbone.Model.extend({ | ||
@@ -133,3 +139,4 @@ belongsTo: function () { | ||
, instance: instance | ||
, EventBus: EventBus | ||
}; | ||
})(); |
@@ -1,2 +0,2 @@ | ||
/*global it, describe, before, beforeEach*/ | ||
/*global it, describe, afterEach, before, beforeEach*/ | ||
var _ = require('underscore') | ||
@@ -10,3 +10,5 @@ , data = require('./data') | ||
describe('Rel', function () { | ||
var users, projects, tasks; | ||
var users | ||
, projects | ||
, tasks; | ||
@@ -94,2 +96,38 @@ beforeEach(function () { | ||
}); | ||
describe('event bus', function () { | ||
var EventBus = data.EventBus | ||
, events_triggered = []; | ||
EventBus.bind('backbone-rel:missing', function (resource, id) { | ||
events_triggered.push([resource, id]); | ||
}); | ||
beforeEach(function () { | ||
events_triggered = []; | ||
}); | ||
describe('if a rel is missing', function () { | ||
var user, missing_project; | ||
beforeEach(function () { | ||
missing_project = projects.get(0); | ||
projects.remove(missing_project); | ||
user = users.get(0); | ||
}); | ||
afterEach(function () { | ||
projects.add(missing_project); | ||
}); | ||
it('triggers a "backbone-rel:missing" event on the event bus', function () { | ||
user.rel('project'); | ||
assert.equal(events_triggered.length, 1); | ||
assert.equal(events_triggered[0][0], 'project'); | ||
assert.equal(events_triggered[0][1], 0); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -96,0 +134,0 @@ |
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
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
27916
614
0
1