CC-Archived / promise-as3

Promises/A+ compliant implementation in ActionScript 3.0
167 stars 52 forks source link

This library requires Flex #9

Open thegoldenmule opened 12 years ago

thegoldenmule commented 12 years ago

promise-as3 is a misleading title for this project. Perhaps promise-flex is better? This library requires the Flex framework which a large number of projects do not use do to its massive overhead. Flex is not required for this project, why is it a dependency?

ThomasBurleson commented 12 years ago

@thegoldenmule The Promise::watch() method provides support to watch an mx.rpc.AsyncToken. So the Flex framework is used only for that feature. It could be easily disabled and then Flex would no longer be a requirement.

thegoldenmule commented 12 years ago

That's not quite true. The [Bindable] metadata tag requires the Flex framework.

pmowrer commented 12 years ago

[Bindable] metadata is only relevant to Flex, but its presence shouldn't prevent you from compiling without Flex. The AS3 compiler will just throw out any metadata dags it doesn't recognize.

I'm using promise-as3 in an AS3-only project just fine, without any modifications.

thegoldenmule commented 12 years ago

My concerns still remain--this library requires Flex, plain and simple. When I try to compile without linking to Flex, it chokes on both the Bindable tags and mx.rpc.AsynchToken.

ThomasBurleson commented 12 years ago

@thegoldenmule [Bindable] is an absolutely required metadata tag for this library. I believe there is a way to compile AS3-only code and retain the [Bindable] by using the mxml compiler... we just have not done that yet!

pmowrer commented 12 years ago

@thegoldenmule

What AS3 compiler are you using that "chokes" on [Bindable]? AFAIK, you should be able declare any metadata tag you like.

ThomasBurleson commented 12 years ago

@Patrick, Please note that the mxml compiler will scan [Bindable] metadata tags and actually generate source code with getter/setter functions and databinding watchers. This is critical... as just preserving [Bindable] metadata is not sufficient.

pmowrer commented 12 years ago

@ThomasBurleson What I'm saying is that an AS3 compiler should be able to compile code containing any metadata notation without a fuss. Adding [Bindable] metadata to your code doesn't make it dependent on Flex. It merely instructs the Flex compiler to do extra work (as you pointed out) whereas a regular AS3 compiler (such as Flash Pro's) just ignores it.

thegoldenmule commented 12 years ago

The [Bindable] metatag requires mx.binding.BindingManager.

pmowrer commented 12 years ago

@thegoldenmule My understanding is that metadata is just annotation, nothing else. You could put anything you want inside of metadata brackets and compile it. From an AS3 language standpoint, no dependencies are ever implied by metadata.

However, the compiler you're using may interpret the metadata and perform work. This is what the Flex compiler does, generating code that, among other things, requires mx.binding.BindingManager. An AS3-only compiler won't do this; it's not programmed to interpret [Bindable]. It sounds like you're trying to compile using the Flex (MXMLC) compiler but without linking in Flex libraries. That would cause an error, but that doesn't mean promise-as3 is dependent on Flex. Try using a different compiler.

You can still use the MXMLC compiler to compile this project and use it with an AS3-only project. Typically, the Flex framework is linked in as an external dependency, which means it won't add very much to the SWC size, except for the generated code for binding support. The SWC I've generated this way is about 14kb -- tiny. This SWC will not require the Flex framework to be used within an AS3-only project.

makc commented 12 years ago

Try using a different compiler.

What other compilers are there? Flash CS?

pmowrer commented 11 years ago

There's the Flash CS compiler, the new ASC 2.0, Haxe and possibly others. I'm not suggesting MXMLC isn't fine, it was just for the sake of the argument. Point is, if you're already using MXMLC to compile your AS3 code, you can use this library as-is.

The single dependency from the Flex framework, mx.rpc.AsyncToken, will be compiled in from the framework source, but will have a very small impact on the file size.

johnyanarella commented 11 years ago

The [Bindable] metadata is no longer used following the Promises/A+ compliant rewrite. (See #2.)

Promise.when() does still reference mx.rpc.AsyncToken, but this can be easily commented out when unavailable.

johnyanarella commented 11 years ago

We could potentially compare the qualified class name against the String "mx.rpc.AsyncToken" in order to avoid the import and explicit class reference, but I think that would have negative performance implications.

The other option that comes to mind would be conditional compilation, but I think only MXMLC supports that.

pmowrer commented 11 years ago

COMPC also supports conditional compilation. I think that works well to solve this issue. See my commit above.

darscan commented 11 years ago

I don't believe that conditional compilation is the best solution here - it forces those compilation arguments onto any project that chooses to use this library.

Instead I'd prefer an opt-in (plugin) approach. I'll see what I can come up with.

johnyanarella commented 11 years ago

Following @darscan's pull request, which has now been integrated, the Promise class is no longer dependent on the Adobe Flex mx.rpc.* classes.

See #12.

darscan commented 11 years ago

When compiled as a SWC (speaking of which, this library probably needs an Ant build script.. and versioning), this change should allow the library to be used in plain AS3 projects without pulling in Flex. As such, this issue can probably be closed.

johnyanarella commented 11 years ago

This issue is still open for now, as I'd like to restructure the project similarly to hamcrest-as3 and linkify-as3. This would include:

I welcome pull requests on any of these.

fwienber commented 10 years ago

I'd like to support this idea. I am evaluating Promise-AS3 to be used with Jangaroo, a compiler from AS3 to JavaScript. Since your recent rewrite, everything seems to work fine if I leave out mx.rpc.AsyncToken. So it would also simplify our build process if you separated sources with Flex dependencies!