addWillDelCellCallback
The addWillDelCellCallback method registers a WillDelCellCallback that will be called before any Cell is deleted from the Store.
addWillDelCellCallback(callback: WillDelCellCallback): Middleware| Type | Description | |
|---|---|---|
callback | WillDelCellCallback | 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 cells from the 'pets' table.
import {createMiddleware, createStore} from 'tinybase';
const store = createStore();
const middleware = createMiddleware(store);
store.setCell('pets', 'fido', 'species', 'dog');
middleware.addWillDelCellCallback((tableId) => tableId !== 'pets');
store.delCell('pets', 'fido', 'species', true);
console.log(store.getCell('pets', 'fido', 'species'));
// -> 'dog'
middleware.destroy();
Since
v8.0.0