Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
..
Failed to load latest commit information.
api
dsl
impl
ModularityExtension.as
readme.md

readme.md

Modularity Extension

Overview

The modularity extensions wires contexts into a hierarchy based on the context view and allows for inter-modular communication.

Basic usage

Communication between modules is facilitated by the Module Connector.

Setup to allow sending events from one module to the other:

//ModuleAConfig.as

[Inject]
public var moduleConnector: IModuleConnector;

moduleConnector.onDefaultChannel()
	.relayEvent(WarnModuleBEvent.WARN);

Setup to allow reception of events from another module:

//ModuleBConfig.as
[Inject]
public var moduleConnector:IModuleConnector;

moduleConnector.onDefaultChannel()
	.receiveEvent(WarnModuleBEvent.WARN);

Now ModuleB can map commands to the event, or allow mediators to attach listeners to it:

eventCommandMap.map(WarnModuleBEvent.WARN)
	.toCommand(HandleWarningFromModuleACommand);

All ModuleA needs to do is dispatch the event:

eventDispatcher.dispatchEvent(new WarnModuleBEvent(WarnModuleBEvent.WARN);

Named channels

If you want to sandbox the communication between two modules, you can use named channels:

//ModuleAConfig.as
moduleConnector.onChannel('A-and-B')
	.relayEvent(WarnModuleBEvent.WARN);
//ModuleBConfig.as
moduleConnector.onChannel('A-and-B')
	.receiveEvent(WarnModuleBEvent.WARN);

Requirements

This extension requires the following extensions:

  • ContextViewExtension

Extension Installation

_context = new Context()
    .install(ContextViewExtension, ModularityExtension)
    .configure(new ContextView(this));

In the example above we provide the instance "this" to use as the Context View. We assume that "this" is a valid DisplayObjectContainer.

By default the extension will be configured to inherit dependencies from parent contexts and expose dependencies to child contexts. You can change this by supplying parameters to the extension during installation:

_context = new Context()
    .install(ContextViewExtension)
    .install(new ModularityExtension(true, false))
    .configure(new ContextView(this));

The example context above inherits dependencies from parent contexts but does not expose its own dependencies to child contexts. However, child contexts may still inherit dependencies from this context's parents.