brianreavis/microplugin.js — pull request #2 by ScottHamper (2014-10-01 20:16:10+00:00)
Title: Updated `initializePlugins` to not wipe out previous `plugins` data

Hey Brian,

I noticed today that calling `initializePlugins` multiple times would end up loading/executing all plugins, but would wipe out the `plugins` object on each invocation.

I was working on creating a plugin for Selectize that would add "singlePlugins" and "multiPlugins" settings, so that I could define default plugins more simply, when I ran into this issue. My custom `mode_plugins' plugin calls `initializePlugins` after Selectize has already initialized it and other plugins.

The main issue this causes in Selectize is that CSS classes are only applied for the latter round of plugins (single/multi), and not for the original listing of plugins, because Selectize looks at `self.plugins.names` to generate the classes.

This pull request includes a simple fix/test for Microplugin to ensure that all plugin data stays intact across multiple invocations of `initializePlugins`. One thing this fix potentially leaves the door open for, if you're worried about it, is that `self.plugins` could already exist, but not be in the format that Microplugin expects.

I don't expect this to be an issue in practice, however.