Skip to content

Commit

Permalink
buggy... but got stock quotes working the same??/
Browse files Browse the repository at this point in the history
  • Loading branch information
seanhess committed Apr 30, 2009
1 parent 06d8a2a commit af88220
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 59 deletions.
7 changes: 7 additions & 0 deletions examples/GlueLoginExample/src/login/control/Authentication.as
Expand Up @@ -28,6 +28,7 @@ package login.control
{
var respond:Respond = new Respond(loginService, attempt);
respond.result(onLogin);
respond.fault(onFault);

attempt.waiting = true;

Expand Down Expand Up @@ -66,5 +67,11 @@ package login.control
app.currentUser = null;
nav.loggedOut();
}

private function onFault(event:Event):void
{
throw new Error("FAULT " + event);
}

}
}
Binary file added examples/StockQuote/libs/Glue.swc
Binary file not shown.
Binary file removed examples/StockQuote/libs/Glue0.3.a.swc
Binary file not shown.
38 changes: 38 additions & 0 deletions examples/StockQuote/src/stocks/control/Quotes.as
@@ -0,0 +1,38 @@
package stocks.control
{
import flash.events.Event;

import mx.rpc.events.ResultEvent;

import net.seanhess.glue.Respond;

import stocks.model.Quote;
import stocks.service.IQuoteService;
import stocks.service.QuoteServiceParser;

public class Quotes
{
public var quoteService:IQuoteService;
public var parser:QuoteServiceParser; // not an interface, but you could extend it to mock it

public function getQuote(quote:Quote):void
{
var respond:Respond = new Respond(quoteService, quote);
respond.result(onResult);
respond.fault(onFault);

quoteService.getQuote(quote.symbol);
}

private function onResult(event:ResultEvent, respond:Respond):void
{
var quote:Quote = respond.data as Quote;
quote.price = parser.getPrice(event.result);
}

private function onFault(event:Event):void
{
trace("There was an error");
}
}
}
41 changes: 0 additions & 41 deletions examples/StockQuote/src/stocks/control/Quotes.mxml

This file was deleted.

3 changes: 2 additions & 1 deletion examples/StockQuote/src/stocks/glue/MainGlue.mxml
Expand Up @@ -5,9 +5,10 @@
<!-- SERVICE -->
<service:QuoteService id="quoteService"/>
<service:RandomQuoteService id="randomQuoteService"/>
<service:QuoteServiceParser id="quoteParser"/>

<!-- CONTROL -->
<control:Quotes id="quotes" quoteService="{quoteService}"/>
<control:Quotes id="quotes" quoteService="{quoteService}" parser="{quoteParser}"/>

<!-- VIEW -->
<Glue>
Expand Down
30 changes: 13 additions & 17 deletions source/src/net/seanhess/glue/Respond.as
Expand Up @@ -6,20 +6,14 @@ package net.seanhess.glue

import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;

/**
* Figure out how to get it to use a responder too.
*
* I need to figure out how to clean this up...
*
*
*/

public class Respond
{
public var service:IEventDispatcher;
public var data:*;
public var handlers:Dictionary;
public var autoClean:Boolean = true;
public var uid:String = Math.random().toString();

public function Respond(service:IEventDispatcher, data:*=null, autoClean:Boolean = true)
{
Expand All @@ -31,7 +25,7 @@ package net.seanhess.glue

public function listen(type:String, handler:Function):void
{
service.addEventListener(type, callback);
service.addEventListener(type, this.callback);
handlers[type] = handler;
}

Expand All @@ -48,8 +42,7 @@ package net.seanhess.glue
protected function callback(event:Event):void
{
var handler:Function = handlers[event.type];
remove(event.type);


try
{
handler(event, this);
Expand All @@ -69,22 +62,25 @@ package net.seanhess.glue

if (autoClean)
clean();

else
remove(event.type);
}

public function clean():void
{
{
for (var type:String in handlers)
remove(type);

service = null;
data = null;
handlers = null;
}

public function remove(type:String):void
{
var handler:Function = handlers[type];

if (handler != null)
service.removeEventListener(type, callback);

delete handlers[type];
service.removeEventListener(type, this.callback);
}

}
Expand Down

0 comments on commit af88220

Please sign in to comment.