Skip to content

Commit 9bc331b

Browse files
authored
switch order of Sample 2&3, address comments
1 parent 9533770 commit 9bc331b

File tree

1 file changed

+47
-50
lines changed

1 file changed

+47
-50
lines changed

articles/azure-app-configuration/quickstart-javascript-provider.md

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -103,80 +103,79 @@ async function run() {
103103
run().catch(console.error);
104104
```
105105

106-
### Sample 2: Load key-values and trim prefix from keys
106+
### Sample 2: Load specific key-values using selectors
107107

108-
In this sample, you load key-values with an option `trimKeyPrefixes`.
109-
After key-values are loaded, the prefix "app." is trimmed from all keys.
110-
This can be convenient especially when the keys share a long prefix.
108+
In this sample, you load a subset of key-values by specifying the `selectors` option.
109+
Only keys starting with "app." are loaded.
110+
Note that you can specify multiple selectors based on your needs, each with `keyFilter` and `labelFilter` properties.
111111

112112
```javascript
113113
const { load } = require("@azure/app-configuration-provider");
114114
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
115115

116116
async function run() {
117-
console.log("Sample 2: Load key-values and trim prefix from keys");
117+
console.log("Sample 3: Load specific key-values using selectors");
118118

119-
// Load all key-values with no label, and trim "app." prefix from all keys.
119+
// Load a subset of keys starting with "app." prefix.
120120
const settings = await load(connectionString, {
121-
trimKeyPrefixes: ["app."]
121+
selectors: [{
122+
keyFilter: "app.*"
123+
}],
122124
});
123125

124126
console.log("---Consume configuration as a Map---");
125-
// Find the key "message" and print its value. The key is not trimmed as it does not start with "app."
126-
console.log('settings.get("message"):', settings.get("message")); // settings.get("message"): Message from Azure App Configuration
127-
// The original key "app.greeting" is trimmed as "greeting".
128-
console.log('settings.get("greeting"):', settings.get("greeting")); // settings.get("greeting"): Hello World
129-
// The original key "app.json" is trimmed as "json".
130-
console.log('settings.get("json"):', settings.get("json")); // settings.get("json"): { myKey: 'myValue' }
127+
// The key "message" is not loaded as it does not start with "app."
128+
console.log('settings.has("message"):', settings.has("message")); // settings.has("message"): false
129+
// The key "app.greeting" is loaded
130+
console.log('settings.has("app.greeting"):', settings.has("app.greeting")); // settings.has("app.greeting"): true
131+
// The key "app.json" is loaded
132+
console.log('settings.has("app.json"):', settings.has("app.json")); // settings.has("app.json"): true
131133

132134
console.log("---Consume configuration as an object---");
133-
// Construct configuration object from loaded key-values with trimmed keys.
134-
const config = settings.constructConfigurationObject();
135+
// Construct configuration object from loaded key-values
136+
const config = settings.constructConfigurationObject({ separator: "." });
135137
// Use dot-notation to access configuration
136-
console.log("config.message:", config.message); // config.message: Message from Azure App Configuration
137-
console.log("config.greeting:", config.greeting); // config.greeting: Hello World
138-
console.log("config.json:", config.json); // config.json: { myKey: 'myValue' }
138+
console.log("config.message:", config.message); // config.message: undefined
139+
console.log("config.app.greeting:", config.greeting); // config.app.greeting: Hello World
140+
console.log("config.app.json:", config.json); // config.app.json: { myKey: 'myValue' }
139141
}
140142

141143
run().catch(console.error);
142144
```
143145

144-
### Sample 3: Load specific key-values using selectors
145-
146-
In this sample, you load a subset of key-values by specifying the `selectors` option.
147-
Only keys starting with "app." are loaded.
148-
Note that you can specify multiple selectors based on your needs, each with `keyFilter` and `labelFilter` properties.
146+
### Sample 3: Load key-values and trim prefix from keys
149147

148+
In this sample, you load key-values with an option `trimKeyPrefixes`.
149+
After key-values are loaded, the prefix "app." is trimmed from all keys.
150+
This is useful when you want to load configurations that are specific to your application by filtering to a certain key prefix, but you don't want your code to carry the prefix every time it accesses the configuration.
150151

151152
```javascript
152153
const { load } = require("@azure/app-configuration-provider");
153154
const connectionString = process.env.AZURE_APPCONFIG_CONNECTION_STRING;
154155

155156
async function run() {
156-
console.log("Sample 3: Load specific key-values using selectors");
157+
console.log("Sample 2: Load key-values and trim prefix from keys");
157158

158-
// Load a subset of keys starting with "app." prefix.
159+
// Load all key-values with no label, and trim "app." prefix from all keys.
159160
const settings = await load(connectionString, {
160161
selectors: [{
161162
keyFilter: "app.*"
162163
}],
164+
trimKeyPrefixes: ["app."]
163165
});
164166

165167
console.log("---Consume configuration as a Map---");
166-
// The key "message" is not loaded as it does not start with "app."
167-
console.log('settings.has("message"):', settings.has("message")); // settings.has("message"): false
168-
// The key "app.greeting" is loaded
169-
console.log('settings.has("app.greeting"):', settings.has("app.greeting")); // settings.has("app.greeting"): true
170-
// The key "app.json" is loaded
171-
console.log('settings.has("app.json"):', settings.has("app.json")); // settings.has("app.json"): true
168+
// The original key "app.greeting" is trimmed as "greeting".
169+
console.log('settings.get("greeting"):', settings.get("greeting")); // settings.get("greeting"): Hello World
170+
// The original key "app.json" is trimmed as "json".
171+
console.log('settings.get("json"):', settings.get("json")); // settings.get("json"): { myKey: 'myValue' }
172172

173173
console.log("---Consume configuration as an object---");
174-
// Construct configuration object from loaded key-values
175-
const config = settings.constructConfigurationObject({ separator: "." });
174+
// Construct configuration object from loaded key-values with trimmed keys.
175+
const config = settings.constructConfigurationObject();
176176
// Use dot-notation to access configuration
177-
console.log("config.message:", config.message); // config.message: undefined
178-
console.log("config.app.greeting:", config.greeting); // config.app.greeting: Hello World
179-
console.log("config.app.json:", config.json); // config.app.json: { myKey: 'myValue' }
177+
console.log("config.greeting:", config.greeting); // config.greeting: Hello World
178+
console.log("config.json:", config.json); // config.json: { myKey: 'myValue' }
180179
}
181180

182181
run().catch(console.error);
@@ -280,20 +279,6 @@ run().catch(console.error);
280279
281280
**Sample 2**
282281
283-
```Output
284-
Sample 2: Load key-values and trim prefix from keys
285-
---Consume configuration as a Map---
286-
settings.get("message"): Message from Azure App Configuration
287-
settings.get("greeting"): Hello World
288-
settings.get("json"): { myKey: 'myValue' }
289-
---Consume configuration as an object---
290-
config.message: Message from Azure App Configuration
291-
config.greeting: Hello World
292-
config.json: { myKey: 'myValue' }
293-
```
294-
295-
**Sample 3**
296-
297282
```Output
298283
Sample 3: Load specific key-values using selectors
299284
---Consume configuration as a Map---
@@ -306,6 +291,18 @@ run().catch(console.error);
306291
config.app.json: { myKey: 'myValue' }
307292
```
308293
294+
**Sample 3**
295+
296+
```Output
297+
Sample 2: Load key-values and trim prefix from keys
298+
---Consume configuration as a Map---
299+
settings.get("greeting"): Hello World
300+
settings.get("json"): { myKey: 'myValue' }
301+
---Consume configuration as an object---
302+
config.greeting: Hello World
303+
config.json: { myKey: 'myValue' }
304+
```
305+
309306
## Clean up resources
310307
311308
[!INCLUDE [azure-app-configuration-cleanup](../../includes/azure-app-configuration-cleanup.md)]

0 commit comments

Comments
 (0)