-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdijon.min.js
More file actions
1 lines (1 loc) · 3.28 KB
/
dijon.min.js
File metadata and controls
1 lines (1 loc) · 3.28 KB
1
/*! dijon - v0.6.1 - 2013-12-04 Copyright (c) 2013 Camille Reynders (http://www.creynders.be/); Licensed MIT */!function(a,b){"object"==typeof exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.dijon=b()}(this,function(){"use strict";var a="no mapping found for this key",b={version:"0.6.1"};return b.System=function(){this._mappings={},this._outlets={},this._handlers={},this.strictInjections=!0,this.autoMapOutlets=!1,this.postInjectionHook="setup"},b.System.prototype={_createAndSetupInstance:function(a,b){var c=new b;return this.injectInto(c,a),c},_retrieveFromCacheOrCreate:function(b,c){"undefined"==typeof c&&(c=!1);var d;if(!this._mappings.hasOwnProperty(b))throw a;var e=this._mappings[b];return!c&&e.isSingleton?(null==e.object&&(e.object=this._createAndSetupInstance(b,e.clazz)),d=e.object):d=e.clazz?this._createAndSetupInstance(b,e.clazz):e.object,d},mapOutlet:function(a,b,c){return b=b||"global",c=c||a,this._outlets.hasOwnProperty(b)||(this._outlets[b]={}),this._outlets[b][c]=a,this},getObject:function(a){return this._retrieveFromCacheOrCreate(a)},mapValue:function(a,b){return this._mappings[a]={clazz:null,object:b,isSingleton:!0},this.autoMapOutlets&&this.mapOutlet(a),this.hasMapping(a)&&this.injectInto(b,a),this},hasMapping:function(a){return this._mappings.hasOwnProperty(a)},mapClass:function(a,b){return this._mappings[a]={clazz:b,object:null,isSingleton:!1},this.autoMapOutlets&&this.mapOutlet(a),this},mapSingleton:function(a,b){return this._mappings[a]={clazz:b,object:null,isSingleton:!0},this.autoMapOutlets&&this.mapOutlet(a),this},instantiate:function(a){return this._retrieveFromCacheOrCreate(a,!0)},injectInto:function(a,b){if("object"==typeof a){var c=[];this._outlets.hasOwnProperty("global")&&c.push(this._outlets.global),"undefined"!=typeof b&&this._outlets.hasOwnProperty(b)&&c.push(this._outlets[b]);for(var d in c){var e=c[d];for(var f in e){var g=e[f];(!this.strictInjections||f in a)&&(a[f]=this.getObject(g))}}"setup"in a&&a.setup.call(a)}return this},unmap:function(a){return delete this._mappings[a],this},unmapOutlet:function(a,b){return delete this._outlets[a][b],this},mapHandler:function(a,b,c,d,e){return b=b||"global",c=c||a,"undefined"==typeof d&&(d=!1),"undefined"==typeof e&&(e=!1),this._handlers.hasOwnProperty(a)||(this._handlers[a]={}),this._handlers[a].hasOwnProperty(b)||(this._handlers[a][b]=[]),this._handlers[a][b].push({handler:c,oneShot:d,passEvent:e}),this},unmapHandler:function(a,b,c){if(b=b||"global",c=c||a,this._handlers.hasOwnProperty(a)&&this._handlers[a].hasOwnProperty(b)){var d=this._handlers[a][b];for(var e in d){var f=d[e];if(f.handler===c){d.splice(e,1);break}}}return this},notify:function(a){var b=Array.prototype.slice.call(arguments),c=b.slice(1);if(this._handlers.hasOwnProperty(a)){var d=this._handlers[a];for(var e in d){var f,g=d[e];"global"!==e&&(f=this.getObject(e));var h,i,j=[];for(h=0,i=g.length;i>h;h++){var k,l=g[h];k=f&&"string"==typeof l.handler?f[l.handler]:l.handler,l.oneShot&&j.unshift(h),l.passEvent?k.apply(f,b):k.apply(f,c)}for(h=0,i=j.length;i>h;h++)g.splice(j[h],1)}}return this},mapCommand:function(a,b,c,d){var e=a+"_command",f=c||"execute";return this.mapClass(e,b),this.mapHandler(a,e,f,!1,d),this},unmapCommand:function(a,b,c){var d=a+"_command",e=c||"execute";return this.unmap(d),this.unmapHandler(a,d,e),this}},b});