Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

buggy... but got stock quotes working the same??/

  • Loading branch information...
commit af88220191d2eb33048b67d1d832db516b884c5e 1 parent 06d8a2a
@seanhess authored
View
7 examples/GlueLoginExample/src/login/control/Authentication.as
@@ -28,6 +28,7 @@ package login.control
{
var respond:Respond = new Respond(loginService, attempt);
respond.result(onLogin);
+ respond.fault(onFault);
attempt.waiting = true;
@@ -66,5 +67,11 @@ package login.control
app.currentUser = null;
nav.loggedOut();
}
+
+ private function onFault(event:Event):void
+ {
+ throw new Error("FAULT " + event);
+ }
+
}
}
View
BIN  examples/StockQuote/libs/Glue.swc
Binary file not shown
View
BIN  examples/StockQuote/libs/Glue0.3.a.swc
Binary file not shown
View
38 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");
+ }
+ }
+}
View
41 examples/StockQuote/src/stocks/control/Quotes.mxml
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<fx:Object xmlns:fx="http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/halo" xmlns:business="com.asfusion.mate.stockQuoteExample.business.*" xmlns:service="stocks.service.*" xmlns:glue="http://glue.seanhess.net/2009">
-
- <fx:Declarations>
- <glue:Respond id="respondQuote" result="onResult(event.source)" fault="onFault(event)"/>
- </fx:Declarations>
-
- <fx:Script>
- <![CDATA[
- import stocks.service.IQuoteService;
- import stocks.service.QuoteServiceParser;
- import mx.rpc.AbstractOperation;
- import mx.controls.Alert;
- import mx.rpc.events.ResultEvent;
- import stocks.model.Quote;
-
- [Bindable]
- private var quote:Quote;
-
- 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
- {
- this.quote = quote;
- respondQuote.start(quoteService);
- quoteService.getQuote(quote.symbol);
- }
-
- private function onResult(event:ResultEvent):void
- {
- quote.price = parser.getPrice(event.result);
- }
-
- private function onFault(event:Event):void
- {
- Alert.show("There was an error");
- }
- ]]>
- </fx:Script>
-</fx:Object>
View
3  examples/StockQuote/src/stocks/glue/MainGlue.mxml
@@ -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>
View
30 source/src/net/seanhess/glue/Respond.as
@@ -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)
{
@@ -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;
}
@@ -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);
@@ -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);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.