forked from magocto/Octopusjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
octopus.min.js
1 lines (1 loc) · 1.77 KB
/
octopus.min.js
1
(function(){var c=this;var f=c.Octopus;var e,b;if(typeof exports!=="undefined"){e=b=exports}else{e=c._8=c.Octopus={}}e.VERSION="0.1.0";e._traits={};e.t=function(i,j){if(!i){throw"Octopus.t Invalid name"}if(!j){return this._traits[id]}var h=j.construct;delete j.construct;this._traits[i]=new d(j,h)};e.hasT=function(h){return(this._traits[h])};e.spawn=function(j,i){if(!i){i={}}var h=this._getBaseObj(i.construct);_.each(g(j),function(l){var k=e._traits[l];if(k){h.prototype._traits.push(l);if(k.init){h.prototype._inits.push(k.init)}_.extend(h.prototype,k.proto)}});delete i.construct;_.extend(h.prototype,i);return h};e.spawnSingle=function(k,j,h){var i=e.spawn(k,j);return new i(h)};e._getBaseObj=function(h){var i=function(){var j=this;_.each(this._inits,function(k){k.apply(j)});this._useConstructor.apply(this,arguments)};i.prototype._traits=[];i.prototype._inits=[];i.prototype._useConstructor=(_.isFunction(h))?h:function(){};i.prototype.hasT=function(j){return _.indexOf(this._traits,j)!=-1};return i};e._paths={};e.path=function(i,h){if(!_.isString(i)){throw"Octopus space path must be a String"}return e._getPathObj(e._paths,i.split("."),h)};e._getPathObj=function(j,l,i){var h=l.shift();var k=j[h];if(!k){j[h]=k={}}if(l.length){return e._getPathObj(k,l,i)}if(i){_.extend(k,i)}return k};e.go=function(h,j){var i=(function(){});_.each(h,function(l,k){i[k]=e.path(l)});if(_.isFunction(j)){j.apply(i,Array.prototype.slice.call(arguments,2))}};e.noConflict=function(){c.Octopus=c._8=f;return e};e.learn=function(h){_.each(_.functions(h),function(i){e[i]=h[i]})};var d=function(h,i){this.proto=(!h)?{}:h;this.init=i};var g=function(h){if(_.isArray(h)){return h}if(_.isString(h)){return _.map(h.split(","),function(i){return a(i)})}return[]};var a=function(h){return h.replace(/^\s*([\S\s]*?)\s*$/,"$1")}})();