Closed darscan closed 11 years ago
A reasonable approach for solving the issues re: dependency on the Flex SDK.
(Major kudos for including unit tests.)
I still like the simplicity and readability of when() being able to transparently provide that adaptation when necessary.
In context:
Promise.when( service.getUser( userId ) ).then( ... );
just feels like it reads better than:
AsyncTokenAdapter.adapt( service.getUser( userId ) ).then( ... );
I'm drawn to your adapter interface suggestion, especially if we could maintain API compatibility. I'm imagining a scenario where adapters are registered such that when() can later internally identify and use the appropriate adapter. However, I'm not sure there would be many (any?) other adapters that would ever be written. Maybe that would be overengineering it...
Pondering this one.
I'm imagining a scenario where adapters are registered such that when() can later internally identify and use the appropriate adapter.
Heh, that's what this patch actually does :) It's used like this:
// In one of your application configuration files somewhere you do this once:
Promise.registerAdapter(AsyncTokenAdapter);
// And from then on you'd use Promise.when as normal:
Promise.when( service.getUser( userId ) ).then( ... );
You can register multiple adapters - the first one to return a promise is used. And you can unregister them later if need be (when unit testing, for example).
I switched the adapter strategy to use a simple function reference. This allows one to create an adapter preloaded with configuration, for example:
var adapter:CrazyAdapter = new CrazyAdapter(some, weird, args);
Promise.registerAdapter(adapter.adapt);
I also update the docs to make usage a little clearer (hopefully!).
Thanks very much, I'm really pleased to see this improvement.
On my initial review I somehow missed your changes to the Promise class to implement the registrable adapter approach. Excellent work - I should have known, given your reputation. I really like your solution.
Thanks again!
One approach to solving: #9 ( https://github.com/CodeCatalyst/promise-as3/issues/9 ).
Removes
import mx.rpc.AsyncToken
from core Promise class.This is just one approach - you could create an "adapter" interface etc, etc, but I think this is a decent, simple solution.