How to convert a widget view to use ES modules?

760
3
07-14-2021 12:11 PM
ShaneBuscher1
New Contributor III

My goal is to add a new button to the Sketch widget. I'm starting with the provided sketch.tsx view code.  My Angular project is using ES modules so I need to convert all of the imports to @arcgis/core.  I've found several cases where declarations do not exist in the code sample below.

Is there an available Sketch.tsx available using ES Modules?
Is there a way around this problem?

// Example original import
import Graphic from "esri/widgets/../Graphic";
// Converted ES module import :)
import Graphic from "@arcgis/core/Graphic"

// These example imports have no ES equivalents :(
import Selector from "esri/widgets/support/Selector";
import { VNode } from "esri/widgets/support/interfaces"; 
import SketchMessages from "esri/widgets/Sketch/t9n/Sketch"
import { CreateTool } from "esri/widgets/Sketch/support/interfaces";



 

3 Replies
RyanSutcliffe
Occasional Contributor II

I've also just come across, I think, a similar problem for IdentityManager. In my case I'm trying to move a React project from using esri-loader local es imports and this was the one module that I'm not sure about. I know that it is a singleton, maybe there is a special approach for this? Will start a new thread if the answer to this is different than for authors original question.

0 Kudos
ShaneBuscher1
New Contributor III

If you are converting to ES modules this should work:

import IdentityManager from '@arcgis/core/identity/IdentityManager';

 

0 Kudos
RyanSutcliffe
Occasional Contributor II

You're right. That works. Could have sworn I tried that before and had issues with the `registerToken` method but seems to work fine now so not sure what I did. Thanks and sorry to hijack your question with this distraction.

0 Kudos