[Request] externs.js for plugins

For developers using the Construct 2 Javascript SDK

Post » Tue Jan 06, 2015 6:36 pm

One of the things that most often go wrong is that the Closure Compiler trashes your code at export with minify.
After this hard lesson you start writing everything with literals like MyExternalLib["activateAFunctionButMisplelled"] and it still will not work, but you don't notice that and spent some quality time debugging.

But there is a solution that is already used for C2 standard plugins and that is to use a externs.js file. So this is something I would like for 3pp plugins as well.

With that I can fully use both code completion and JSHint/JSLint type syntax checkers. If you are doing a large and complex plugin that is really an advantage.

I have gone from using Notepad++ to Brackets and now WebStorm and finally it's easy to write javascript again. WebStorm will index C2s all system files and give you code completion for everything. Well almost everything, the edittime.js needs special handling so I did a "library" for that here: https://www.frostyelk.se/development/edittimeLib.zip
B
18
S
7
Posts: 88
Reputation: 1,424

Post » Thu Feb 05, 2015 8:03 pm

I forgot to make the request to @Ashley, he is of course the only one to make improvements in this area :)
B
18
S
7
Posts: 88
Reputation: 1,424

Post » Thu Feb 05, 2015 8:18 pm

I find the choice to force advanced optimizations as the only minify option is a poor one. It makes using a plugin with external libraries and minify pretty much impossible / a huge pain. It'd be nice to have a less vicious minify option.
B
79
S
13
G
8
Posts: 1,977
Reputation: 9,947

Post » Fri Feb 06, 2015 2:19 pm

You don't really need an externs.js file. Just use obj["prop"] syntax for anything from external scripts.

Note if you use something like externalLib["someFunc"], then 'externalLib' is not using the ["prop"] syntax so will be renamed and broken by the minifier. Solution: just use window["externalLib"]["someFunc"].
Scirra Founder
B
403
S
238
G
89
Posts: 24,648
Reputation: 196,133

Post » Sat Feb 07, 2015 11:03 am

Sorry @Ashley for being unclear and jumping to solutions before making the requirements clear. What I want has nothing to do with extern.js but I saw it as a possible solution to my needs.

What I want is:
* Code completion in Webstorm when using external libraries in a plugin.

As code completion is built on "dot" syntax it doesn't work when using literals. Another thing is that JSLint/JSHint complains about this, minor issue but I couldn't get Bracket to work after their last update.

Any suggestions?
B
18
S
7
Posts: 88
Reputation: 1,424

Post » Sat Feb 07, 2015 1:53 pm

Aren't those feature requests for the tools you're using?
Scirra Founder
B
403
S
238
G
89
Posts: 24,648
Reputation: 196,133

Post » Mon Feb 09, 2015 2:34 am

@Arne

You might place these could outside of runtime.js, so that they will not be minify.
B
110
S
28
G
280
Posts: 4,488
Reputation: 156,568

Post » Mon Feb 09, 2015 8:54 pm

I want the code to be minified but I want to use "dot"-code completion also. Now I have code that looks like this:
Code: Select all
var queryClass = Parse["Object"]["extend"](qClass);
queryObject = new Parse["Query"](queryClass);

It looks horrible, fails JSHint/JSLint, is error prone, does not support code completion or JSDoc type documentation. Just plain bad!

To test how good it can be, I did my own edittime.js lib with documentation and code completion support and get this when I point to AddCondition i WebStorm:
Image
B
18
S
7
Posts: 88
Reputation: 1,424

Post » Thu Feb 12, 2015 9:39 pm

The c2 sdk is pretty limited, id imagine stuff like this would be part of c3. There are a lot of choices in the c2 plugin system that could be vastly improved. Obe major issue is plugins cant share a common ACE, so you end up having to do nasty workarounds. Theres a lot of features i wish the sdk had that would make advanced plugins easier to maintain. I feel the current sdk was designed with the expectation that the plugins wouldnt become very elaborate, or try to augment c2 in a meaningful way, and thus only needed the bare minimum in terms of inheritance and eddittime data management.

As things stand its impossible to make plugins that require preprocessing without nasty hacks and workarounds. Another issue is that the edittime only has access to textures, so if you need to import some proprietary format, or some kind of file and display that data in the editor you just wont be able to. The data interface is severely lacking aswell, and doesnt allow any kind of interaction. Theres a lot of issues that c3 should address like this. I love construct but i feel the closed off edittime like this is a huge detriment to its growth.
B
79
S
13
G
8
Posts: 1,977
Reputation: 9,947


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 0 guests