Skip to content

Commit

Permalink
Merge pull request #51 from creynders/fix_51
Browse files Browse the repository at this point in the history
BUG: Singleton (backbone) instances resolved twice
  • Loading branch information
geekdave committed Sep 1, 2014
2 parents 79e3c31 + 5018150 commit f767071
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
4 changes: 1 addition & 3 deletions backbone.geppetto.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,8 @@

wireSingleton: function(key, clazz, wiring) {

var constructor = (clazz.prototype.initialize ? this._wrapConstructor(clazz, wiring) : clazz);

this._mappings[key] = {
clazz: constructor,
clazz: clazz,
object: null,
type: TYPES.SINGLETON,
wiring: wiring
Expand Down
2 changes: 1 addition & 1 deletion dist/backbone.geppetto.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions specs/src/resolver-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,24 @@ define([
throw (/no mapping found/);
});
});
describe('when used with Backbone objects', function(){
var clazzInstantiated;
var clazz = function(){
clazzInstantiated++;
};
var singleton = Backbone.Model.extend({
wiring : ['clazz']
});
beforeEach(function(){
clazzInstantiated=0;
resolver.wireClass('clazz', clazz);
resolver.wireSingleton('singleton', singleton);
});
it("should not resolve singleton dependencies twice, see #51", function(){
var actual = resolver.getObject('singleton');
expect(clazzInstantiated ).to.equal(1);
});
});
});

});

0 comments on commit f767071

Please sign in to comment.