Watch for changes in components using reactiveUtils

This sample demonstrates how to watch for changes in components using reactiveUtils to observe property and state changes. Updates are shown in the message panel as they occur. Use reactiveUtils when you need control over property changes, especially for continuous observation or reacting to specific value updates.

If you want to respond to higher-level component behavior like when a component is ready or react to interactions, see watch for changes with components, which uses lifecycle methods and custom events.

Import reactiveUtils

Once the map components are defined, import reactiveUtils at the start of your script.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      const reactiveUtils = await $arcgis.import("@arcgis/core/core/reactiveUtils.js");

Wait for the component to be ready

Before using the reactiveUtils, wait for the component to be fully loaded.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      await mapElement.viewOnReady();

Use reactiveUtils.watch() to observe mapElement.ready. When the value is true, the element is fully initialized and you can safely start reacting to other property changes.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      reactiveUtils.watch(
        () => mapElement.ready,
        (isComponentReady) => {
          state.ready = isComponentReady;
          renderState();
        },
        { initial: true }
      );

Watch component's property changes

With the component fully initialized, live map interaction can be tracked. Use reactiveUtils.watch() to observe several properties at once by returning them as an array from the getValue function. The callback runs whenever any of those values change.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      reactiveUtils.watch(
        () => [mapElement.zoom, mapElement.scale, mapElement.stationary],
        ([zoomLevel, scaleValue, isStationary]) => {
          state.zoom = zoomLevel;
          state.scale = Math.round(scaleValue);
          state.stationary = isStationary;
          renderState();
        },
        { initial: true }
      );

The mapElement.basemap?.title property is also observed so that any time the user selects a new basemap in the gallery, the updated title is pushed to the shared state and displayed in the messages panel.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
      reactiveUtils.watch(
        () => mapElement.basemap?.title,
        (basemapTitle) => {
          state.basemap = basemapTitle;
          renderState();
        },
        { initial: true }
      );

For more information, see the Observing property changes with reactiveUtils guide topic.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.