Class: InMemoryStore

InMemoryStore()

new InMemoryStore()

Default in-memory store implementation for Pubst.

InMemoryStore is the default store used by Pubst when no custom store is provided. It holds topic values in a plain object in memory.

This class also serves as the reference interface for custom store implementations. Any custom store provided to Pubst via the `store` configuration option must implement the same set of async methods:

  • `registerTopic(topicName, initialVal, storeConfig)` - Called when a topic is configured via `addTopic`.
  • `getValue(topicName)` - Retrieve the current value for a topic.
  • `setValue(topicName, value)` - Store a new value for a topic.
  • `clearValue(topicName)` - Clear the value for a topic (set to null).
  • `getTopicNames()` - Return an array of all registered topic names.

All methods must return a Promise (or be declared async).

Source:

Methods

(async) clearValue(topicName) → {Promise.<null>}

Clear the value for a topic by setting it to null.

Parameters:
Name Type Description
topicName string The name of the topic to clear.
Source:
Returns:
Resolves with `null`.
Type
Promise.<null>

(async) getTopicNames() → {Promise.<Array.<string>>}

Get the names of all topics that have been registered.

Source:
Returns:
Resolves with an array of topic name strings.
Type
Promise.<Array.<string>>

(async) getValue(topicName) → {Promise.<*>}

Retrieve the current value for a topic.

Parameters:
Name Type Description
topicName string The name of the topic.
Source:
Returns:
Resolves with the current value, or `undefined` if the topic has not been registered or set.
Type
Promise.<*>

(async) registerTopic(topicName, initialValopt, storeConfigopt) → {Promise.<Object>}

Register a new topic in the store.

Parameters:
Name Type Attributes Default Description
topicName string The name of the topic to register.
initialVal * <optional>
null The initial value for the topic.
storeConfig Object <optional>
{} Store-specific configuration passed through from the topic's `storeConfig` option. InMemoryStore does not use this value, but custom store implementations may use it for their own initialization (e.g. persistence keys, TTL settings, etc.).
Source:
Returns:
Resolves with an object containing the `topicName`, `initialVal`, and `storeConfig` that were registered.
Type
Promise.<Object>

(async) setValue(topicName, valueopt) → {Promise.<*>}

Store a new value for a topic.

Parameters:
Name Type Attributes Default Description
topicName string The name of the topic.
value * <optional>
null The value to store.
Source:
Returns:
Resolves with the value that was stored.
Type
Promise.<*>