Different ChannelDispatchers

Philip's Avatar

Philip

12 Sep, 2014 08:52 AM

Hi Ondina, I am a little confused as to the usage of channelIds

ModuleB

moduleConnector.onChannel('parent-child-channel')
. receiveEvent (ModularConnectorEvent.SHELL_TO_MODULES_MESSAGE);

moduleConnector.onChannel('parent-child-channel')
. relayEvent (ModularConnectorEvent.MODULES_TO_SHELL_MESSAGE);

moduleConnector.onChannel('sibling -channel')
. receiveEvent (ModularConnectorEvent.A_TO_B_MESSAGE);

moduleConnector.onChannel('sibling -channel')
. relayEvent (ModularConnectorEvent.B_TO_A_MESSAGE);

vs.

moduleConnector.onChannel('some-channel')
. receiveEvent (ModularConnectorEvent.SHELL_TO_MODULES_MESSAGE);

moduleConnector.onChannel('some-channel')
. relayEvent (ModularConnectorEvent.MODULES_TO_SHELL_MESSAGE);

moduleConnector.onChannel('some-channel')
. receiveEvent (ModularConnectorEvent.A_TO_B_MESSAGE);

moduleConnector.onChannel('some-channel')
. relayEvent (ModularConnectorEvent.B_TO_A_MESSAGE);

If a context listens to custom events of a particular type, what does it matter which channel it is on?

Thanks.
Philip

  1. 1 Posted by Philip on 12 Sep, 2014 09:02 AM

    Philip's Avatar

    Well, come to think of it, I guess you could have two different contexts who are interested in the same event but from different channels.

  2. Support Staff 2 Posted by Ondina D.F. on 12 Sep, 2014 10:35 AM

    Ondina D.F.'s Avatar

    Hey Philip,

    Yes, it might be a bit confusing, firstly, because there are 2 kinds of channels: the default channel, and custom channels, and secondly because there are 2 slightly different examples:

    a.
    https://github.com/Ondina/robotlegs-bender-modular-air (see the readme)
    Here, I wanted to show how that works for both situations, default and custom channels

    and

    b.
    https://github.com/Ondina/robotlegs-bender-as3-modular-example
    Here, it was about having multiple custom channels, and also models and commands

    Maybe I should make it more clear in the readme files that there are 2 kinds of channels, when I get a chance...

    When you use moduleConnector.onDefaultChannel(), the modularity extension is defining a channel internally, and all you have to do is find good names for your events:

    SHELL

    moduleConnector.onDefaultChannel()
        .relayEvent(ModularConnectorEvent.SHELL_TO_MODULES_MESSAGE);
    
    moduleConnector.onDefaultChannel()
        .receiveEvent(ModularConnectorEvent.MODULES_TO_SHELL_MESSAGE);
    

    MODULE

    moduleConnector.onDefaultChannel()
        .receiveEvent(ModularConnectorEvent.SHELL_TO_MODULES_MESSAGE);
    
    moduleConnector.onDefaultChannel()
        .relayEvent(ModularConnectorEvent.MODULES_TO_SHELL_MESSAGE);
    

    Obviously, with moduleConnector.onChannel('name_of_your_custom_channel') we can name the channels as we wish.

    So, you can use one single channel (default or custom), but you have to use different event types for the relaying and receiving events. There is still an unsolved issue with the moduleConnector when using the same event type for relying and receiving events - causing an infinite loop, but that's probably not affecting you.

    Having multiple custom channels is a matter of preferences. Those were silly names in my examples, but in a real project, you might want to name your channels and the event types in a way that makes sense to you. The names should help you see the relationship between the modules and their roles.

    Let me know, whether the above explanation made things more clear, or on the contrary it made the confusion even worse;)

    Ondina

  3. 3 Posted by Philip on 12 Sep, 2014 11:14 AM

    Philip's Avatar

    Your explanation is clear. I think I will use custom channel names as indexical tokens then. Could be quite helpful.

    Thanks again,
    Philip

  4. Philip closed this discussion on 12 Sep, 2014 11:15 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac