getTransactionLog
The getTransactionLog
method returns the changes that were made to a Store
during a transaction in more detail, including invalid changes, and what previous values were.
getTransactionLog(): TransactionLog
returns | TransactionLog | A |
---|
This is useful for deciding whether to rollback a transaction, for example. The returned object is only meaningful if the method is called when the Store
is in a transaction - such as in a TransactionListener
.
Example
This example makes changes to the Store
. At the end of the transaction, detail about what changed is enumerated.
import {createStore} from 'tinybase';
const store = createStore()
.setTables({pets: {fido: {species: 'dog', color: 'brown'}}})
.setValues({open: true});
store
.startTransaction()
.setCell('pets', 'fido', 'color', 'black')
.setCell('pets', 'fido', 'eyes', ['left', 'right'])
.setCell('pets', 'fido', 'info', {sold: null})
.setValue('open', false)
.setValue('employees', ['alice', 'bob'])
.finishTransaction(() => {
const [, , changedCells, invalidCells, changedValues, invalidValues] =
store.getTransactionLog();
console.log(changedCells);
console.log(invalidCells);
console.log(changedValues);
console.log(invalidValues);
});
// -> {pets: {fido: {color: ['brown', 'black']}}}
// -> {pets: {fido: {eyes: [['left', 'right']], info: [{sold: null}]}}}
// -> {open: [true, false]}
// -> {employees: [['alice', 'bob']]}
Since
v5.0.0