TinyBase logoTinyBase

addWillDelValuesCallback

The addWillDelValuesCallback method registers a WillDelValuesCallback that will be called before all Values are deleted from the Store.

addWillDelValuesCallback(callback: WillDelValuesCallback): Middleware
TypeDescription
callbackWillDelValuesCallback

The WillDelValuesCallback to register.

returnsMiddleware

A reference to the Middleware object, for chaining.

The callback returns true to allow the deletion or false to prevent it. Multiple callbacks can be registered and they are called sequentially. If any callback returns false, the deletion is prevented.

Example

This example registers a callback that prevents deleting all Values from the pet store.

import {createMiddleware, createStore} from 'tinybase';

const store = createStore();
const middleware = createMiddleware(store);

store.setValues({storeName: 'happy pets', limit: 50});

middleware.addWillDelValuesCallback(() => false);

store.delValues();
console.log(store.getValues());
// -> {storeName: 'happy pets', limit: 50}

middleware.destroy();

Since

v8.0.0