From 835ecd9d1e829e7aba29f4c0e5f0bee100fe463b Mon Sep 17 00:00:00 2001 From: Scott Hamper Date: Wed, 1 Oct 2014 15:58:13 -0400 Subject: [PATCH] Updated initializePlugins to not wipe out prev data Calling initializePlugins multiple times would load/execute all plugins, but would only keep internal plugin data relevant to the last invocation. --- src/microplugin.js | 2 +- test/index.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/microplugin.js b/src/microplugin.js index 0b53c50..7138722 100644 --- a/src/microplugin.js +++ b/src/microplugin.js @@ -48,7 +48,7 @@ var self = this; var queue = []; - self.plugins = { + self.plugins = self.plugins || { names : [], settings : {}, requested : {}, diff --git a/test/index.js b/test/index.js index 84254f7..3f5df33 100644 --- a/test/index.js +++ b/test/index.js @@ -169,6 +169,23 @@ describe('MicroPlugin', function() { }); + it('should not overwrite `plugins` data from previous initializations', function() { + var Lib = function() { + this.initializePlugins({'a': {test: 'hello_a'}}); + this.initializePlugins(['b']); + }; + MicroPlugin.mixin(Lib); + + Lib.define('a', function () { }); + Lib.define('b', function () { }); + + var instance = new Lib(); + assert(instance.plugins.names.indexOf('a') >= 0); + assert.deepEqual(instance.plugins.settings['a'], {test: 'hello_a'}); + assert(instance.plugins.requested['a']); + assert(instance.plugins.loaded.hasOwnProperty('a')); + }); + }); describe('#require()', function() {