Skip to content

Commit f8e5033

Browse files
committed
Refine steps per comments
1 parent f9bf4e1 commit f8e5033

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

articles/azure-app-configuration/enable-dynamic-configuration-javascript.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ The following examples show how to use refreshable configuration values in conso
4343
The refresh behavior is configured by `refreshOptions` parameter when calling `load` function.
4444
The loaded configuration is updated when a change is detected on the server.
4545

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.
4747

4848
### [Use configuration as Map](#tab/configuration-map)
4949

@@ -53,25 +53,23 @@ The loaded configuration is updated when a change is detected on the server.
5353
// Setting up to refresh when the sentinel key is changed
5454
refreshOptions: {
5555
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
5857
}
5958
});
6059
```
6160

6261
### [Use configuration as object](#tab/configuration-object)
6362

6463
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.
6665

6766
```javascript
6867
// Connecting to Azure App Configuration using connection string
6968
const settings = await load(connectionString, {
7069
// Setting up to refresh when the sentinel key is changed
7170
refreshOptions: {
7271
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
7573
}
7674
});
7775

@@ -88,25 +86,26 @@ The loaded configuration is updated when a change is detected on the server.
8886

8987
1. Add the following code to poll configuration changes of watched key-values every 5 seconds.
9088

89+
### [Use configuration as Map](#tab/configuration-map)
90+
9191
```javascript
9292
// Polling for configuration changes every 5 seconds
9393
while (true) {
9494
await sleepInMs(5000); // Waiting before the next refresh
9595
await settings.refresh(); // Refreshing the configuration setting
96+
console.log(settings.get("message")); // Consume current value of message from a Map
9697
}
9798
```
9899

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-
```
106100
### [Use configuration as object](#tab/configuration-object)
107101

108102
```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+
}
110109
```
111110

112111
---
@@ -126,8 +125,7 @@ The loaded configuration is updated when a change is detected on the server.
126125
// Setting up to refresh when the sentinel key is changed
127126
refreshOptions: {
128127
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
131129
}
132130
});
133131
@@ -154,8 +152,7 @@ The loaded configuration is updated when a change is detected on the server.
154152
// Setting up to refresh when the sentinel key is changed
155153
refreshOptions: {
156154
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
159156
}
160157
});
161158

0 commit comments

Comments
 (0)