Skip to content
This repository was archived by the owner on Oct 24, 2021. It is now read-only.

Commit 60f7ab0

Browse files
committed
Doc WebApp.updatedConfigHook
1 parent fff4bc8 commit 60f7ab0

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

source/packages/webapp.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ These 2 conditions break `autoupdate` for the cordova applications. `cordova-plu
134134
To remedy this problem `webapp` has a hook for dynamically configuring `__meteor_runtime_config__` on the server.
135135

136136
#### Dynamic Runtime Configuration Hook
137+
Register a callback when the meteor runtime configuration, `__meteor_runtime_config__` is being sent to the client.
137138
```js
138139
WebApp.addRuntimeConfigHook(({arch, request, encodedCurrentConfig, updated}) => {
139140
// check the request to see if this is a request that requires
140141
// modifying the runtime configuration
141-
if(req.headers.domain === 'calling.domain') {
142+
if(request.headers.domain === 'calling.domain') {
142143
// make changes to the config for this domain
143144
// decode the current runtime config string into an object
144145
const config = WebApp.decodeRuntimeConfig(current);
@@ -176,3 +177,26 @@ Additionally, 2 helper functions are available to decode the runtime config stri
176177
`WebApp.encodeRuntimeConfig(config_object)`: returns an encoded string from a config object that is ready for the root page.
177178

178179
The expected usage is to decode the runtime config string, operate on the object and then return the encoded runtime configuration.
180+
181+
### Updated Runtime Configuration Hook
182+
Register a callback on updates to the configuration runtime.
183+
```js
184+
const autoupdateCache;
185+
// Get a notification when the runtime configuration is updated
186+
WebApp.addUpdatedConfigHook(({arch, manifest, runtimeConfig}) => {
187+
// Example, see if runtimeConfig.autoupdate has changed and if so
188+
// do something
189+
if(!_.isEqual(autoupdateCache, runtimeConfig.autoupdate)) {
190+
autoupdateCache = runtimeConfig.autoupdate;
191+
// do something...
192+
}
193+
})
194+
```
195+
196+
`WebApp.addUpdatedConfigHook(handler)` has one argument:
197+
198+
**handler** - The `handler` is called on every change to an `arch` runtime configuration. The handler takes a single options argument with the following properties:
199+
200+
- **arch** - _String_. the architecture being responded to. This can be one of `web.browser`, `web.browser.legacy` or `web.cordova`.
201+
- **manifest** - _Object_. the manifest object.
202+
- **runtimeConfig** - _Object_. the new updated configuration object for this `arch`.

0 commit comments

Comments
 (0)