cairngorm commands deal with lots of things
程序员文章站
2022-04-30 09:25:58
...
Yeah.
As the best practice says: the command and event should be One-To-One in cairngorm . If doing so, we would have lots of command and event files.
So here is my way in solving the problem, see codes below.
[b]PhotoEvent.as[/b] has two event types.
[b]PhotoCommand.as[/b] deal with PhotoEvent; PhotoServiceDelegate.as contains HTTPService Call.
My Question is : the way I hold [color=red]PhotoEvent[/color] and reuse it in result function is right ?
is there any advice ?
As the best practice says: the command and event should be One-To-One in cairngorm . If doing so, we would have lots of command and event files.
So here is my way in solving the problem, see codes below.
[b]PhotoEvent.as[/b] has two event types.
import com.adobe.cairngorm.control.CairngormEvent;
import com.babytree.photoUpload.control.MainController;
public class PhotoEvent extends CairngormEvent
{
public function PhotoEvent (type:String)
{
super(type);
}
//get all albums of a user
public static const GET_ALBUMSLIST:String = "get_albumslist";
//get all photos of an album
public static const GET_ALBUMPHOTOS:String = "get_albumphotos";
}
[b]PhotoCommand.as[/b] deal with PhotoEvent; PhotoServiceDelegate.as contains HTTPService Call.
public class PhotoCommand implements ICommand,IResponder
{
private var model : ModelLocator = ModelLocator.getInstance();
private var photoServiceDelegate:PhotoServiceDelegate;
private var photoEvent:PhotoEvent;
// functions ============================
public function execute( event:CairngormEvent ) : void
{
photoEvent = event as PhotoEvent;
photoServiceDelegate = new PhotoServiceDelegat(this as IResponder);
switch(photoEvent.type){
case PhotoEvent.GET_ALBUMSLIST:
photoServiceDelegate.getUserAlbums(model.userVO);
break;
case PhotoEvent.GET_ALBUMPHOTOS:
photoServiceDelegate.getAlbumPhotos(model.userVO);
break;
}
}
public function result( data:Object ) : void
{
switch(photoEvent.type){
case PhotoEvent.GET_ALBUMSLIST:
//do something
break;
case PhotoEvent.GET_ALBUMPHOTOS:
//do something
break;
}
}
public function fault( info : Object ) : void
{
trace("fault in PhotoCommand.as ==== Event.type is ===" + photoEvent.type);
}
}
My Question is : the way I hold [color=red]PhotoEvent[/color] and reuse it in result function is right ?
is there any advice ?