SlideShare a Scribd company logo
關於 PureMVC Command 的
       那點事
              Erin Lin
      http://about.me/erinlin
到處都有 Command...
Command 是?
Command 是?
Command 是?
Command 是?
Command
Command       Command


Command
       Command
   Command
         Command
       不想學還是要學的
 Command
         命令 設計模式
 Command         Command
                Command
Command Command
    Command
       Command
<<interface>>
                         ICommand


     Controller         execute():void

   addCommand()
 removeCommand()
//-------------------    Command
   doSomething()

                        execute():void
真情推薦
傻瓜都可以看懂的設計模式入門書
    自己上網去買!




     http://www.oreilly.com.tw/product_java.php?id=a163
回到 PureMVC...
PureMVC
兩個基本必知 Command
最基本的
SimpleCommand
反正要亂搞就是
    extends
SimpleCommand
你認識的第一支繼承 SimpleCommand 寫法
package com.mvc.controls
{
	 	
	 import org.puremvc.as3.interfaces.INotification;
	 import org.puremvc.as3.patterns.command.SimpleCommand;

	   public class StartupCommand extends SimpleCommand
	   {
	   	 public function StartupCommand()
	   	 {
	   	 	 super();
	   	 }
	   	 override public function execute(notification:INotification):void{
	   	 	 //初始 Application 要做的事情
	   	 	 //facade.registerMediator, facade.registerProxy
	   	   	   // or facade.registerCommand
	   	   	   //通常都會將 Application 傳進來做應用
	   	   }
	   }
}
群組同時執行的
MacroCommand
使用 MacroCommand 的 StartupCommand

package com.mvc.controls
{
	 import org.puremvc.as3.patterns.command.MacroCommand;

	   public class StartupCommand extends MacroCommand
	   {
	   	 public function StartupCommand()
	   	 {
	   	 	 super();
	   	 }
	   	
	   	 override protected function initializeMacroCommand() :void
         {
         		 addSubCommand( ModelPrepCommand );
         		 addSubCommand( ViewPrepCommand );
	   	 	 	 addSubCommand( 你寫的Command );
         }
	   }
}
啊...我想要一個命令做完,
    才要執行下一個....
最後還要來個完美的 Ending
  要怎麼辦?
http://trac.puremvc.org/PureMVC_AS3/




                              PureMVC Utilities
                                 使用的時候要心存感激喔!
處理非同步的 AsyncCommand




      http://trac.puremvc.org/Utility_AS3_AsyncCommand
啥叫非同步?
當然就是一件工作做完
  才做下一個指令
 照順序來不懂嗎?
AsyncCommand 也有
 兩個 Class 給你用
AsyncCommand and
AsyncMacroCommand
基本用法是以成組的方式應用
package controllers
{
	 import flash.utils.setTimeout;
	
	 import org.puremvc.as3.multicore.interfaces.ICommand;
	 import org.puremvc.as3.multicore.interfaces.INotification;
	 import org.puremvc.as3.multicore.patterns.command.AsyncCommand;
	
	 public class AsyncCommand0 extends AsyncCommand implements ICommand
	 {
	 	 public function AsyncCommand0()
	 	 {
	 	 	 super();
	 	 }
	 	
	 	 override public function execute(notification:INotification):void{
	 	 	 trace("lalala AsyncCommand0");
	 	 	 setTimeout( commandComplete, 1000);
	 	 }
	 }
}
package controllers
{
	 import
org.puremvc.as3.multicore.patterns.command.AsyncMacroCommand;
	
	 public class StartupCommand extends AsyncMacroCommand
	 {
	 	 public function StartupCommand()
	 	 {
	 	 	 super();
	 	 }
	 	 private function onComplete():void{
	 	 	 trace("end of StartupCommand");
	 	 }
	 	 override protected function initializeAsyncMacroCommand():void{
	 	 	 setOnComplete( onComplete );
	 	 	 addSubCommand( AsyncCommand0 );
	 	 	 addSubCommand( AsyncCommand1 );
	 	 	 addSubCommand( AsyncCommand2 );
	 	 }
	 }
}
AsyncCommand
    DEMO
