[Arp] Passing data to commands
Darron J. Schall
darron at darronschall.com
Mon Jan 10 11:56:05 PST 2005
Aral Balkan wrote:
> First off, welcome to the list! :)
Thanks. Glad I was able to contribute something useful already.. hehe :-)
> I agree. And we can still save a reference to ViewRef so existing code
> will not be broken (unless it wasn't using the CommandTemplate and was
> expecting the old behavior from the Controller.
Yup - just for the record, the change would look like this:
// in CommandTemplate
public function execute ( event:Event )
{
trace ("INFO Command::execute");
// save view reference
this.viewRef = event.target;
this.data = event.data
// primitive operation
executeOperation();
}
// in ControllerTemplate
// in handleEvent method
remove this line "var viewRef = eventObj.target;"
replace this line:
theCommand.execute( viewRef );
with
theCommand.execute(eventObj);
Then, all of the commands will get a this.data property, and there's no
more need to ask the view for more information. For example, my
EmailErrorCommand looks like:
// snip
public function executeOperation():Void {
this.applicationDelegate = new ApplicationDelegate(this);
this.applicationDelegate.emailError(String(this.data));
}
That has a much better "feel" to it, I think.
> How about making it more flexible? Event ( type, target, arg1, arg2,
> argN )?
To be honest, I think type, target, and data is good enough. :-) What
if I needed 20 arguments.. are we really going to make a constructor
with that many arguments? It's possible to use the arguments object to
catch an indefinite number of args, but much easier I think to just dump
all the args in the data object.
-d
More information about the Arp
mailing list