You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-app-configuration/enable-dynamic-configuration-javascript.md
+15-18Lines changed: 15 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ The following examples show how to use refreshable configuration values in conso
43
43
The refresh behavior is configured by `refreshOptions` parameter when calling `load` function.
44
44
The loaded configuration is updated when a change is detected on the server.
45
45
46
-
1. Open the file *app.js* and update the `load` function with `refreshOptions`specified.
46
+
1. Open the file *app.js* and update the `load` function. Add a `refreshOptions`parameter to enable the refresh and configure refresh options. By default, a refresh interval of 30 seconds is used, but you can override it with the `refreshIntervalInMs` property.
47
47
48
48
### [Use configuration as Map](#tab/configuration-map)
49
49
@@ -53,25 +53,23 @@ The loaded configuration is updated when a change is detected on the server.
53
53
// Setting up to refresh when the sentinel key is changed
54
54
refreshOptions: {
55
55
enabled:true,
56
-
watchedSettings: [{ key:"sentinel" }], // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
57
-
refreshIntervalInMs:10*1000// Default value is 30 seconds, shorted for this sample
56
+
watchedSettings: [{ key:"sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
58
57
}
59
58
});
60
59
```
61
60
62
61
### [Use configuration as object](#tab/configuration-object)
63
62
64
63
The configuration object is constructed by calling `constructConfigurationObject`function.
65
-
So you need to add a callback to ensure the object is also updated after a refresh.
64
+
To ensure an up-to-date configuration, update the configuration object in the `onRefresh` callback triggered whenever a configuration change is detected and the configuration is updated.
66
65
67
66
```javascript
68
67
// Connecting to Azure App Configuration using connection string
69
68
const settings = await load(connectionString, {
70
69
// Setting up to refresh when the sentinel key is changed
71
70
refreshOptions: {
72
71
enabled:true,
73
-
watchedSettings: [{ key:"sentinel" }], // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
74
-
refreshIntervalInMs:10*1000// Default value is 30 seconds, shorted for this sample
72
+
watchedSettings: [{ key:"sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
75
73
}
76
74
});
77
75
@@ -88,25 +86,26 @@ The loaded configuration is updated when a change is detected on the server.
88
86
89
87
1. Add the following code to poll configuration changes of watched key-values every 5 seconds.
90
88
89
+
### [Use configuration as Map](#tab/configuration-map)
90
+
91
91
```javascript
92
92
// Polling for configuration changes every 5 seconds
93
93
while (true) {
94
94
await sleepInMs(5000); // Waiting before the next refresh
95
95
await settings.refresh(); // Refreshing the configuration setting
96
+
console.log(settings.get("message")); // Consume current value of message from a Map
96
97
}
97
98
```
98
99
99
-
1. At the end of the while loop, add the following line to print the value after each refresh call.
100
-
101
-
### [Use configuration as Map](#tab/configuration-map)
102
-
103
-
```javascript
104
-
console.log(settings.get("message")); // Consume current value of message from a Map
105
-
```
106
100
### [Use configuration as object](#tab/configuration-object)
107
101
108
102
```javascript
109
-
console.log(config.message); // Consume current value of message from an object
103
+
// Polling for configuration changes every 5 seconds
104
+
while (true) {
105
+
await sleepInMs(5000); // Waiting before the next refresh
106
+
await settings.refresh(); // Refreshing the configuration setting
107
+
console.log(config.message); // Consume current value of message from an object
108
+
}
110
109
```
111
110
112
111
---
@@ -126,8 +125,7 @@ The loaded configuration is updated when a change is detected on the server.
126
125
// Setting up to refresh when the sentinel key is changed
127
126
refreshOptions: {
128
127
enabled: true,
129
-
watchedSettings: [{ key: "sentinel" }], // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
130
-
refreshIntervalInMs: 10 * 1000 // Default value is 30 seconds, shorted for this sample
128
+
watchedSettings: [{ key: "sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
131
129
}
132
130
});
133
131
@@ -154,8 +152,7 @@ The loaded configuration is updated when a change is detected on the server.
154
152
// Setting up to refresh when the sentinel key is changed
155
153
refreshOptions: {
156
154
enabled: true,
157
-
watchedSettings: [{ key: "sentinel" }], // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
158
-
refreshIntervalInMs: 10 * 1000 // Default value is 30 seconds, shorted for this sample
155
+
watchedSettings: [{ key: "sentinel" }] // Watch for changes to the key "sentinel" and refreshes the configuration when it changes
0 commit comments