Flowtype libdefs -- How to export a class definition from one module and extend it in another? - flowtype

The project I'm working on uses some 3rd-party libraries in which a main module defines classes that are imported and extended by other, associated modules. In my case the main module is three.js, a JavaScript 3D computer graphics library, and the other modules are extensions that extend the features of the main module. These superclasses are an important part of the interface to the extensions, and I would like to include their contribution. Flow has been a great tool for typechecking the rest of the project, but I haven't been able to describe this particular situation well.
I've played with the existing three.js libdef and looked through several others for ideas, without luck. You can certainly declare/export a class in one module and import its type into another, but while that can be used to describe function parameters and such, you can't define a class that extends the imported type: flow complains that it "Cannot reference type ... [1] from a value position. [type-as-value]". I tried using the Class utility type, but that doesn't seem to be available in a libdef: using it causes a "Cannot resolve name Class. [cannot-resolve-name]" error. Am I missing something obvious here? Perhaps there's an well-known workaround?
Thanks in advance for any suggestions.

Related

Is it possible to export/import Flow types in Node?

What is the correct syntax to export a type definition from a module in Node, and be able to use it?
The Flow modules types documentation describes how to export/import types if you are using ES6 modules, but that doesn't work with Node, which uses exports and require().
You can still use import type ... and export type ... in CommonJS files. They are already custom things added for Flow, they just resemble ES6 module syntax. Since they are all erased by the time the code actually runs, there is no problem.

Trying to use a TreeMap in a subclass entitiy

I have found help for subclassing of a mapped superclass, and I have found help on how to map a TreeMap. However, I can not find anything that covers using a TreeMap in a subclass at all. Here is the situation: I am adding a function to a long-existing application. That application has mapped entities, a certain set of which, form a hierarchy. There is a , for instance that establishes the base class. Then there are many many MANY subclasses that use the elements to map the individual subclasses. The subclasses all use elements to reference the additional table that holds the attributes of the subclass. This has worked for several years and life has seemingly been good.
Now along comes my work effort and I need to use a TreeMap in my new subclass entity (extending the same base class as all of the others) so the first thing that I do is attempt to map it the same way other subclasses do, with a inside a .
Making the story short, I got an error when I started the app and Hibernate began mapping. Researching this error led me to review the DTD for hibernate mapping files and, guess what? According to my interpretation, one can not configure a Map of any kind inside a .
That same research exposed me to the which CAN contain a Map. So, off I go configuring a inside the base class mapping.
When I did this, I got bizarre errors referencing symbols that I can't even find in the code, in mappings.... anywhere! More research and I find a reference in the Hibernate reference manual, Chapter 9, that says that Hibernate does not support mixing of and elements. So that can't be done either.
My question is: is there a solution that I have missed along the way? From the sound of things it seems that you can NOT configure a map in a subclass if you are using because the inside it won't take a map.... and, while a Map can be configured in a , I doubt that I can gather up much support around here for wading through the current mapping files and re-mapping ALL entities as entities.
Has anybody got any ideas? If I am not looking at this right, believe me, I am willing to accept that and learn!

Build JAR file with only recursivly dependant classes from main class

is there a simple way to generate a JAR file, that contains only the classes that depend transitive from a certain "main" class (reflection omitted of course).
I want to provide a little part of my application to someone else but do not want to export the whole application.
Thanks,
M.
Probably the easiest approach is using a tool like yGuard which "...provides elaborate code shrinking functionality through dependency analysis." This would also solve the same problem where you give it an entry point, and it performs dependency analysis to work out which classes can be excluded from the Jar.
However, I have throught about this problem myself a few times and fancied having a go at it myself for the challenge. All it would take would be to parse the import statements of Java source files and build a dependncy graph of how the classes interact with each other. Each reference from the main class should be recursively scanned until a complete graph is assembled. Then once the graph is assembled it would be a case of outputting this in a way that some packaging logic could process (or if you are feeling daring, the JDK has its own built in Jar creating/modifying code to do it yourself). Granted, this approach would require writing this custom utility and would also miss fully qualified class references in the code.

How can I best convert an AS1/AS2 application to an ActionScript3 application?

I have a program consisting of multiple SWF's. An AS2-SWF loads a bunch of AS1-SWFs.
It's a crappy program. I'd like to specify the GUI in MXML and perhaps refactor some code to AS3. However, converting all of the 300+ symbols to AS3 or whatever is undoable.
What are my options in converting to AS3/Flex/MXML? The app is very simple, only also quite large. It consists only of buttons, backgrounds and attention-texts. All the button texts are in XML files.
I want to turn this into pretty code ASAP but also controlled so the code becomes:
easily updateable/maintainable,
readable
learnable (so I can have the updating done by someone that can only script AS3 or even MXML).
Of course doing this is on my own initiative, if it'll take more than a week, I won't be able to find the time.
Regards, Jurgen
This might help:
http://flexman.info/2009/03/29/as3converter-an-ant-task-small-collection-of-as3/
It's mainly for AS2 code, so FLA editing is out of the question. But you should certainly look into JSFL.
There are some pretty good scripts out there already dealing with something like this:
http://bumpslide.com/blog/2009/03/07/jsfl-class-generator/
What this command does is that it
looks through your library and finds
all library items that have a custom
linkage class name. If the class
extends flash.display.MovieClip (or if
the base class is blank), it checks to
see if a classfile exists, and if not,
it creates it for you. When it does
this, the script looks at all the
items on the timeline and adds
relevant properties to your class. If
these clips are instances of other
components, they will be typed as
such, and relevant import statements
will automatically be added to your
class. If your component is set to
extend some other class (for instance,
com.bumpslide.ui.Button), no class
will be generated. Class files will be
written to the correct package
location inside the first custom class
path defined in your publish settings.
Jurgen, I feel for you... it sounds like a lot of work.
What sorts of issues do you have? are all the swfs treatable as different classes? is there much overlap in the logic or does each object have a specific role?
I think having so many different SWFs may possibly lead to scoping problems> which swf talks to which. you may be able to set up something with as3 that uses the existing parts and then try making a facade over the existing code > use the existing logic in the swfs and do the visual part through mxml. other than that, all I can advise is a rebuild. you might find yourself in need of a swf decompiler too if you are missing some of the original fla's

Where to put code that defines prototypes for base types in flex?

I've added functions to the Date prototype and I am wondering where is the best place to put the code in a Flex project?
The best practice for a Flex application is to create a utility class to manipulate instances of a class rather than to change the prototype of that class. For example, you might create a com.example.utils.DateUtil class with static functions that accept Date objects as arguments. The reason you want to follow this best practice is that Flex uses the compiler's strict setting by default, and trying to access non-standard functions added to the prototype of a sealed class will throw compiler errors. The alternative, turning off strict mode, is not advisable because the compiler will not be able to optimize your code as well as it could under strict mode.
Probably best to put it in a preinitialize handler for the Application - in case the prototype is used by any components as they're created.

Resources