Class Index | File Index

Classes


Class dijon.System

dijon.System
Defined in: dijon.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Field Summary
Field Attributes Field Name and Description
 
Enables the automatic mapping of outlets for mapped values, singletons and classes When this is true any value, singleton or class that is mapped will automatically be mapped as a global outlet using the value of key as outlet name
 
The name of the method that will be called for all instances, right after injection has occured.
 
When true injections are made only if an object has a property with the mapped outlet name.
Method Summary
Method Attributes Method Name and Description
 
getObject(key)
Retrieve (or create) the object mapped to key
 
Returns whether the key is mapped to an object
 
injectInto(instance, key)
Perform an injection into an object's mapped outlets, satisfying all it's dependencies
 
Force instantiation of the class mapped to key, whether it was mapped as a singleton or not.
 
mapClass(key, clazz)
Maps clazz as a factory to key
 
mapHandler(eventName/route, key, handler, oneShot, passEvent)
maps a handler for an event/route.
 
mapOutlet(sourceKey, targetKey, outletName)
defines outletName as an injection point in targetKeyfor the object mapped to sourceKey
 
mapSingleton(key, clazz)
Maps clazz as a singleton factory to key
 
mapValue(key, useValue)
Maps useValue to key
 
notify(eventName/route)
calls all handlers mapped to eventName/route
 
unmap(key)
Remove the mapping of key from the system
 
unmapHandler(eventName, key, handler)
Unmaps the handler for a specific event/route.
 
unmapOutlet(target, outlet)
removes an injection point mapping for a given object mapped to key
Class Detail
dijon.System()
Field Detail
{Boolean} autoMapOutlets
Enables the automatic mapping of outlets for mapped values, singletons and classes When this is true any value, singleton or class that is mapped will automatically be mapped as a global outlet using the value of key as outlet name
var o = {
    userModel : undefined; //inject
}
system.mapSingleton( 'userModel', UserModel );
system.injectInto( o ):
//o.userModel now holds a reference to the singleton instance of UserModel
Default Value:
false

{String} postInjectionHook
The name of the method that will be called for all instances, right after injection has occured.
Default Value:
'setup'

{Boolean} strictInjections
When true injections are made only if an object has a property with the mapped outlet name.
Set to false at own risk, may have quite undesired side effects.
system.strictInjections = true
var o = {};
system.mapSingleton( 'userModel', UserModel );
system.mapOutlet( 'userModel' );
system.injectInto( o );

//o is unchanged

system.strictInjections = false;
system.injectInto( o );

//o now has a member 'userModel' which holds a reference to the singleton instance
//of UserModel
Default Value:
true
Method Detail
{Object} getObject(key)
Retrieve (or create) the object mapped to key
system.mapValue( 'foo', 'bar' );
var b = system.getObject( 'foo' ); //now contains 'bar'
Parameters:
{Object} key
Returns:
{Object}

{Boolean} hasMapping(key)
Returns whether the key is mapped to an object
system.mapValue( 'foo', 'bar' );
var isMapped = system.hasMapping( 'foo' );
Parameters:
{String} key
Returns:
{Boolean}

{dijon.System} injectInto(instance, key)
Perform an injection into an object's mapped outlets, satisfying all it's dependencies
var UserModel = function(){
}
system.mapSingleton( 'userModel', UserModel );
var SomeClass = function(){
     user = undefined; //inject
}
system.mapSingleton( 'o', SomeClass );
system.mapOutlet( 'userModel', 'o', 'user' );

var foo = {
     user : undefined //inject
}

system.injectInto( foo, 'o' );

//foo.user now holds a reference to the singleton instance of UserModel
Parameters:
{Object} instance
{String} key Optional
use the outlet mappings as defined for key, otherwise only the globally mapped outlets will be used.
Returns:
{dijon.System}

{Object} instantiate(key)
Force instantiation of the class mapped to key, whether it was mapped as a singleton or not. When a value was mapped, the value will be returned. TODO: should this last rule be changed?
         var SomeClass = function(){
         }
         system.mapClass( 'o', SomeClass );

         var s1 = system.getObject( 'o' );
         var s2 = system.getObject( 'o' );
//s1 and s2 reference different instances of SomeClass
Parameters:
{String} key
Returns:
{Object}

{dijon.System} mapClass(key, clazz)
Maps clazz as a factory to key
var SomeClass = function(){
}
system.mapClass( 'o', SomeClass );

var s1 = system.getObject( 'o' );
var s2 = system.getObject( 'o' );

//s1 and s2 reference two different instances of SomeClass
Parameters:
{String} key
{Function} clazz
Returns:
{dijon.System}

{dijon.System} mapHandler(eventName/route, key, handler, oneShot, passEvent)
maps a handler for an event/route.
         var hasExecuted = false;
         var userView = {
         showUserProfile : function(){
         hasExecuted = true;
         }
         }
         system.mapValue( 'userView', userView );
         system.mapHandler( 'user/profile', 'userView', 'showUserProfile' );
         system.notify( 'user/profile' );
         //hasExecuted is true
