BSHT: Views and Mediators Deep Dive, Ready for Review

The Mediation section of the Big, Strange How-To is ready for your inspection and commentary.

Strange mediation flowchart

A flowchart of how View mediation happens in StrangeIoC

https://docs.google.com/document/d/10aGHuasL6GMFhwgvrO5JNec2CK0zIRsanCa5MnV1c1A/edit?usp=sharing

Advertisements

ListensTo: The Sound of His Master’s Voice

Just a quickie post to introduce you to a nice enhancement, now part of the upcoming Strange release.

The sound of his master's voice.

Good Will Corwin, author of Strange Signals and my co-owner of StrangeIoC, has added a feature that allows you to remove some unnecessary legwork from your Mediators.

How many times have you typed some variation of this?

[Inject]
public MySignal mySignal {get; set;}

override public OnRegister()
{
    mySignal.AddListener(listenerMethod);
}
override public OnRemove()
{
    mySignal.RemoveListener(listenerMethod);
}
private void listenerMethod()
{
    //Took a lot of lines of code to get here
}

Now in the whole, vast scheme of things, this isn’t the worst thing in the known universe (I reserve that kind of derision for blended whisky). But it’s a lot of boilerplate, and pretty annoying when you’re trying to code as fast as you think.

Will’s latest work gets us to the same result a lot faster, and just as clearly:

[ListensTo(typeof(MySignal))]
public void listenerMethod()
{
    //Wow! That was fast!
}

[edit]I changed the method accessor above to ‘public’. Only public methods areĀ  scanned for ListensTo. ‘private’ and ‘protected’ methods aren’t scanned (we always try to minimize the costs associated with reflection), so there’s no simple way at present to throw an error and alert you if you mark the method incorrectly. We’re looking at whether we can do this better.[/edit]

The ListensTo attribute allows us to implicitly handle injection, and the adding and removing of Signal listeners at the default moments, thereby making your code that bit more concise and manageable. As with anything to do with reflection, we encourage you to be cautious with this use in your main game loop (i.e., don’t create and destroy lots of Mediators at performance-critical moments…this has always been the case).

The new version of Strange is fast approaching. You can see the evolving feature list here: https://github.com/strangeioc/strangeioc/wiki/TODO-list-for-next-version.

It’s probably worth pointing out that these features are in flux…and we’re not ruling out more. If there’s something you need or just really want, please let us know!