PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: ejot on July 09, 2009, 08:09:27



Title: Lazy proxy?
Post by: ejot on July 09, 2009, 08:09:27
My concern here is to create a proxy that has lazy fetching of remote objects... something like:

:
// In some Proxy or Mediator

myLazyProxy.fetchObject("Foo");

// And in LazyProxy

public function fetchObject(key:String):ValueObject {
if(myValueObjectMap.get(key) == null) {
var result:ValueObject = LazyMagic.get("http://domain.fake/objects?id=" + key);
myValueObjectMap.set(key, result);
}

return myValueObjectMap.get(key);
}

What kind of magic does LazyMagic need? :) Or what approach should I have here? I really want to keep the signature of fetchObject to a single parameter to I dont think it's possible. Should I perhaps pass in a function reference as the second parameter, which takes a single parameter (my ValueObject instance)?


Title: Re: Lazy proxy?
Post by: puremvc on July 09, 2009, 12:25:43
The kind of magic you need depends on your definition of 'lazy'. The mediator has asked for the asset. Why don't you make the call right then?

Are you trying to build a list of items before beginning to make calls? The call is async, so making it doesn't block you.

Are you wanting to make sure you don't already have the object? if so, the proxy could just see if it has the object and send a note out with it if it does, or make the call if not.

Also, passing a function reference to a proxy for callback isn't really what you want to do. Invoke a method and expect an immediate return if there is a return type for the method, or if not, expect a notification to come back later, and be interested in that.

-=Cliff>