registerPlugins(plugins)

Registers plugins and returns new instance of self (cacheInstance) extended with functionalities provided by plugins.

Arguments

  1. plugins (array): Array of plugins.

Returns

(cacheInstance): A new instance of cacheInstance. New instance of cache, like the original one, is immutable (using Object.freeze).

Throws

  1. When plugins are not passed as an array.

  2. When any of the plugins won't contain either hooks or createExtensions method.

  3. When any of the plugins will try do add a method that already exists (which would overwrite it).

Example

// assuming that you already have cache instance and some plugins prepared
// plugin adds additional method `foo`
const cacheWithPlugins = cache.registerPlugins([ plugin ]);

cacheWithPlugins === cache; // false

typeof cacheWithPlugins.foo; // function
typeof cache.foo; // undefined

Last updated