Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

package robotlegs.bender.extensions.commandCenter.api
{

/**
* @private
*/
Expand Down Expand Up @@ -38,6 +37,14 @@ package robotlegs.bender.extensions.commandCenter.api
*/
function get fireOnce():Boolean;

/**
* Command "group" identifier.
*
* @see robotlegs.bender.extensions.commandCenter.dsl.ICommandConfigurator#toGroup()
* @see robotlegs.bender.extensions.eventCommandMap.api.IEventCommandMap#unmapGroup()
*/
function get groupName() : String;

/**
* Supply the payload values via instance injection
*/
Expand Down Expand Up @@ -67,5 +74,15 @@ package robotlegs.bender.extensions.commandCenter.api
* Supply the payload values via instance injection
*/
function setPayloadInjectionEnabled(value:Boolean):ICommandMapping;

/**
* Setup specific command's identifier, further we can unmap all commands with the same groupName
* @param name
* @return Self
*
* @see robotlegs.bender.extensions.commandCenter.dsl.ICommandConfigurator#toGroup()
* @see robotlegs.bender.extensions.eventCommandMap.api.IEventCommandMap#unmapGroup()
*/
function setGroup(name : String) : void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,12 @@ package robotlegs.bender.extensions.commandCenter.dsl
* @return Self
*/
function withPayloadInjection(value:Boolean = true):ICommandConfigurator;

/**
* Specific command's identifier, further we can unmap all commands with the same groupName
* @param name
* @return Self
*/
function toGroup(name : String) : ICommandConfigurator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,13 @@ package robotlegs.bender.extensions.commandCenter.impl
_mapping.setPayloadInjectionEnabled(value);
return this;
}

/**
* @inheritDoc
*/
public function toGroup(name : String) : ICommandConfigurator {
_mapping.setGroup(name);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ package robotlegs.bender.extensions.commandCenter.impl
return _payloadInjectionEnabled;
}

private var _groupName:String;

/**
* @inheritDoc
*/
public function get groupName() : String {
return _groupName;
}

/*============================================================================*/
/* Constructor */
/*============================================================================*/
Expand Down Expand Up @@ -141,6 +150,13 @@ package robotlegs.bender.extensions.commandCenter.impl
return this;
}

/**
* @inheritDoc
*/
public function setGroup(name : String) : void {
_groupName = name;
}

public function toString():String
{
return 'Command ' + _commandClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package robotlegs.bender.extensions.commandCenter.impl
{
import flash.utils.Dictionary;
import robotlegs.bender.extensions.commandCenter.api.ICommandTrigger;
import robotlegs.bender.extensions.eventCommandMap.impl.EventCommandTrigger;

/**
* @private
Expand Down Expand Up @@ -62,6 +63,15 @@ package robotlegs.bender.extensions.commandCenter.impl
return destroyTrigger(getKey(params));
}

/**
* @private
*/
public function unmapGroup(groupName : String) : void {
for each (var trigger : EventCommandTrigger in _triggers) {
trigger.unmapGroup(groupName);
}
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,11 @@ package robotlegs.bender.extensions.eventCommandMap.api
* @return Self
*/
function addMappingProcessor(handler:Function):IEventCommandMap;

/**
* Unmap all commands with specified groupName.
* @param groupName
*/
function unmapGroup(groupName : String) : void;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ package robotlegs.bender.extensions.eventCommandMap.impl
return this;
}

/**
* @inheritDoc
*/
public function unmapGroup(groupName : String) : void {
_triggerMap.unmapGroup(groupName);
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package robotlegs.bender.extensions.eventCommandMap.impl
import flash.events.Event;
import flash.events.IEventDispatcher;
import robotlegs.bender.extensions.commandCenter.api.ICommandExecutor;
import robotlegs.bender.extensions.commandCenter.api.ICommandMapping;
import robotlegs.bender.extensions.commandCenter.api.ICommandMappingList;
import robotlegs.bender.extensions.commandCenter.api.ICommandTrigger;
import robotlegs.bender.extensions.commandCenter.impl.CommandExecutor;
Expand Down Expand Up @@ -89,6 +90,17 @@ package robotlegs.bender.extensions.eventCommandMap.impl
_dispatcher.removeEventListener(_type, eventHandler);
}

/**
* @private
*/
public function unmapGroup(groupName : String) : void {
for each (var mapping : ICommandMapping in _mappings.getList()) {
if (mapping.groupName == groupName) {
_mappings.removeMapping(mapping);
}
}
}

public function toString():String
{
return _eventClass + " with selector '" + _type + "'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ package robotlegs.bender.extensions.mediatorMap.api
*/
function unmap(type:Class):IMediatorUnmapper;

/**
* Removes all mappings that was linked to specified group name.
* No error will be thrown if there isn't a mapping to remove.
* @param groupName Mapping group's name that would be key.
*/
function unmapGroup(groupName : String) : void;

/**
* Mediates an item directly. If the item matches any mapped matchers or types then it will be mediated according to those mappings.
* @param item The item to create mediators for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@ package robotlegs.bender.extensions.mediatorMap.api
* Should the mediator be removed when the mediated item looses scope?
*/
function get autoRemoveEnabled():Boolean;

/**
* Mapping group identifier
*/
function get groupName() : String;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,12 @@ package robotlegs.bender.extensions.mediatorMap.dsl
* @return Self
*/
function autoRemove(value:Boolean = true):IMediatorConfigurator;

/**
* Add mapping to mapping group, futher whole group can be instantly unmapped with this identifier
* @param groupName Mapping group identifier
* @return Self
*/
function toGroup(groupName : String):IMediatorConfigurator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ package robotlegs.bender.extensions.mediatorMap.dsl
* Unmaps all mediator mappings for this matcher
*/
function fromAll():void;

/**
* Unmap all mediator mappings that linked to specified group
* @param groupName Mapping group identifier
*/
function unmapGroup(groupName : String) : void;
}
}
11 changes: 11 additions & 0 deletions src/robotlegs/bender/extensions/mediatorMap/impl/MediatorMap.as
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ package robotlegs.bender.extensions.mediatorMap.impl
return unmapMatcher(new TypeMatcher().allOf(type));
}

/**
* @inheritDoc
*/
public function unmapGroup(groupName : String) : void
{
for each (var mapper : IMediatorUnmapper in _mappers)
{
mapper.unmapGroup(groupName)
}
}

/**
* @inheritDoc
*/
Expand Down
20 changes: 20 additions & 0 deletions src/robotlegs/bender/extensions/mediatorMap/impl/MediatorMapper.as
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ package robotlegs.bender.extensions.mediatorMap.impl
}
}

/**
* @inheritDoc
*/
public function unmapGroup(groupName : String) : void
{
var mappingsToDelete : Vector.<IMediatorMapping> = new <IMediatorMapping>[];
var mapping : IMediatorMapping;
for each (mapping in _mappings)
{
if (mapping.groupName == groupName)
{
mappingsToDelete.push(mapping);
}
}
for each (mapping in mappingsToDelete)
{
deleteMapping(mapping);
}
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,15 @@ package robotlegs.bender.extensions.mediatorMap.impl
return _autoRemoveEnabled;
}

private var _groupName : String = "";

/**
* @inheritDoc
*/
public function get groupName() : String {
return _groupName;
}

/*============================================================================*/
/* Constructor */
/*============================================================================*/
Expand Down Expand Up @@ -114,5 +123,14 @@ package robotlegs.bender.extensions.mediatorMap.impl
_autoRemoveEnabled = value;
return this;
}

/**
* @inheritDoc
*/
public function toGroup(groupName : String):IMediatorConfigurator
{
_groupName = groupName;
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,12 @@ package robotlegs.bender.extensions.mediatorMap.impl
public function fromAll():void
{
}

/**
* @private
*/
public function unmapGroup(groupName : String) : void
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,12 @@ package robotlegs.bender.extensions.commandCenter.impl
mapping.setPayloadInjectionEnabled(false);
assertThat(mapping.payloadInjectionEnabled, isFalse());
}

[Test]
public function group_mapping():void
{
mapping.setGroup("test");
assertThat(mapping.groupName, equalTo("test"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,20 @@ package robotlegs.bender.extensions.eventCommandMap.impl
assertThat(callCount, equalTo(1));
}

[Test]
public function group_mapping() : void {
var executeCount:uint = 0;
var groupName : String = "test";
injector.map(Function, 'executeCallback').toValue(function():void
{
executeCount++;
});
subject.map(SupportEvent.TYPE1, SupportEvent).toCommand(CallbackCommand).toGroup(groupName);
subject.unmapGroup(groupName);
dispatcher.dispatchEvent(new SupportEvent(SupportEvent.TYPE1));
assertThat(executeCount, equalTo(0));
}

/*============================================================================*/
/* Private Functions */
/*============================================================================*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,41 @@ package robotlegs.bender.extensions.mediatorMap.impl
{
mediatorMap.unmap(Sprite).fromMediator(ExampleMediator);
}

[Test]
public function unmap_group_for_strict_mapping() : void {
var groupName : String = "test";
mediatorMap.map(Sprite).toMediator(ExampleMediator).toGroup(groupName);
mediatorMap.unmapGroup(groupName);

mediatorMap.handleView(new Sprite(), null);

const expectedNotifications:Vector.<String> = new <String>[];
assertEqualsVectorsIgnoringOrder(expectedNotifications, mediatorWatcher.notifications);
}

[Test]
public function unmap_group_for_type_matcher() : void {
var groupName : String = "test";
mediatorMap.mapMatcher(new TypeMatcher().allOf(DisplayObject)).toMediator(ExampleDisplayObjectMediator).toGroup(groupName);
mediatorMap.unmapGroup(groupName);

mediatorMap.handleView(new Sprite(), null);

const expectedNotifications:Vector.<String> = new <String>[];
assertEqualsVectorsIgnoringOrder(expectedNotifications, mediatorWatcher.notifications);
}

[Test]
public function unmap_one_group_doesnt_affect_another() : void {
mediatorMap.map(Sprite).toMediator(ExampleMediator).toGroup("firstGroup");
mediatorMap.unmapGroup("secondGroup");

mediatorMap.handleView(new Sprite(), null);

const expectedNotifications:Vector.<String> = new <String>['ExampleMediator'];
assertEqualsVectorsIgnoringOrder(expectedNotifications, mediatorWatcher.notifications);
}
}
}

Expand Down