Dart DocumentationdartscaleSandbox

Sandbox class

An object through which the module has access to several functions of the Framework, such as the Cores Mediator.

Also a Sandbox can have several plugins registered to have fine grained controll to what the module has access.

class Sandbox {
 
 static final Map<Symbol, dynamic> _plugins = new Map<Symbol, dynamic>();
 
 Mediator _mediator;
 
 Sandbox(Mediator this._mediator);
 /**
  * __not used by your code!__
  */
 noSuchMethod(Invocation invocation) {
     var plugin = _plugins[invocation.memberName];
     
     if (invocation.isSetter) {
       throw new UnsupportedError("Setting Plugins is not allowed!");
     }
     
     if (plugin == null) {
       throw new NoSuchPluginError(invocation.memberName.toString());
     }
     
     if (invocation.isGetter || invocation.isAccessor) {
       return plugin;
     }
     else if (invocation.isMethod) {
       return Function.apply(plugin, invocation.positionalArguments, invocation.namedArguments);
     }
 }
 
 /**
  * Register a plugin which can be any object or function.
  * After registration it can be accessed like any property of the sandbox.
  * 
  * __example__
  *     var sandbox = new Sandbox(Mediator());
  * 
  *     sandbox.registerPlugin("testMethod", (arg1, arg2) {
  *          return "${arg1}+${arg2}";
  *     });
  * 
  *     var result = sandbox.testMethod("Hello", "World");
  */
 static registerPlugin(String name, dynamic plugin) {
   _plugins[new Symbol(name)] = plugin;
 }
 
 /**
  * Access to the messagebus through [Core]s [Mediator].
  * 
  * __example__
  *     this.sandbox.channel('mychannel').topic('mytopic').listen((data) {
  *         print('Hello ${data}!');
  *     });
  *     
  *     this.sandbox.channel('mychannel').topic('mytopic').add('World');
  */
 MediatorChannel channel (String channelName) {
   return this._mediator.channel(channelName);
 }
}

Static Methods

dynamic registerPlugin(String name, plugin) #

Register a plugin which can be any object or function. After registration it can be accessed like any property of the sandbox.

example

var sandbox = new Sandbox(Mediator());

sandbox.registerPlugin("testMethod", (arg1, arg2) {
     return "${arg1}+${arg2}";
});

var result = sandbox.testMethod("Hello", "World");
static registerPlugin(String name, dynamic plugin) {
 _plugins[new Symbol(name)] = plugin;
}

Constructors

new Sandbox(Mediator _mediator) #

Sandbox(Mediator this._mediator);

Methods

MediatorChannel channel(String channelName) #

Access to the messagebus through Cores Mediator.

example

this.sandbox.channel('mychannel').topic('mytopic').listen((data) {
    print('Hello ${data}!');
});

this.sandbox.channel('mychannel').topic('mytopic').add('World');
MediatorChannel channel (String channelName) {
 return this._mediator.channel(channelName);
}

dynamic noSuchMethod(Invocation invocation) #

not used by your code!

noSuchMethod(Invocation invocation) {
   var plugin = _plugins[invocation.memberName];
   
   if (invocation.isSetter) {
     throw new UnsupportedError("Setting Plugins is not allowed!");
   }
   
   if (plugin == null) {
     throw new NoSuchPluginError(invocation.memberName.toString());
   }
   
   if (invocation.isGetter || invocation.isAccessor) {
     return plugin;
   }
   else if (invocation.isMethod) {
     return Function.apply(plugin, invocation.positionalArguments, invocation.namedArguments);
   }
}