Last active
August 29, 2015 13:57
-
-
Save tosik/9501208 to your computer and use it in GitHub Desktop.
Robotlegs2 とは ref: http://qiita.com/tosik/items/45a7e68d3c987ca8d2e6
This file contains 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
public class Application extends Sprite | |
{ | |
public function Apllication() | |
{ | |
var context:Context = new Context() | |
.install(MVCSBundle) | |
.configure(MainConfig) | |
.configure(ContextView(this)) | |
context.initialize(); | |
} | |
} |
This file contains 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
public class Foo | |
{ | |
[Inject] | |
public var bar:Bar; | |
} |
This file contains 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
// configuration | |
var user:User = new User; | |
injector.map(User).toValue(user); | |
// when user.name changed then print the name | |
user.nameChanged.add(function():void | |
{ | |
// command instantiation | |
var command:PrintUsernameCommand = new PrintUsernameCommand(); | |
injector.injectInto(command); | |
// command execution | |
command.execute(); | |
}); | |
user.name = "Taro"; // => "The user's name is Taro." |
This file contains 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
public class MainConfig implements IConfig | |
{ | |
[Inject] | |
public var injector:IInjector; | |
[Inject] | |
public var mediatorMap:IMediatorMap; | |
[Inject] | |
public var contextView:ContextView; | |
public function configure():void | |
{ | |
injector.map(User).asSingleton(); | |
mediatorMap.map(UserView).toMeidator(UserViewMediator); | |
contextView.addChild(new UserView); | |
} | |
} |
This file contains 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
public class PrintUsernameCommand | |
{ | |
[Inject] | |
public var user:User; | |
private var _printer:Printer = new Printer; | |
public function execute():void | |
{ | |
_printer.print("The user's name is " + user.name + "."); | |
} | |
} |
This file contains 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
public class User | |
{ | |
public const nameChanged:Signal = new Signal; | |
private var _name:String; | |
public function get name():String { return _name; } | |
public function set name(value:String):void | |
{ | |
_name = value; | |
nameChanged.dispatch(); | |
} | |
} |
This file contains 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
public class UserView extends Sprite | |
{ | |
private var _nameTextField:TextField; | |
public function UserView() | |
{ | |
_nameTextField = new TextField; | |
addChild(_nameTextField); | |
} | |
public function changeName(name:String):void | |
{ | |
_nameTextField.text = name; | |
} | |
} |
This file contains 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
public class UserViewMediator extends Mediator | |
{ | |
[Inject] | |
public var view:UserView; | |
[Inject] | |
public var user:User; | |
public override function initialize():void | |
{ | |
user.nameChanged.add(changeView); | |
} | |
public override function destroy():void | |
{ | |
user.nameChanged.remove(changeView); | |
} | |
public function changeView():void | |
{ | |
view.changeName(user.name); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment