Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document readConfig function #3230

Merged
merged 4 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" />