@xstd/with-immutability
v1.0.0
Published
Class that may have an immutable state.
Downloads
11
Readme
@xstd/with-immutability
Add immutability to any class.
📦 Installation
yarn add @xstd/with-immutability
# or
npm install @xstd/with-immutability --save📜 Documentation
/**
* The `WithImmutability` class provides a mechanism to enforce immutability, where certain changes to
* an instance can be restricted after being marked as immutable. The class includes methods to set
* the immutable state and to throw an error if a modification is attempted when immutable.
*/
declare class WithImmutability {
/**
* Throws an error if the current instance is immutable.
*
* @throws {Error} An Error indicating that the instance is immutable.
*/
throwIfImmutable(): void;
/**
* Retrieves the immutable status of the instance.
*
* @returns {boolean} Returns `true` if the instance is immutable, otherwise `false`.
*/
readonly immutable: boolean;
/**
* Marks the current instance as immutable, ensuring that subsequent modifications are restricted.
*
* @returns {this} The current instance with immutability enforced.
*/
makeImmutable(): this;
}