TinyBase logoTinyBase β

createMiddleware

The createMiddleware function creates a Middleware object, and is the main entry point into the middleware module.

createMiddleware(store: Store): Middleware
TypeDescription
storeStore

The Store for which to register the Middleware.

returnsMiddleware

A reference to the new Middleware object.

A given Store can only have one Middleware object associated with it. If you call this function twice on the same Store, your second call will return a reference to the Middleware object created by the first.

Examples

This example creates a Middleware object.

import {createMiddleware, createStore} from 'tinybase';

const store = createStore();
const middleware = createMiddleware(store);
console.log(middleware.getStore() == store);
// -> true
middleware.destroy();

This example creates a Middleware object, and calls the method a second time for the same Store to return the same object.

import {createMiddleware, createStore} from 'tinybase';

const store = createStore();
const middleware = createMiddleware(store);
console.log(middleware === createMiddleware(store));
// -> true
middleware.destroy();

Since

v8.0.0