var userView = {
     showUserProfile : function(){
         //do stuff
     }
}
system.mapValue( 'userView', userView );
system.mapHandler( 'showUserProfile', 'userView' );
system.notify( 'showUserProfile' );

//userView.showUserProfile is called
var showUserProfile = function(){
         //do stuff
}
system.mapHandler( 'user/profile', undefined, showUserProfile );
system.notify( 'user/profile' );

//showUserProfile is called
var userView = {};
var showUserProfile = function(){
         //do stuff
}
system.mapValue( 'userView', userView );
system.mapHandler( 'user/profile', 'userView', showUserProfile );
system.notify( 'user/profile' );

//showUserProfile is called within the scope of the userView object
var userView = {
     showUserProfile : function(){
         //do stuff
     }
}
system.mapValue( 'userView', userView );
system.mapHandler( 'user/profile', 'userView', 'showUserProfile', true );
system.notify( 'user/profile' );
system.notify( 'user/profile' );
system.notify( 'user/profile' );

//userView.showUserProfile is called exactly once [!]
var userView = {
     showUserProfile : function( route ){
         //do stuff
     }
}
system.mapValue( 'userView', userView );
system.mapHandler( 'user/profile', 'userView', 'showUserProfile', false, true );
system.notify( 'user/profile' );

//userView.showUserProfile is called and the route/eventName is passed to the handler
Parameters:
{String} eventName/route
{String} key Optional, Default: undefined
If key is undefined the handler will be called without scope.
{String|Function} handler Optional, Default: eventName
If handler is undefined the value of eventName will be used as the name of the member holding the reference to the to-be-called function. handler accepts either a string, which will be used as the name of the member holding the reference to the to-be-called function, or a direct function reference.
{Boolean} oneShot Optional, Default: false
Defines whether the handler should be called exactly once and then automatically unmapped
{Boolean} passEvent Optional, Default: false
Defines whether the event object should be passed to the handler or not.
Returns:
{dijon.System}
See:
dijon.System#notify
dijon.System#unmapHandler

{dijon.System} mapOutlet(sourceKey, targetKey, outletName)
defines outletName as an injection point in targetKeyfor the object mapped to sourceKey
         system.mapSingleton( 'userModel', TestClassA );
         var o = {
         user : undefined //inject
         }
         system.mapOutlet( 'userModel', 'o', 'user' );
         system.mapValue( 'o', o );

         var obj = system.getObject( 'o' );
//obj.user holds a reference to the singleton instance of UserModel
         system.mapSingleton( 'userModel', TestClassA );
         var o = {
         userModel : undefined //inject
         }
         system.mapOutlet( 'userModel', 'o' );
         system.mapValue( 'o', o );

         var obj = system.getObject( 'o' );
//obj.userModel holds a reference to the singleton instance of UserModel
         system.mapSingleton( 'userModel', TestClassA );
         system.mapOutlet( 'userModel' );
         var o = {
         userModel : undefined //inject
         }
         system.mapValue( 'o', o );

         var obj = system.getObject( 'o' );
//o.userModel holds a reference to the singleton instance of userModel
Parameters:
{String} sourceKey
the key mapped to the object that will be injected
{String} targetKey Optional, Default: 'global'
the key the outlet is assigned to.
{String} outletName Optional, Default: sourceKey
the name of the property used as an outlet.
Returns:
{dijon.System}
See:
dijon.System#unmapOutlet

{dijon.System} mapSingleton(key, clazz)
Maps clazz as a singleton factory to key
var SomeClass = function(){
}
system.mapSingleton( 'o', SomeClass );

var s1 = system.getObject( 'o' );
var s2 = system.getObject( 'o' );

//s1 and s2 reference the same instance of SomeClass
Parameters:
{String} key
{Function} clazz
Returns:
{dijon.System}

{dijon.System} mapValue(key, useValue)
Maps useValue to key
system.mapValue( 'foo', 'bar' );
var b = system.getObject( 'foo' ); //now contains 'bar'
Parameters:
{String} key
{Object} useValue
Returns:
{dijon.System}

{dijon.System} notify(eventName/route)
calls all handlers mapped to eventName/route
Parameters:
{String} eventName/route
Returns:
{dijon.System}
See:
dijon.System#mapHandler

{dijon.System} unmap(key)
Remove the mapping of key from the system
Parameters:
{String} key
Returns:
{dijon.System}

{dijon.System} unmapHandler(eventName, key, handler)
Unmaps the handler for a specific event/route.
Parameters:
{String} eventName
Name of the event/route
{String} key Optional, Default: undefined
If key is undefined the handler is removed from the global mapping space. (If the same event is mapped globally and specifically for an object, then only the globally mapped one will be removed)
{String | Function} handler Optional, Default: eventName
Returns:
{dijon.System}
See:
dijon.System#mapHandler

{dijon.System} unmapOutlet(target, outlet)
removes an injection point mapping for a given object mapped to key
Parameters:
{String} target
{String} outlet
Returns:
{dijon.System}
See:
dijon.System#addOutlet

Documentation generated by JsDoc Toolkit 2.3.2 on Mon Apr 23 2012 08:37:26 GMT+0200 (CEST)