gardr/gardr-core-plugin — pull request #1 by gregersrygg (2014-06-16 13:57:29+00:00)
Title: Pass along the options when initializing plugins

We're starting to see that passing config-options to plugins makes the code unnecessary complex. There is no defined way to do it. You will have to expose an extra method for configuration or have a higher-order function that returns the plugin pre-configured. See this example (higher-order function):

var gardrHost = require('gardr-host');
var examplePlugin = require('gardr-plugin-host-example');

gardrHost.plugin( examplePlugin({
foo: 'bar'
}) );

var myGardr = gardrHost({
iframeUrl: '...'
});

I suggest we pass the options given to gardr-{host | ext} along when initializing plugins. Then it's just to add the extra options in the general configuration. It makes regestring plugins a lot easier, and configuration is in one place instead.

var gardrHost = require('gardr-host');
gardrHost.plugin( require('gardr-plugin-host-example') );

var myGardr = gardrHost({
iframeUrl: '...',
foo: 'bar'
});

A risk might be collision of options between plugins. But it's quite easy to detect, and we can suggest that plugins have a short prefix before their options. Having a deeper options-object will make the code more complex.