/*!
 * base-store <https://github.com/jonschlinkert/base-store>
 *
 * Copyright (c) 2015-2016, Jon Schlinkert.
 * Licensed under the MIT License.
 */

'use strict';

var utils = require('./utils');

module.exports = function(name, config) {
  if (typeof name !== 'string') {
    config = name;
    name = undefined;
  }

  return function(app) {
    if (this.isRegistered('store')) return;

    if (typeof name === 'undefined') {
      name = utils.project(process.cwd());
    }

    var opts = utils.extend({}, config, app.options.store);
    this.define('store', utils.store(name, opts));

    /**
     * Bubble up specific events to `app`
     */

    this.store.on('set', function(key, val) {
      app.emit('store.set', key, val);
      app.emit('store', 'set', key, val);
    });

    this.store.on('get', function(key, val) {
      app.emit('store.get', key, val);
      app.emit('store', 'get', key, val);
    });

    this.store.on('del', function(key, val) {
      app.emit('store.del', key, val);
      app.emit('store', 'del', key, val);
    });
  };
};

@@ -331,16 +331,23 @@
 function
+ plugin
 (app) %7B%0A
@@ -358,33 +358,28 @@
 if (
-this.isRegistered('store'
+!isValidInstance(app
 )) r
@@ -1057,12 +1057,313 @@
 %7D);%0A
-  %7D;%0A%7D;
+%0A    return plugin;%0A  %7D;%0A%7D;%0A%0Afunction isValidInstance(app) %7B%0A  var fn = app.options.validatePlugin;%0A  if (typeof fn === 'function' && !fn(app)) %7B%0A    return false;%0A  %7D%0A  if (app.isRegistered('base-store')) %7B%0A    return false;%0A  %7D%0A  if (app.isCollection %7C%7C app.isView) %7B%0A    return false;%0A  %7D%0A  return true;%0A%7D
 %0A

return the plugin, improve validation logic