Skip to content
This repository has been archived by the owner on Jan 12, 2018. It is now read-only.

Maintaining module names, official typings file support #10

Merged
merged 1 commit into from
Jul 2, 2016

Conversation

nickcam
Copy link
Contributor

@nickcam nickcam commented Jun 13, 2016

Added an option 'maintainModuleNames' that if set to true will register each esri module into it's own module in systemjs. This plays well with the official typings file when importing into classes.

Made the name 'default' so a default import syntax should be used. Seems to actually work across module systems that may be defined in tsconfig, ie: system, commonjs, amd...etc.

In Visual Studio using the official typings I was getting a compilation error using any type other than 'system' though. Have a feeling other IDE's may be more forgiving...haven't tested in others though.

Thanks,
Nick

… instead of registering all modules into a single systemjs module. Added maintainModuleNames option, that when set to true will use this new behaviour. This plays nicley with the official typings file for arcgis v4.
@tomwayson tomwayson self-assigned this Jun 15, 2016
@tomwayson
Copy link
Member

Thanks @nickcam!

I'll test this week w/ other IDEs with the intent to merge.

//get the module name from the url that system js thinks it's loading it from
function getName(location: string) {
let startIndex = location.lastIndexOf("esri");
if (startIndex === -1) startIndex = location.lastIndexOf("dojo");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately this probably needs to check for the other Dojo packages like 'dijit', 'dojox', etc, right? I'm still not totally clear how this works (I'll have to do some console.loging so I can see what's going on, but the main thing is, it works!

@tomwayson tomwayson merged commit fa6d08d into Esri:master Jul 2, 2016
@tomwayson
Copy link
Member

@nickcam this is awesome! I got it working in @jwasilgeo's angular2-esri-playground app by setting maintainModuleNames: true and updating all the import statements to import defaults using the full module names like so:

import Map from 'esri/Map';
import MapView from 'esri/views/MapView';

I then ran the following to get the typings:

typings install --global --save github:Esri/jsapi-resources/4.x/typescript/arcgis-js-api.d.ts

And now I have intellisense for the ArcGIS API for JavaScript, which is pretty fucking amazing

image

This works well, and is much more straightforward than registering all the modules off a single psuedo module (like esri-mods). In fact, w/ the typings support, it's hard to imagine a reason why anyone would want to do it the other way. So, I'd like this to be the default way this library behaves. I'm thinking of doing away w/ the maintainModuleNames option, and only calling registerToOutModule if the outModuleName option is passed. That would be a breaking change, so I'll release that as v1.0.0-beta.0.

Once I've done that, I'll make a PR to angular2-esri-playground that uses the new API.

@nickcam
Copy link
Contributor Author

nickcam commented Jul 2, 2016

Ok cool, glad it's working - yeah it's ridiculously helpful having intellisense isn't it!

Regarding your comment, yep you'll have to add dijit and dojox to the check for module names, not adding dojox bit me the other day until I realised what was going on :).

I think it's a good idea to make it the default behavior as well, just seems a little more standard.

@jwasilgeo
Copy link
Contributor

Wow. This is awesome!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants