This is not specifically a query about RL but more about whether this is a good idea or not, im personally not sure but I was wondering if you had any opinions.
Im currently writing a database in Air using Robotlegs. I have a view with a list of tables on the left and the currently active table displayed as a DataGrid. What I want is that whenever a change occurs to a table (a change could be a row added, row removed, schema change, cell edit etc etc).
What I was doing previously was to have a number of signals on each table for the various events "rowAdded" "rowRemoved" etc. Then in the TablesListItemRenderer I was listening for all the various changes on the table. The problem was I was getting in quite a mess. Firstly the view itself was starting to look pretty ugly with lots of signal.add and signal.remove calls. Secondly it was getting complicated to detect a table change particularly when a cell edit would need to bubble up from the cell to the row then to the table etc.
What I decided was instead of having the signals on the Table, Row, Cell etc, instead put all the signals in a single "SignalBus" so for example:
public class SignalBus
{
public var rowAdded : Signal = new Signal(Row);
public var rowDeleted : Signal = new Signal(Row);
public var cellEdited : Singla = new Signal(Cell);
public var tableChanged : Signal = new Signal(Table);
}
Then in the context I mapped as a singleton and had that injected into all my tables, rows, cells. When one of these events occurs they instead dispatch the signal bus signal with 'this' as the parameter.
Then I wrote TablesListItemRendererMediator:
public class TablesListItemRendererMediator extends CoreMediator
{
[Inject] public var view : TablesListItemRenderer;
[Inject] public var bus : SignalBus;
override public function onRegister():void
{
addSignalListener(bus.cellEdited, onCellEdited);
addSignalListener(bus.rowAdded, onRowAdded);
addSignalListener(bus.rowDeleted, onRowDeleted);
addSignalListener(bus.tableChanged, onTableChanged);
}
private function onTableChanged(t:Table):void
{
if(t==view.table) view.update();
}
private function onRowDeleted(r:Row):void
{
if(r.table==view.table) view.update();
}
private function onRowAdded(r:Row):void
{
if(r.table==view.table) view.update();
}
private function onCellEdited(c:Cell):void
{
if(c.row.table==view.table) view.update();
}
}
This way I am able to shift the listening out of the view and into the mediator.
Is this how you guys would have solved this problem? Or is there a better way? Is a 'global' signal bus a good idea?