Class

Config

Config

Represents the configuration of the publisher. This represents the API call of /api/v1/config.

In the malibu framework, this is loaded at page load, then updated periodically. An instance of the Config object will be injected into most malibu functions, and you should never need to create it manually.

See the API Documentation for a list of fields

Methods

asJson()

Use this to convert to a simple javascript object, suitable for JSON.

View Source index.js, line 565

getDomainConfig(domainSlug) → {object}

This method can be used to get the configuration for a domain.

Parameters:
Name Type Description
domainSlug string

View Source index.js, line 579

Configuration for the domain

object

getDomainSections(domainSlug) → {array}

This method can be used to get the list of sections for a given domain

Parameters:
Name Type Description
domainSlug string

View Source index.js, line 597

A list of sections that are part of the domain

array

getHomeCollectionSlug(domainSlug) → {string}

This method can be used to get the home collection's slug for a given domainSlug

Parameters:
Name Type Description
domainSlug string

View Source index.js, line 588

The slug of the home collection for a domain

string

getStack()

Deprecated:
  • Yes

View Source index.js, line 570

memoize(key, f)

This can be used to memoize a synchronous function. The value of f() is stored against the given key until the config object is removed from memory. By default in malibu, the config object is replaced every two minutes. Typically, this is used to memoize the routes for fast subsequest requests.

This function shares a keyspace with memoizeAsync

Example:

const routes = config.memoize("routes_all", () => [homePage, ...storyPages, ...sectionPages])
Parameters:
Name Type Description
key string

The key to store the results against

f function

A function that is executed to get the results

View Source index.js, line 625

The value of f() if it's called the first time, else the value against the key

async memoizeAsync(key, f)

This can be used to memoize an asynchronous function. The value of await f() is stored against the given key until the config object is removed from memory. By default in malibu, the config object is replaced every two minutes. This can be used to memoize objects such as collections returned by this library

This function can be used concurrently. The first call will cause other requests to block. If the promise resolves, then all calls (and future calls) will recieve that value. If the promise fails, then all waiting promises reject, but the next call will start afresh.

This function shares a keyspace with memoize

Example:

const collection = await config.memoizeAsync("collection-on-every-page", async () => await Collection.getCollectionBySlug("collection-on-every-page"))
Parameters:
Name Type Description
key string

The key to store the results against

f function

An async function that is executed to get the results

View Source index.js, line 651

The value of f() if it's called the first time, else the value against the key