robotlegs / robotlegs-framework

An ActionScript 3 application framework for Flash and Flex
https://robotlegs.tenderapp.com/
MIT License
967 stars 261 forks source link

Easy way to listen context dispatch #131

Closed hbakhtiyor closed 11 years ago

hbakhtiyor commented 11 years ago
override public function listEventInterests():Array
{
  return [FileEvent.DOWNLOADING, FileEvent.UPLOADING];
}

override public function handleEvent(event:Event):void
{
  switch(event.type)
  {
    case FileEvent.DOWNLOADING:
      // do something
      break;
    case FileEvent.UPLOADING:
      // do something
      break;
  }
}

Instead of

override public function initialize():void
{
  addContextListener(FileEvent.DOWNLOADING, _onFile_DownloadingHandler);
  addContextListener(FileEvent.UPLOADING, _onFile_UploadingHandler);
  // a lots of addContextListener 
}

Same as PureMVC event instead notification. It's just idea without unit testing. What do you think?

creynders commented 11 years ago

There's a number of problems with this approach:

  1. it creates monolithic handleEvents methods if you have lots of events.
  2. it allows for orphaned events: the event is still registered for listening, but nothing happens with it in the event handler.
  3. it can't differentiate between two different events with the same type
  4. there's asymmetry with how you listen to context events and how you listen to view events.

So no, I'm sorry, we won't consider this. And I don't quite understand how this is easier? There's a lot more boilerplate code to be written.

hbakhtiyor commented 11 years ago

Agree! I'm in PureMVC habit :laughing: Thanks

creynders commented 11 years ago

No probs! If you're new to RL you'll notice a lot of things are quite similar to PureMVC, but the main idea was to try and reduce a lot of the boilerplate code necessary to get PMVC up and running. It takes a little while to adjust.

darscan commented 11 years ago

Hi @hbakhtiyor, thanks for all the pull requests and suggestions! It's great that you're getting involved. As @creynders pointed out, there might be quite a lot that we don't use or pull in, but it's still great to have these ideas to discuss.