Skip to content

Commit f767071

Browse files
committed
Merge pull request #51 from creynders/fix_51
BUG: Singleton (backbone) instances resolved twice
2 parents 79e3c31 + 5018150 commit f767071

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

backbone.geppetto.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,8 @@
124124

125125
wireSingleton: function(key, clazz, wiring) {
126126

127-
var constructor = (clazz.prototype.initialize ? this._wrapConstructor(clazz, wiring) : clazz);
128-
129127
this._mappings[key] = {
130-
clazz: constructor,
128+
clazz: clazz,
131129
object: null,
132130
type: TYPES.SINGLETON,
133131
wiring: wiring

dist/backbone.geppetto.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

specs/src/resolver-specs.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,24 @@ define([
363363
throw (/no mapping found/);
364364
});
365365
});
366+
describe('when used with Backbone objects', function(){
367+
var clazzInstantiated;
368+
var clazz = function(){
369+
clazzInstantiated++;
370+
};
371+
var singleton = Backbone.Model.extend({
372+
wiring : ['clazz']
373+
});
374+
beforeEach(function(){
375+
clazzInstantiated=0;
376+
resolver.wireClass('clazz', clazz);
377+
resolver.wireSingleton('singleton', singleton);
378+
});
379+
it("should not resolve singleton dependencies twice, see #51", function(){
380+
var actual = resolver.getObject('singleton');
381+
expect(clazzInstantiated ).to.equal(1);
382+
});
383+
});
366384
});
367385

368386
});

0 commit comments

Comments
 (0)