marrus-sh / laboratory

An API framework for interfacing with Mastodon servers
MIT License
3 stars 0 forks source link

Start shying away from EventListener for Requests #63

Closed marrus-sh closed 7 years ago

marrus-sh commented 7 years ago

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.)

marrus-sh commented 7 years ago

assign(), remove(), and go() have all been added in https://github.com/marrus-sh/laboratory/commit/258324bec1c82956bebec4f9b3f491951743a571, and the EventTarget interface has been removed.