@harlem/extension-transaction

The official transaction extension for Harlem
1,490 515
Install
npm install @harlem/extension-transaction
Latest Version:3.1.8
Vue:3
License:MIT
Last Updated:Jun 3, 2024
Links: GitHub  ·  npm
Maintainer: andrewcourtice

Harlem Transaction Extension

The transaction extension adds the ability to rollback a set of mutations in the event of an error.

Getting Started

Follow the steps below to get started using the transaction extension.

Installation

Before installing this extension make sure you have installed harlem.

yarn add @harlem/extension-transaction
# or
npm install @harlem/extension-transaction

Registration

To get started simply register this extension with the store you wish to extend.

import transactionExtension from '@harlem/extension-transaction';

import {
    createStore
} from 'harlem';

const STATE = {
    firstName: 'Jane',
    lastName: 'Smith'
};

const {
    state,
    getter,
    mutation,
    transaction,
    onBeforeTransaction,
    onAfterTransaction,
    onTransactionSuccess,
    onTransactionError,
} = createStore('example', STATE, {
    extensions: [
        transactionExtension()
    ]
});

The transaction extension adds several new methods to the store instance (highlighted above).

Usage

Defining a transaction

A transaction can be defined the same way you define any other core functionality (eg. getter, mutation etc.).

export default transaction('my-transaction', (payload, mutate) => {
    /*
    Any mutations run during this method
    will be rolled back if an error occurs
    */
});
  • This extension comes with a performance cost. The entire state tree is cloned and stored before a transaction is run in order to rollback in the event of an error.
  • This extension does not protect against issues attempting to roll back state in async scenarios

Related Packages

@harlem/extension-compose

The official compose extension for Harlem

5,461 515
@harlem/extension-action

The official action extension for Harlem

2,809 515
@harlem/extension-storage

The official storage extension for Harlem

2,248 515
@harlem/extension-lazy

The official lazy extension for Harlem

2,012 515
@harlem/extension-trace

The official trace extension for Harlem

1,645 515

Version History

Version Released License
3.1.8 MIT
3.1.7 MIT
3.1.6 MIT
3.1.5 MIT
3.1.4 MIT
Pre-releases (25)
Version Released License
3.0.0-beta.1 MIT
3.0.0-beta.0 MIT
2.4.0-beta.11 MIT
2.4.0-beta.10 MIT
2.4.0-beta.9 MIT