Skip to content

Commit

Permalink
Lazy loading of imported packages has been implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
divmgl committed Oct 6, 2015
1 parent a467e4e commit 84f30d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ gulp.task('test', function() {
});

gulp.task('watch:test', function(){
gulp.watch('index.js', ["test"]);
});
gulp.watch(['index.js', "tests/**/*"], ["test"]);
});
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ module.exports = function nwire(config, callback) {

if (!skipNeeds) {
self.packages[dependencyName] = load(dependencyName, skip);
imports[dependencyName] = self.packages[dependencyName];
Object.defineProperty(imports, dependencyName, {
get: function(){
return self.packages[dependencyName];
}
});
}
});

Expand All @@ -91,4 +95,4 @@ module.exports = function nwire(config, callback) {
if (!callback) throw err;
callback(err);
}
}
}
6 changes: 3 additions & 3 deletions tests/nwire.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ describe('nwire application', function() {
});

describe('leech package', function(){
it('has a consumed package', function(){
it('should not have packages', function(){
var app = wire(configurationFixture);
expect(_.size(app.packages.leech.imports)).to.equal(1);
expect(_.size(app.packages.leech.imports)).to.equal(0);
});

it('has the consumed seed package', function(){
Expand All @@ -100,4 +100,4 @@ describe('leech package', function(){
var app = wire(circularConfigurationFixture);
expect(app.packages.leech.imports.seed.dummyFn).to.not.be.undefined;
});
});
});

0 comments on commit 84f30d7

Please sign in to comment.