Naughty Programmer's Madness

    track-object-history
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    track-object-history

    track-object-history provides a simple function with which you can wrap your object in a proxy that automatically tracks mutations to said object.

    It has a couple of use cases:

    • debugging mutation-heavy code
    • simple time travel capabilities

    However, if you find yourself reaching for this package, you might want to consider rewriting your code in a immutable fashion instead.

    Installation

    npm install track-object-history

    Usage

    Supports the most common ways of mutating an object, i.e. reassigning, deleting and defining properties.

    Basic example

    import { trackObjectHistory } from "track-object-history";
     
    const [form, history] = trackObjectHistory({
      firstName: "",
      lastName: ""
    });
     
    form.firstName = "John";
    console.log(form); // { firstName: "John", lastName: "" }
    console.log(history); // [{ firstName: "", lastName: "" }]
     
    form.lastName = "Doe";
     
    console.log(form); // { firstName: "John", lastName: "Doe" }
    console.log(history); // [{ firstName: "John", lastName: "" }]

    Install

    npm i track-object-history

    DownloadsWeekly Downloads

    1

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    3.23 kB

    Total Files

    3

    Last publish

    Collaborators

    • janove