What's the best way to mediate signals?

jansensan's Avatar

jansensan

24 May, 2012 03:50 AM

It's a simple question really, but I wonder which is the most efficient way.

So in a mediator I do this:

signalMap.addToSignal(stateModel.updated, onStateUpdated);
signalMap.addToSignal(contentService.updated, onContentUpdated);

Then I realized I could simply do this:

stateModel.updated.add(onStateUpdated);
contentService.updated.add(onContentUpdated);

So my understanding is that the second options skips the whole signal mapping, thus being quicker. I would then only keep signal mapping for the signals that are singletons.

Does that sound alright, or is there something else I should consider?

Thanks for your opinion!

  1. 1 Posted by Stray on 24 May, 2012 04:06 AM

    Stray's Avatar

    With signalMap.addToSignal, when the mediator is removed, all your signal handlers are also removed. This provides parity with the eventMap.

    with

    stateModel.updated.add... etc

    you need to manually do

    stateModel.updated.remove... etc

    for every signal, in your onRemove (v1) or destroy (v2) function in the mediator.

    If you don't remove the handlers from the signals then you risk the possibility of a memory leak, and of multiple-handlers being added to the same signal (because each new mediator instance would add a new handler).

    So - I'd always take the signalMap route myself. I'm not sure that the signal / singleton issue is directly relevant.

    hth,

    Stray

  2. 2 Posted by jansensan on 24 May, 2012 05:25 AM

    jansensan's Avatar

    That's an interesting point! I don't need to dispose of any of the views in this project, but it's a nice thing to think of. Thanks for your input!

  3. Ondina D.F. closed this discussion on 21 Jun, 2012 08:18 PM.

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