Methods
asJson()
Use this to convert to a simple javascript object, suitable for JSON.
getDomainConfig(domainSlug) → {object}
This method can be used to get the configuration for a domain.
Parameters:
Name | Type | Description |
---|---|---|
domainSlug |
string |
Configuration for the domain
getDomainSections(domainSlug) → {array}
This method can be used to get the list of sections for a given domain
Parameters:
Name | Type | Description |
---|---|---|
domainSlug |
string |
A list of sections that are part of the domain
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 |
The slug of the home collection for a domain
getStack()
- Deprecated:
- Yes
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 |
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 |
The value of f() if it's called the first time, else the value against the key