1.0.1 • Published 3 years ago

object-rewinder v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Installation

npm install object-rewinder

Getting started

import ObjectRewinder from 'object-rewinder';

let dataToWatch = { empty: 'object' };

let rewinder = new ObjectRewinder(dataToWatch);
dataToWatch = rewinder.getObject(); // Overwrite the data with the observed one

// From now on every change on "dataToWatch" will be recorded
// And We're be able to rollback thoses changes

dataToWatch.value = 'very good value'
console.log(dataToWatch);

//  Outputs:
//   {
//     empty: 'object',
//     value: 'very good value'
//   }

rewinder.back();
console.log(dataToWatch);

//  Outputs:
//   {
//     empty: 'object',
//   }

rewinder.forward();
console.log(dataToWatch);

//  Outputs:
//   {
//     empty: 'object',
//     value: 'very good value'
//   }