所以 Command 可以做什麼?
應用一:Assets loader
package controllers
{
	 import mx.rpc.AsyncToken;
	 import mx.rpc.IResponder;
	 import mx.rpc.http.HTTPService;
	 import org.puremvc.as3.multicore.interfaces.ICommand;
	 import org.puremvc.as3.multicore.interfaces.INotification;
	 import org.puremvc.as3.multicore.patterns.command.AsyncCommand;	
	 public class LoadConfigCommand extends AsyncCommand implements IResponder
	 {
	 	 public function LoadConfigCommand()
	 	 {
	 	 	 super();
	 	 }
	 	 override public function execute(notification:INotification):void{
	 	 	 var service:HTTPService = new HTTPService;
	 	 	 service.resultFormat = 'xml';
	 	 	 service.url = "your configuration files url";
	 	 	 service.send();
	 	 }	
	 	 public function result( result:Object ):void{
	 	 	 this.commandComplete();
	 	 }
	 	 public function fault( result:Object ):void{
	 	 	 //如果要中斷流程,需要在這邊傳出 ERROR notification 由其他 Command 處理
	 	 }
	 }
package controllers
{
	 import org.puremvc.as3.multicore.patterns.command.AsyncMacroCommand;
	
	 public class StartupCommand extends AsyncMacroCommand
	 {
	 	 public function StartupCommand()
	 	 {
	 	 	 super();
	 	 }
	 	 private function onComplete():void{
	 	 	 trace("end of StartupCommand");
          sendNotification( "APP_INIT" );
	 	 }
	 	 override protected function initializeAsyncMacroCommand():void{
	 	 	 this.setOnComplete( onComplete );
	 	 	 addSubCommand( LoadConfigCommand );
	 	 	 addSubCommand( LoadAssetsCommand );
	 	 	 addSubCommand( LoadXXXCommand );
	 	 }
	 }
}
應用二:做外掛...
package com.controls
{
	   public class GroupEditorCommand extends SimpleCommand implements ICommand
	   {
	   	    public function GroupEditorCommand()
	   	    {
	   	    	   super();
	   	    }
	   	    override public function execute(notification:INotification):void
	   	    {
	   	    	   switch( notification.getName() ){
	   	    	   	    case "GroupEditorCommand.INIT":
	   	    	   	    	   //將之前開發用的 proxy notification 組織起來
	   	    	   	    	   facade.registerCommand( "DataProxy.ITEM_UPDATED" , GroupEditorCommand );
	   	    	   	    	   facade.registerCommand( "XXXProxy.NOTIFICATION_NAME" , GroupEditorCommand );
	   	    	   	    	   showLoader();
	   	    	   	    	   //看你要做什麼起始
	   	    	   	    	   break;
	   	    	   	    case "DataProxy.ITEM_UPDATED":
	   	    	   	    	   //看要叫 proxy 做啥,還是 call 啥畫面出來
	   	    	   	    	   break;
	   	    	   }
	   	    }
	   	    private function clearCommands():void{
	   	    	   facade.removeCommand( "DataProxy.ITEM_UPDATED" );
	   	    	   facade.removeCommand( "XXXProxy.NOTIFICATION_NAME" );
	   	    	   removeLoader();
	   	    	   sendNotification( "GroupEditorCommand.CLOSE" );
	   	    }
	   	    private function showLoader( string:String ):void{
	   	    	   //將檔畫面的 loader call 到前景
	   	    }	
	   	    private function removeLoader():void{
	   	    	   //remove loader
	   	    }
	   }
}
其他?
其實你要怎樣玩它
   就開心的玩吧!
想太多就什麼都寫不出來了!
最後...
請保持愉快的心情
開心的寫程式吧!
FIN
參考資料


•   http://trac.puremvc.org/PureMVC_AS3/

•   http://www.oreilly.com.tw/product_java.php?id=a163

•   http://trac.puremvc.org/Utility_AS3_AsyncCommand

More Related Content

Viewers also liked

Internet in mobilità: scenari, tecnologie ed esigenze dei Consumatori
Internet in mobilità: scenari, tecnologie ed esigenze dei ConsumatoriInternet in mobilità: scenari, tecnologie ed esigenze dei Consumatori
Internet in mobilità: scenari, tecnologie ed esigenze dei ConsumatoriVodafoneIT
 
Developing for the BlackBerry PlayBook using Flex Builder Burrito
Developing for the BlackBerry PlayBook using Flex Builder BurritoDeveloping for the BlackBerry PlayBook using Flex Builder Burrito
Developing for the BlackBerry PlayBook using Flex Builder Burrito
Yuri Visser
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
Yuri Visser
 
Switching perspectives nov10 s sh
Switching perspectives nov10 s shSwitching perspectives nov10 s sh
Switching perspectives nov10 s sh
John Juliano
 
An Opinionated Introduction to Mate
An Opinionated Introduction to MateAn Opinionated Introduction to Mate
An Opinionated Introduction to Mate
Effective
 
Architecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVCArchitecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVC
marcocasario
 
User Testing: Adapt to Fit Your Needs
User Testing: Adapt to Fit Your NeedsUser Testing: Adapt to Fit Your Needs
User Testing: Adapt to Fit Your Needs
Effective
 

Viewers also liked (7)

Internet in mobilità: scenari, tecnologie ed esigenze dei Consumatori
Internet in mobilità: scenari, tecnologie ed esigenze dei ConsumatoriInternet in mobilità: scenari, tecnologie ed esigenze dei Consumatori
Internet in mobilità: scenari, tecnologie ed esigenze dei Consumatori
 
Developing for the BlackBerry PlayBook using Flex Builder Burrito
Developing for the BlackBerry PlayBook using Flex Builder BurritoDeveloping for the BlackBerry PlayBook using Flex Builder Burrito
Developing for the BlackBerry PlayBook using Flex Builder Burrito
 
Lunch and learn as3_frameworks
Lunch and learn as3_frameworksLunch and learn as3_frameworks
Lunch and learn as3_frameworks
 
Switching perspectives nov10 s sh
Switching perspectives nov10 s shSwitching perspectives nov10 s sh
Switching perspectives nov10 s sh
 
An Opinionated Introduction to Mate
An Opinionated Introduction to MateAn Opinionated Introduction to Mate
An Opinionated Introduction to Mate
 
Architecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVCArchitecting ActionScript 3 applications using PureMVC
Architecting ActionScript 3 applications using PureMVC
 
User Testing: Adapt to Fit Your Needs
User Testing: Adapt to Fit Your NeedsUser Testing: Adapt to Fit Your Needs
User Testing: Adapt to Fit Your Needs
 

Similar to 關於 Puremvc Command 的那點事

Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management ToolPeeyush Ranjan
 
Foomo / Zugspitze Presentation
Foomo / Zugspitze PresentationFoomo / Zugspitze Presentation
Foomo / Zugspitze Presentation
weareinteractive
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
Yun Zhi Lin
 
Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
muthusvm
 
Appium troubleshooting
Appium troubleshootingAppium troubleshooting
Appium troubleshooting
adi ben aroya
 
Command pattern vs. MVC: Lean Beans (are made of this)
Command pattern vs. MVC: Lean Beans (are made of this)Command pattern vs. MVC: Lean Beans (are made of this)
Command pattern vs. MVC: Lean Beans (are made of this)
philipdurbin
 
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
Raimundas Banevičius
 
Presentation Lfoppiano Pycon
Presentation Lfoppiano PyconPresentation Lfoppiano Pycon
Presentation Lfoppiano PyconLuca Foppiano
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a RideBruce Snyder
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
Erlang Herlambang
 
Forcetree.com writing a java program to connect to sfdc
Forcetree.com writing  a java program to connect  to sfdcForcetree.com writing  a java program to connect  to sfdc
Forcetree.com writing a java program to connect to sfdcEdwin Vijay R
 
Will it blend? Java agents and OSGi
Will it blend? Java agents and OSGiWill it blend? Java agents and OSGi
Will it blend? Java agents and OSGi
Robert Munteanu
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
Matthew McCullough
 
Robotlegs Extensions
Robotlegs ExtensionsRobotlegs Extensions
Robotlegs Extensions
Yennick Trevels
 
The Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework EvolutionThe Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework Evolution
FITC
 
Flex Monkey
Flex MonkeyFlex Monkey
Flex Monkey
Yasuhiro Morikawa
 
Setting Apple's UI Automation Free with Appium
Setting Apple's UI Automation Free with AppiumSetting Apple's UI Automation Free with Appium
Setting Apple's UI Automation Free with Appium
mobiletestsummit
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limitsDroidcon Berlin
 

Similar to 關於 Puremvc Command 的那點事 (20)

Transaction Management Tool
Transaction Management ToolTransaction Management Tool
Transaction Management Tool
 
Cursor Demo App
Cursor Demo AppCursor Demo App
Cursor Demo App
 
Foomo / Zugspitze Presentation
Foomo / Zugspitze PresentationFoomo / Zugspitze Presentation
Foomo / Zugspitze Presentation
 
Dropwizard and Friends
Dropwizard and FriendsDropwizard and Friends
Dropwizard and Friends
 
Session2-J2ME development-environment
Session2-J2ME development-environmentSession2-J2ME development-environment
Session2-J2ME development-environment
 
Appium troubleshooting
Appium troubleshootingAppium troubleshooting
Appium troubleshooting
 
Command pattern vs. MVC: Lean Beans (are made of this)
Command pattern vs. MVC: Lean Beans (are made of this)Command pattern vs. MVC: Lean Beans (are made of this)
Command pattern vs. MVC: Lean Beans (are made of this)
 
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
The Next Step in AS3 Framework Evolution - FITC Amsterdam 2013
 
Presentation Lfoppiano Pycon
Presentation Lfoppiano PyconPresentation Lfoppiano Pycon
Presentation Lfoppiano Pycon
 
Taking Apache Camel For a Ride
Taking Apache Camel For a RideTaking Apache Camel For a Ride
Taking Apache Camel For a Ride
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
 
Forcetree.com writing a java program to connect to sfdc
Forcetree.com writing  a java program to connect  to sfdcForcetree.com writing  a java program to connect  to sfdc
Forcetree.com writing a java program to connect to sfdc
 
Will it blend? Java agents and OSGi
Will it blend? Java agents and OSGiWill it blend? Java agents and OSGi
Will it blend? Java agents and OSGi
 
DOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A RideDOSUG Taking Apache Camel For A Ride
DOSUG Taking Apache Camel For A Ride
 
Robotlegs Extensions
Robotlegs ExtensionsRobotlegs Extensions
Robotlegs Extensions
 
The Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework EvolutionThe Next Step in AS3 Framework Evolution
The Next Step in AS3 Framework Evolution
 
Bt j2 me
Bt j2 meBt j2 me
Bt j2 me
 
Flex Monkey
Flex MonkeyFlex Monkey
Flex Monkey
 
Setting Apple's UI Automation Free with Appium
Setting Apple's UI Automation Free with AppiumSetting Apple's UI Automation Free with Appium
Setting Apple's UI Automation Free with Appium
 
Android programming -_pushing_the_limits
Android programming -_pushing_the_limitsAndroid programming -_pushing_the_limits
Android programming -_pushing_the_limits
 

Recently uploaded

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 

Recently uploaded (20)

Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 

關於 Puremvc Command 的那點事

  • 1. 關於 PureMVC Command 的 那點事 Erin Lin http://about.me/erinlin
  • 7. Command Command Command Command Command Command Command 不想學還是要學的 Command 命令 設計模式 Command Command Command Command Command Command Command
  • 8. <<interface>> ICommand Controller execute():void addCommand() removeCommand() //------------------- Command doSomething() execute():void
  • 9. 真情推薦 傻瓜都可以看懂的設計模式入門書 自己上網去買! http://www.oreilly.com.tw/product_java.php?id=a163
  • 13. 反正要亂搞就是 extends SimpleCommand
  • 14. 你認識的第一支繼承 SimpleCommand 寫法 package com.mvc.controls { import org.puremvc.as3.interfaces.INotification; import org.puremvc.as3.patterns.command.SimpleCommand; public class StartupCommand extends SimpleCommand { public function StartupCommand() { super(); } override public function execute(notification:INotification):void{ //初始 Application 要做的事情 //facade.registerMediator, facade.registerProxy // or facade.registerCommand //通常都會將 Application 傳進來做應用 } } }
  • 16. 使用 MacroCommand 的 StartupCommand package com.mvc.controls { import org.puremvc.as3.patterns.command.MacroCommand; public class StartupCommand extends MacroCommand { public function StartupCommand() { super(); } override protected function initializeMacroCommand() :void { addSubCommand( ModelPrepCommand ); addSubCommand( ViewPrepCommand ); addSubCommand( 你寫的Command ); } } }
  • 17. 啊...我想要一個命令做完, 才要執行下一個.... 最後還要來個完美的 Ending 要怎麼辦?
  • 18. http://trac.puremvc.org/PureMVC_AS3/ PureMVC Utilities 使用的時候要心存感激喔!
  • 19. 處理非同步的 AsyncCommand http://trac.puremvc.org/Utility_AS3_AsyncCommand
  • 22. AsyncCommand 也有 兩個 Class 給你用
  • 25. package controllers { import flash.utils.setTimeout; import org.puremvc.as3.multicore.interfaces.ICommand; import org.puremvc.as3.multicore.interfaces.INotification; import org.puremvc.as3.multicore.patterns.command.AsyncCommand; public class AsyncCommand0 extends AsyncCommand implements ICommand { public function AsyncCommand0() { super(); } override public function execute(notification:INotification):void{ trace("lalala AsyncCommand0"); setTimeout( commandComplete, 1000); } } }
  • 26. package controllers { import org.puremvc.as3.multicore.patterns.command.AsyncMacroCommand; public class StartupCommand extends AsyncMacroCommand { public function StartupCommand() { super(); } private function onComplete():void{ trace("end of StartupCommand"); } override protected function initializeAsyncMacroCommand():void{ setOnComplete( onComplete ); addSubCommand( AsyncCommand0 ); addSubCommand( AsyncCommand1 ); addSubCommand( AsyncCommand2 ); } } }
  • 27. AsyncCommand DEMO
  • 30. package controllers { import mx.rpc.AsyncToken; import mx.rpc.IResponder; import mx.rpc.http.HTTPService; import org.puremvc.as3.multicore.interfaces.ICommand; import org.puremvc.as3.multicore.interfaces.INotification; import org.puremvc.as3.multicore.patterns.command.AsyncCommand; public class LoadConfigCommand extends AsyncCommand implements IResponder { public function LoadConfigCommand() { super(); } override public function execute(notification:INotification):void{ var service:HTTPService = new HTTPService; service.resultFormat = 'xml'; service.url = "your configuration files url"; service.send(); } public function result( result:Object ):void{ this.commandComplete(); } public function fault( result:Object ):void{ //如果要中斷流程,需要在這邊傳出 ERROR notification 由其他 Command 處理 } }
  • 31. package controllers { import org.puremvc.as3.multicore.patterns.command.AsyncMacroCommand; public class StartupCommand extends AsyncMacroCommand { public function StartupCommand() { super(); } private function onComplete():void{ trace("end of StartupCommand"); sendNotification( "APP_INIT" ); } override protected function initializeAsyncMacroCommand():void{ this.setOnComplete( onComplete ); addSubCommand( LoadConfigCommand ); addSubCommand( LoadAssetsCommand ); addSubCommand( LoadXXXCommand ); } } }
  • 33. package com.controls { public class GroupEditorCommand extends SimpleCommand implements ICommand { public function GroupEditorCommand() { super(); } override public function execute(notification:INotification):void { switch( notification.getName() ){ case "GroupEditorCommand.INIT": //將之前開發用的 proxy notification 組織起來 facade.registerCommand( "DataProxy.ITEM_UPDATED" , GroupEditorCommand ); facade.registerCommand( "XXXProxy.NOTIFICATION_NAME" , GroupEditorCommand ); showLoader(); //看你要做什麼起始 break; case "DataProxy.ITEM_UPDATED": //看要叫 proxy 做啥,還是 call 啥畫面出來 break; } } private function clearCommands():void{ facade.removeCommand( "DataProxy.ITEM_UPDATED" ); facade.removeCommand( "XXXProxy.NOTIFICATION_NAME" ); removeLoader(); sendNotification( "GroupEditorCommand.CLOSE" ); } private function showLoader( string:String ):void{ //將檔畫面的 loader call 到前景 } private function removeLoader():void{ //remove loader } } }
  • 35. 其實你要怎樣玩它 就開心的玩吧! 想太多就什麼都寫不出來了!
  • 38. FIN
  • 39. 參考資料 • http://trac.puremvc.org/PureMVC_AS3/ • http://www.oreilly.com.tw/product_java.php?id=a163 • http://trac.puremvc.org/Utility_AS3_AsyncCommand