var debug = require('debug')('electrolyte');


function Component(id, dependencies) {
  this.id = id;
  this.dependencies = dependencies;
}

Component.prototype.create = function(container) {
  debug('create %s', this.id);
  
  if (!this.loaded) {
    var deps = this.dependencies
      , args = [];
    for (var i = 0, len = deps.length; i < len; ++i) {
      var inst = container.create(deps[i], this);
      // TODO: Clean up terminology re "suites"
      var loader = container._suites[this._sid].loader;
      var suite = container._suites[this._sid];
      if (typeof loader.scope == 'function') {
        inst = loader.scope(deps[i], inst, { prefix: suite.prefix, options: suite.options });
      }
      args.push(inst);
    }
  }
  return this.instantiate.apply(this, args);
}

Component.prototype.instantiate = function() {
  throw new Error("Unable to instantiate component '" + this.id + "'");
}

module.exports = Component;

var debug = require('debug')('electrolyte');


function Component(id, dependencies) {
  this.id = id;
  this.dependencies = dependencies;
}

Component.prototype.create = function(container) {
  debug('create %s', this.id);
  
  if (!this.loaded) {
    var deps = this.dependencies
      , args = [];
    for (var i = 0, len = deps.length; i < len; ++i) {
      var inst = container.create(deps[i], this);
      // TODO: Clean up terminology re "suites"
      var suite = container._suites[this._sid];
      if (suite && suite.loader) {
        var loader = suite.loader;
        if (typeof loader.scope == 'function') {
          inst = loader.scope(deps[i], inst, { prefix: suite.prefix, options: suite.options });
        }
      }
      args.push(inst);
    }
  }
  return this.instantiate.apply(this, args);
}

Component.prototype.instantiate = function() {
  throw new Error("Unable to instantiate component '" + this.id + "'");
}

module.exports = Component;

Fix tests.