Had a lot of fun with this one. I’ve worked with PureMVC in the past, and while I appreciated the framework for staying true to its name, I found it unwieldy and difficult to use correctly in practice. Along came SignalsCircuit, an extension to the framework by Omar Gonzalez (@s9tpepper) that really helped.
“SignalsCircuit is a small set of classes that implement and extend PureMVC core classes and interfaces to allow you to wire Signals to a Command pattern that provides access to the rest of your application via your PureMVC Facade implementation.”
Basically, the notification/controller system is overridden to use as3-Signals, and all of a sudden PureMVC became a pleasure to work with. My code retains the benefits of being loosely coupled, but is much easier to follow and understand– and Signals are also faster than notifications. My only criticism would be that Commands receive arguments from Signals as Arrays, which doesn’t feel or look very nice… but I don’t think that can actually be improved, so … whatevs!
The architecture and code essentially wrote itself. I spent way more time in Maya jiggering with the model than actually planning or coding, and I am pretty satisfied with the code. Though there are some improvements I would like to make:
- Abstract away3D functionality into a wrapper class. Currently have no choice but to scatter references to the class that was generated by prefab (away3D modeling helper tool) in my application. A wrapper class would be a step towards mitigating the effects of the dependency.
- Integrate unit tests. Obviously it’s a little late for this (you’re supposed to let the writing of the tests drive your programming) but from what I hear, having the tests is better than nothing. However I did run into some big problems with unit testing that I could not solve, perhaps you all have some hints?
- I like to use local variables wherever possible, so as to black-box not just my classes but my functions as well. How does one test a function such as UseFaceCaptureAsTextureCommand.execute() ?
- Do you only test your public API? No protected or private functions? I won’t be testing very much in that case.
- I know I can use FlexUnit4 Asynchronous Tests to test functions that are dependent on events, but how do I go about this with Signals?
- Find more concise class names. I picked my own brain pretty hard on this one but am not satisfied with a 60 character command name (SupplyToUntexturedProxyAndAssembleTextureAs3DMaterialCommand – yeesh). I know I know, there is an “And” in there. But I just could not bring myself to break apart a Command with only 7 lines of real code in it into two separate Commands.
- You’ll notice there are virtually no comments in the code. This was an attempt at writing code so readable I wouldn’t need to comment it. I hope I got close. So if you’re looking through it and are going “WTF?” please let me know in the comments.
I’m sure there is a lot more I could improve… and I’ll probably regret this, but I invite you to take a sip of haterade, pore through the code and let me know what you would do differently!
coming soon, I’ll write up the steps I took to architect this guy.