Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
#! The bind method use previous binded alias entry
Browse files Browse the repository at this point in the history
  • Loading branch information
mjancarik committed Dec 2, 2016
1 parent 8a94a25 commit 51adf1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ObjectContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ export default class ObjectContainer {
}

let classConstructorEntry = this._entries.get(classConstructor);
let nameEntry = this._entries.get(name);
let entry = classConstructorEntry || nameEntry;

if (classConstructorEntry) {
this._entries.set(name, classConstructorEntry);
if (entry) {
this._entries.set(name, entry);

if (dependencies) {
this._updateEntryValues(classConstructorEntry, classConstructor, dependencies);
this._updateEntryValues(entry, classConstructor, dependencies);
}

} else {
Expand Down
20 changes: 20 additions & 0 deletions __tests__/ObjectContainerSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ describe('ima.ObjectContainer', function() {
expect(oc._entries.get(alias)).toEqual(oc._entries.get(classParent));
});

it('should use entry from entries which was provided and binded', function() {
oc.provide(classParent, classConstructor, dependencies);
oc.bind(alias, classParent);
var aliasEntry = oc._entries.get(alias);

spyOn(oc, '_updateEntryValues')
.and
.callThrough();

oc.bind(alias, classConstructorWithDependencies, classConstructorWithDependencies.$dependencies);

expect(oc._updateEntryValues).toHaveBeenCalledWith(
aliasEntry,
classConstructorWithDependencies,
classConstructorWithDependencies.$dependencies
);
expect(aliasEntry.classConstructor).toEqual(classConstructorWithDependencies);
expect(aliasEntry.dependencies).toEqual(classConstructorWithDependencies.$dependencies);
});

});

describe('provide method', function() {
Expand Down

0 comments on commit 51adf1a

Please sign in to comment.