Last active
October 11, 2016 17:40
-
-
Save zaynyatyi/1a09179c8bf7eb0916845ea6a0294737 to your computer and use it in GitHub Desktop.
Typed message in hexMachina illustration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test.message; | |
| /** | |
| * ... | |
| * @author Heorhiy Kharvat | |
| */ | |
| class MessageData | |
| { | |
| public var id:Int; | |
| public var message:String; | |
| public function new(id:Int, message:String) | |
| { | |
| this.id = id; | |
| this.message = message; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test.module.welcome.view; | |
| import test.message.MessageData; | |
| import hex.event.MessageType; | |
| import hex.view.viewhelper.ViewHelper; | |
| /** | |
| * ... | |
| * @author Heorhiy Kharvat | |
| */ | |
| class OtherViewHelper extends ViewHelper<IOtherView> | |
| { | |
| public function new() | |
| { | |
| super(); | |
| } | |
| override function _initialize() : Void | |
| { | |
| super._initialize(); | |
| dispatcher.addHandlerTyped(WelcomeModuleMessage.TYPED_TEST, {}, handleTyped); | |
| dispatcher.addHandlerTyped(WelcomeModuleMessage.COMPLEX_TYPED_TEST, {}, handleComplex); | |
| //dispatcher.addHandlerTyped(WelcomeModuleMessage.TYPED_TEST, {}, handleDummy); <-- will fire compilation error | |
| //dispatcher.addHandlerTyped(WelcomeModuleMessage.COMPLEX_TYPED_TEST, {}, handleDummy); <-- will fire compilation error | |
| } | |
| // we can be sure here will be Int if we will use typed dispatches | |
| function handleTyped(id:Int):Void | |
| { | |
| trace(id); | |
| } | |
| // we can easily handle data here | |
| function handleComplex(data:MessageData):Void | |
| { | |
| trace(data.id, data.message); | |
| } | |
| function handleDummy(something:String):Void | |
| { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test.module.welcome.view; | |
| import hex.event.MessageType; | |
| import hex.view.viewhelper.ViewHelper; | |
| /** | |
| * ... | |
| * @author Heorhiy Kharvat | |
| */ | |
| class SomeViewHelper extends ViewHelper<ISomeView> | |
| { | |
| public function new() | |
| { | |
| super(); | |
| } | |
| function triggerDispatches():Void | |
| { | |
| dispatcher.dispatchTyped(WelcomeModuleMessage.TYPED_TEST, 1); | |
| dispatcher.dispatchTyped(WelcomeModuleMessage.COMPLEX_TYPED_TEST, new MessageData(1, "test")); | |
| //dispatcher.dispatchTyped(WelcomeModuleMessage.COMPLEX_TYPED_TEST, "string data"); <-- will fire compilation error | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test.message; | |
| import hex.event.MessageType; | |
| import hex.event.TypedMessageType; | |
| /** | |
| * ... | |
| * @author Heorhiy Kharvat | |
| */ | |
| class TestModuleMessage | |
| { | |
| static public var SIMPLE_TYPED_TEST = new TypedMessageType<Int>("simple_typed_test"); | |
| static public var COMPLEX_TYPED_TEST = new TypedMessageType<MessageData>("simple_typed_test"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment