Select to view content in your preferred language

reactiveUtils ESM import problem

136
0
11-28-2024 06:52 AM
majae
by
New Contributor

Hello! I have encountered a problem using reactiveUtils | API Reference | ArcGIS Maps SDK for JavaScript 4.31 | Esri Developer. The setup i have is a small test server which consumes a webcomponent. The webcomponent uses the @ArcGIS/core NPM package. The problem is that i can't get the reactiveUtil to work as expected. Im trying to use the watch function in the reactiveUtils module. It initially runs the provided getValue function once but not later when the value is updated.

I have created a test example where i provide a reactiveUtils instance to the webcomponent from the test server, this reactiveUtils being imported using the AMD method. This instance of reactiveUtils works as expected.

This is the ESM import

 

 

import * as reactiveUtils from "@arcgis/core/core/reactiveUtils.js"

 

 

 

And this is the test erver with the AMD import

 

 

require(["esri/core/reactiveUtils"], (reactiveUtils) => {
    const myWebComponent = new MyWebComponent();
    myWebComponent.ru = reactiveUtils;
}

 

 

 

I the use both of these instances in the webcomponent as follows

 

this.ru.watch(()=> {
   console.log("watching AMD", this.selectionLayer.graphics.length)
   return this.selectionLayer.graphics.length
}, () => console.log('Graphics changed! AMD'));

reactiveUtils.watch(()=> {
   console.log("watching ESM", this.selectionLayer.graphics.length)
   return this.selectionLayer.graphics.length
}, () => console.log('Graphics changed! ESM'));

 

 

Then in the browser we expect the console to log initally both "watching AMD" and "watching ESM" which it does 😀

majae_0-1732805403726.png

Then when we add a graphic to the 'selectionLayer' we expect the console to log "watching AMD", 'Graphics changed! AMD',"watching ESM" and 'Graphics changed! ESM' however only the reactiveUtils from the ESM import runs 😭

majae_1-1732805445540.png

Does anyone have any idea what the issue may be? As i wrote it doesn't have any issue finding and running the file at @ArcGIS/core/core/reactiveUtils.js but the functionality does not work.

Have tried with @ArcGIS/core versions 4.27.6 and 4.31.6

Thanks in advance, Maja

 

0 Kudos
0 Replies