@susisu/tesseract
v0.1.0
Published
session and transaction
Downloads
2
Readme
@susisu/tesseract
npm i @susisu/tesseract
# or
yarn add @susisu/tesseract
Usage
Database
Manipulating database with transaction.
import { AsyncSession } from "@susisu/tesseract";
const session = new AsyncSession({
async initialize() {
await begin();
},
async finalize() {
await commit();
},
async handleError() {
await rollback();
},
});
await session.transact(async () => {
await updateA(session);
await updateB(session);
});
async function updateA(session: AsyncSession): Promise<void> {
await session.transact(async () => {
await updateA0(session);
await updateA1(session);
});
}
Editor
Executing multiple edit operations while pushing at most one history to the undo buffer.
import { Session } from "@susisu/tesseract";
const session = new Session<State>({
initialize() {
return dumpState();
},
finalize(oldState: State) {
const newState = dumpState();
if (!newState.equals(oldState)) {
pushHistory(oldState);
}
},
});
session.transact(() => {
editA(session);
editB(session);
});
Emitter
Updating a state multiple times while emitting at most one update event.
import { Session } from "@susisu/tesseract";
const session = new Session<State>({
initialize() {
return dumpState();
},
finalize(oldState: State) {
const newState = dumpState();
if (!newState.equals(oldState)) {
emitUpdate();
}
},
});
session.transact(() => {
updateA(session);
updateB(session);
});