Since the event type on Requests is always "response" (or, I guess, "failure"), another model would probably be simpler—and then instead of event.detail.response we would just feed detail directly lol.
Obviously this is well-suited to the Promises model (see https://github.com/marrus-sh/laboratory/issues/49), but since we're targeting ECMAScript 5 we can't depend on that; furthermore, dynamic adding/removing of callbacks is a plus.
So I'm thinking:
request = new Request; // -> request
request.assign(callback); // -> request
request.remove(callback); // -> request
request.start(); // -> new Promise or void
request.stop(); // -> void
Alternatively, we could introduce a new method on top of start() that produces a Promise if that's easier implementation-wise; for example, go(). (This way a Promise is only created if you're going to be using it.)
Since the event type on
Request
s is always"response"
(or, I guess,"failure"
), another model would probably be simpler—and then instead ofevent.detail.response
we would just feeddetail
directly lol.Obviously this is well-suited to the
Promise
s model (see https://github.com/marrus-sh/laboratory/issues/49), but since we're targeting ECMAScript 5 we can't depend on that; furthermore, dynamic adding/removing of callbacks is a plus.So I'm thinking:
Alternatively, we could introduce a new method on top of
start()
that produces aPromise
if that's easier implementation-wise; for example,go()
. (This way aPromise
is only created if you're going to be using it.)