From 78c0c7c1eb039fa4acea6c702b542fec76264971 Mon Sep 17 00:00:00 2001 From: popomore Date: Wed, 29 Jul 2015 01:09:48 +0800 Subject: [PATCH] feat: init support array --- index.js | 11 ++++++++--- test/loading.test.js | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 629fe8f..9da0d39 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,14 @@ function Loader(dirpath, opt) { this.opt.call = this.opt.call !== false; this.opt.override = this.opt.override === true; this._mods = []; - this.concat(dirpath); + + if (Array.isArray(dirpath)) { + for (var i = 0, l = dirpath.length; i < l; i++) { + this.concat(dirpath[i]); + } + } else { + this.concat(dirpath); + } } var proto = Loader.prototype; @@ -39,7 +46,6 @@ proto._load = function (target, field, options) { var mods = this._mods; var isCall = this.opt.call; var isOverride = this.opt.override; - var self = this; if (!target) { return; @@ -49,7 +55,6 @@ proto._load = function (target, field, options) { target[field] = {}; } - var map = {}; mods.forEach(function (item, index) { var properties = item.properties; if (filters && filters.length > 0 && filters.indexOf(properties[0]) === -1) { diff --git a/test/loading.test.js b/test/loading.test.js index 516a641..6569391 100644 --- a/test/loading.test.js +++ b/test/loading.test.js @@ -73,6 +73,14 @@ describe('loading.test.js', function () { .into(app, 'services'); }); + it('should overwrite property from loading using array', function() { + var app = {}; + loading([ + path.join(__dirname, 'fixtures', 'services'), + path.join(__dirname, 'fixtures', 'overwrite_services') + ], {override: true}).into(app, 'services'); + }); + it('should just return when no target', function() { loading(path.join(__dirname, 'fixtures', 'services')).into(); });