On 11/16/16, 1:52 AM, "Harbs" <harbs.li...@gmail.com> wrote:
>In my attempt to port my Adobe InDesign flash panels to FlexJS, it became >clear to me very quickly that Promises is critical for a normal flow of >code. > >I needed to convert a synchronous flow of code to an asynchronous one and >Promises is a very important piece of that. For things like network, >async file access and processes, Promises is a much better code flow than >events. > >It would be even better if we supported await and async functions, but I >think Promises is the first step towards that goal. > >There are a number of MIT licensed implementations of Promises and a port >to ActionScript should be very easy.[1] > >I would also like to change/augment HTTPService/URLLoader to return >Promises as well so we don’t need events or standard callbacks. Please create an HTTPServiceWithPromises instead. Basic components should remain basic. > >My question is how exactly it should work. Should Promise be a top level >object or org.apache.flex.utils.Promise? There is a Promise class in js.swc in the global package. If you implement a SWF side for it you should be good to go. >If we want it to work using the native browser implementation without >wrappers, it seems like it should be a top-level object. Another question >is how to handle polyfills. I.E. does not have any Promise support built >in, so a polyfill is needed for I.E. That might be a reason to wrap >Promise in a flex class and include the polyfill in the implementation. IMO, polyfills should be beads you add to your Application beads if you need them. If you don't need support on IE (if you are mobile only, for example) then why carry the polyfill around? >Another advantage of rolling our own Promises is that we can add some of >the advanced features to Promises which are in some of the >implementations. The standard browser ones have a pretty basic API.[5] You can always roll out a more sophisticated Promise class in another package. But why not have a more basic implementation that mirrors what is in most browsers? -Alex