Skip to content

Instantly share code, notes, and snippets.

@joelhooks
Created December 30, 2011 01:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelhooks/1537177 to your computer and use it in GitHub Desktop.
Save joelhooks/1537177 to your computer and use it in GitHub Desktop.
Robotlegs 2: Flickr Image Gallery Snippets
package robotlegs.bender.demos.imagegallery.base
{
import flash.events.Event;
import flash.events.IEventDispatcher;
/**
* Provides some common functionality for basic application classes (models and services)
*/
public class BaseActor
{
[Inject]
public var eventDispatcher:IEventDispatcher;
protected function dispatch(e:Event):void
{
if(eventDispatcher.hasEventListener(e.type))
eventDispatcher.dispatchEvent(e);
}
}
}
package robotlegs.bender.bundles.classic
{
import robotlegs.bender.bundles.shared.configs.ContextViewListenerConfig;
import robotlegs.bender.core.api.ContextLogLevel;
import robotlegs.bender.core.api.IContextBuilder;
import robotlegs.bender.core.api.IContextBuilderBundle;
import robotlegs.bender.extensions.autoDestroy.AutoDestroyExtension;
import robotlegs.bender.extensions.commandMap.CommandMapExtension;
import robotlegs.bender.extensions.eventCommandMap.EventCommandMapExtension;
import robotlegs.bender.extensions.logging.impl.TraceLogTarget;
import robotlegs.bender.extensions.mediatorMap.MediatorMapExtension;
import robotlegs.bender.extensions.modularity.ModularityExtension;
import robotlegs.bender.extensions.viewManager.ViewManagerExtension;
public class ClassicRobotlegsBundle implements IContextBuilderBundle
{
public function install(builder:IContextBuilder):void
{
// Use a simple trace logger
builder.withLogTarget(new TraceLogTarget(ContextLogLevel.DEBUG));
// Install the Modularity extension
builder.withExtension(ModularityExtension);
// Install the CommandMap extension
builder.withExtension(CommandMapExtension);
// Install the EventCommandMap extension
builder.withExtension(EventCommandMapExtension);
// Install the DisplayList extension
// and add the contextView to the ViewManager
builder
.withExtension(ViewManagerExtension)
.withConfig(ContextViewListenerConfig);
// Install the MediatorMap extension
builder.withExtension(MediatorMapExtension);
// Destroy the context when the contextView leaves the stage
builder.withExtension(AutoDestroyExtension);
}
}
}
public class FlickrImageService extends BaseActor implements IGalleryImageService
{
private var service:FlickrService;
private var photos:Photos;
package robotlegs.bender.demos.imagegallery
{
import robotlegs.bender.bundles.classic.ClassicRobotlegsBundle;
import robotlegs.bender.core.api.IContextBuilder;
import robotlegs.bender.core.api.IContextBuilderBundle;
public class GalleryAppBundle implements IContextBuilderBundle
{
public function install(builder:IContextBuilder):void
{
builder
.withBundle(ClassicRobotlegsBundle)
.withConfig(GalleryAppConfig);
}
}
}
package robotlegs.bender.demos.imagegallery
{
import flash.display.DisplayObjectContainer;
import org.swiftsuspenders.Injector;
import robotlegs.bender.core.api.*;
import robotlegs.bender.demos.imagegallery.controller.*;
import robotlegs.bender.demos.imagegallery.view.events.*;
import robotlegs.bender.demos.imagegallery.model.GalleryModel;
import robotlegs.bender.demos.imagegallery.service.*;
import robotlegs.bender.demos.imagegallery.view.*;
import robotlegs.bender.demos.imagegallery.view.api.*;
import robotlegs.bender.extensions.eventCommandMap.api.IEventCommandMap;
import robotlegs.bender.extensions.mediatorMap.api.IMediatorMap;
public class GalleryAppConfig implements IContextConfig
{
[Inject]
public var mediatorMap:IMediatorMap;
[Inject]
public var commandMap:IEventCommandMap;
[Inject]
public var contextView:DisplayObjectContainer;
[Inject]
public var injector:Injector;
public function configure(context:IContext):void
{
mediatorMap.map(IGalleryView).toMediator(GalleryViewMediator);
mediatorMap.map(IGallerySearch).toMediator(GallerySearchMediator);
mediatorMap.map(IGalleryLabel).toMediator(GalleryLabelMediator);
injector.map(GalleryModel).asSingleton();
injector.map(IGalleryImageService).toSingleton(FlickrImageService);
commandMap.map(GalleryEvent.GALLERY_LOADED, GalleryEvent).toCommand(UpdateGalleryCommand);
commandMap.map(GalleryImageEvent.SELECT_GALLERY_IMAGE, GalleryImageEvent).toCommand(SetSelectedImageCommand);
commandMap.map(GalleryEvent.LOAD_GALLERY, GalleryEvent).toCommand(LoadGalleryCommand);
commandMap.map(GallerySearchEvent.SEARCH, GallerySearchEvent).toCommand(LoadSearchGalleryCommand);
}
}
}
public class GalleryLabelMediator extends Mediator
{
[Inject]
public var galleryLabel:IGalleryLabel;
[Inject]
public var service:IGalleryImageService;
override public function initialize():void
{
setLabelText("interestingness");
addContextListener( GallerySearchEvent.SEARCH, handleSearch, GallerySearchEvent );
galleryLabel.visible = galleryLabel.includeInLayout = service.searchAvailable;
}
<fx:Declarations>
<rl:ContextBuilder>
<imagegallery:GalleryAppBundle/>
</rl:ContextBuilder>
</fx:Declarations>
<components:GalleryHeader/>
<view:GallerySearch id="search"
width="100%"
visible="false"
includeInLayout="false"/>
<view:GalleryView id="gallery"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment