UNPKG

riveter

Version:

Mix-in, inheritance and constructor extend behavior for your JavaScript enjoyment.

9 lines 2.84 kB
/** * riveter - Mix-in, inheritance and constructor extend behavior for your JavaScript enjoyment. * © 2012 - Copyright appendTo, LLC * Author(s): Jim Cowart, Nicholas Cloud, Doug Neiner * Version: v0.2.0 * Url: https://github.com/a2labs/riveter * License(s): MIT, GPL */ (function(t,n){"function"==typeof define&&define.amd?define(["lodash"],function(e){return n(e,t)}):"object"==typeof module&&module.exports?module.exports=n(require("lodash")):t.riveter=n(t._,t)})(this,function(t){function n(n){return t.isArray(n)?"array":t.isDate(n)?"date":t.isRegExp(n)?"regex":typeof n}function e(t){var e=n(t);return p[e]?e:"*"}function r(n){return t.each(o.call(arguments,1),function(r){t.each(r,function(t,r){p[e(t)](n,r,t)})}),n}var o=Array.prototype.slice,i=function(){for(var t=o.call(arguments,0);t.length;)i.rivet(t.shift())},p={"*":function(t,n,e){t[n]=e},object:function(t,n,e){t[n]=r(t[n]||{},e)},array:function(n,r,o){n[r]=[],t.each(o,function(t,o){p[e(t)](n[r],o,t)},this)}};return i.rivet=function(t){t.hasOwnProperty("extend")||(t.extend=function(n,e,r){return i.extend(t,n,e,r)}),t.hasOwnProperty("compose")||(t.compose=function(){return i.compose.apply(this,[t].concat(o.call(arguments,0)))}),t.hasOwnProperty("inherits")||(t.inherits=function(n,e,r){return i.inherits(t,n,e,r)}),t.hasOwnProperty("mixin")||(t.mixin=function(){return i.mixin.apply(this,[t].concat(o.call(arguments,0)))}),t.hasOwnProperty("punch")||(t.punch=function(){return i.punch.apply(this,[t].concat(o.call(arguments,0)))})},i.inherits=function(n,e,o,p){p=p||{};var u,c=function(){},s=function(){e.apply(this,arguments)};return"object"==typeof n?(n.hasOwnProperty("constructor")&&(s=n.constructor),u=n):(s=n,u=n.prototype),i.rivet(s),p.deep?r(s,e,o):t.defaults(s,e,o),c.prototype=e.prototype,s.prototype=new c,p.deep?r(s.prototype,u,{constructor:s}):t.extend(s.prototype,u,{constructor:s}),s.__super=e,s.__super__=e.prototype,s},i.extend=function(t,n,e,r){return i.inherits(n,t,e,r)},i.compose=function(){var n=o.call(arguments,0),e=n.shift();i.rivet(e);var r=t.reduce(n,function(t,n){return n.hasOwnProperty("_preInit")&&t.preInit.push(n._preInit),n.hasOwnProperty("_postInit")&&t.postInit.push(n._postInit),n=n.mixin||n,t.items.push(n),t},{items:[],preInit:[],postInit:[]}),p=e.extend({constructor:function(){var n=o.call(arguments,0);t.each(r.preInit,function(t){t.apply(this,n)},this),e.prototype.constructor.apply(this,n),t.each(r.postInit,function(t){t.apply(this,n)},this)}});return i.rivet(p),t.defaults(p.prototype,t.extend.apply(null,[{}].concat(r.items))),p},i.mixin=function(){var n=o.call(arguments,0),e=n.shift();return i.rivet(e),t.defaults(e.prototype,t.extend.apply(null,[{}].concat(n))),e},i.punch=function(){var n=o.call(arguments,0),e=n.shift();return i.rivet(e),t.extend(e.prototype,t.extend.apply(null,[{}].concat(n))),e},i});