Skip to content

Commit

Permalink
Merge pull request #66 from jaredhanson/protect
Browse files Browse the repository at this point in the history
Electrolyte 0.5.0
  • Loading branch information
jaredhanson committed May 31, 2017
2 parents 6f16ae3 + e778000 commit c0a5274
Show file tree
Hide file tree
Showing 27 changed files with 345 additions and 387 deletions.
30 changes: 30 additions & 0 deletions lib/assembly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var path = require('canonical-path');


function Assembly(h, ns, asm) {
this.h = h;
this.namespace = ns || '';
this.components = [];
this._load = asm.load;
this._export = asm.export;

var ids = asm.components || []
, aid, i, len;
for (i = 0, len = ids.length; i < len; ++i) {
aid = path.join(this.namespace, ids[i]);
this.components.push(aid);
}
}

Assembly.prototype.load = function(id) {
var rid = path.relative(this.namespace, id);
return this._load(rid);
}

Assembly.prototype.isExported = function(id) {
if (this._export === true) { return true; }
return this.components.indexOf(id) != -1;
}


module.exports = Assembly;
33 changes: 14 additions & 19 deletions lib/spec.js → lib/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Load modules.
var debug = require('debug')('electrolyte')
, NotImplementedError = require('./errors/notimplemented')
, Promise = require('promise');
var Promise = require('promise')
, debug = require('debug')('electrolyte');



/**
Expand All @@ -22,23 +22,18 @@ var debug = require('debug')('electrolyte')
* should be created.
* - `@implements` - Declares the interfaces implemented by this object.
*
* Note that `@implements` is not used directly by Electrolyte. Rather, it
* exists to support higher-level frameworks, such as Bixby.js, which encourage
* component-based programming in which you code to an interface, not an
* implementation.
*
* A specification may contain other annotations, and the complete set of
* annotations is available under the `.a` hash (short for annotations). Such
* annotations are typically used by higher-level frameworks for purposes such
* as declaring service endpoints and loading plug-ins.
*
* @constructor
* @param {string} id - The id of the specification.
* @param {object} mod - The module containing the object factory.
* @param {number} hs - The handle of the source from which the spec was loaded.
* @param {string} id - The id of the component.
* @param {object} mod - The module containing the component specification.
* @param {number} asm - The assembly from which the component was loaded.
* @protected
*/
function Spec(id, mod, source) {
function Component(id, mod, asm) {
var keys, i, len;

this.id = id;
Expand All @@ -58,15 +53,15 @@ function Spec(id, mod, source) {
}
}
}
this._source = source;
this._assembly = asm;
}

/**
* Create an object from the specification.
*
* @protected
*/
Spec.prototype.create = function(container) {
Component.prototype.create = function(container) {
debug('create %s', this.id);

// Immediately return cached instance. Optimization for singleton and literal
Expand All @@ -77,8 +72,8 @@ Spec.prototype.create = function(container) {
// objects that are dependencies of the object being created.
var deps = this.dependencies
, promises = []
, promise, p;
for (var i = 0, len = deps.length; i < len; ++i) {
, promise, p, i, len;
for (i = 0, len = deps.length; i < len; ++i) {
promise = container.create(deps[i], this);
promises.push(promise);
}
Expand Down Expand Up @@ -109,10 +104,10 @@ Spec.prototype.create = function(container) {
*
* @private
*/
Spec.prototype.instantiate = function() {
throw new NotImplementedError("Spec#instantiate must be overridden by subclass");
Component.prototype.instantiate = function() {
throw new Error("Component#instantiate must be overridden by subclass");
}


// Expose constructor.
module.exports = Spec;
module.exports = Component;

0 comments on commit c0a5274

Please sign in to comment.