Skip to content

Commit

Permalink
Document readConfig function (#3230)
Browse files Browse the repository at this point in the history
* Update getConfig.md

* Create readConfig.md

* Update getConfig.md

* Update readConfig.md

Co-authored-by: MartianTribe <[email protected]>
  • Loading branch information
patmmccann and MartianTribe authored Sep 9, 2021
1 parent f0e8f78 commit 424c82b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
10 changes: 7 additions & 3 deletions dev-docs/publisher-api-reference/getConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ title: pbjs.getConfig([string])
description:
---

## Overview

The `getConfig` function is for retrieving the current configuration object or subscribing to configuration updates. When called with no parameters, the entire config object is returned. When called with a string parameter, a single configuration property matching that parameter is returned.
The `getConfig` function is used for retrieving the current configuration object or subscribing to configuration updates. When called with no parameters, the entire config object is returned. When called with a string parameter, a single configuration property matching that parameter is returned. Be careful with use of this function, as it returns a reference to the configuration instead of a clone. The readConfig function has been introduced for safer use.

{% highlight js %}
/* Get config object */
Expand All @@ -15,7 +16,10 @@ config.getConfig()
config.getConfig('debug')
{% endhighlight %}

The `getConfig` function also contains a 'subscribe' ability that adds a callback function to a set of listeners that are invoked whenever `setConfig` is called. The subscribed function will be passed the options object that was used in the `setConfig` call. Individual topics can be subscribed to by passing a string as the first parameter and a callback function as the second. For example:

### Subscribe

The `getConfig` function contains a `subscribe` feature that adds a callback function to a set of listeners that are invoked whenever `setConfig` is called. The `subscribed` function will be passed the `options` object that was used in the `setConfig` call. Individual topics can be subscribed to by passing a string as the first parameter and a callback function as the second. For example:

{% highlight js %}

Expand All @@ -31,4 +35,4 @@ unsubscribe(); // no longer listening

{% endhighlight %}

<hr class="full-rule" />
<hr class="full-rule" />
18 changes: 18 additions & 0 deletions dev-docs/publisher-api-reference/readConfig.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
layout: api_prebidjs
title: pbjs.readConfig([string])
description:
---


The `readConfig` function is used for retrieving the current configuration object or subscribing to configuration updates. When called with no parameters, the entire config object is returned. When called with a string parameter, a single configuration property matching that parameter is returned. The readConfig function has been introduced for safer use of the getConfig functionality, as it returns a clone.

{% highlight js %}
/* Get config object */
config.readConfig()

/* Get debug config */
config.readConfig('debug')
{% endhighlight %}

<hr class="full-rule" />

0 comments on commit 424c82b

Please sign in to comment.