addWillDelValuesCallback
The addWillDelValuesCallback method registers a WillDelValuesCallback that will be called before all Values are deleted from the Store.
addWillDelValuesCallback(callback: WillDelValuesCallback): Middleware| Type | Description | |
|---|---|---|
callback | WillDelValuesCallback | The |
| returns | Middleware | A reference to the |
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