addWillDelValueCallback
The addWillDelValueCallback method registers a WillDelValueCallback that will be called before any Value is deleted from the Store.
addWillDelValueCallback(callback: WillDelValueCallback): Middleware| Type | Description | |
|---|---|---|
callback | WillDelValueCallback | 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 the 'storeName' Value from the pet store.
import {createMiddleware, createStore} from 'tinybase';
const store = createStore();
const middleware = createMiddleware(store);
store.setValue('storeName', 'happy pets');
middleware.addWillDelValueCallback((valueId) => valueId !== 'storeName');
store.delValue('storeName');
console.log(store.getValue('storeName'));
// -> 'happy pets'
middleware.destroy();
Since
v8.0.0