track-changes
Very simple API for tracking changes to the property of an object for use in debugging.
npm
Install withnpm i track-changes --save
Examples
This is a basic example showing how you might track changes to a value in your application.
var app = ;var a = 'a';app; a = 'b';app; a = 'c';app; a = 'd';app; console;// { first: 'a',// last: 'd',// 'change #1': 'a',// 'change #2': 'b',// 'change #3': 'c',// 'change #4': 'd' }
Tracking changes to an object
This example just shows how you might track changes to an object after using merge
versus extend
.
var app = ; // objects with properties to track. These are both the same.var foo = b: c: 'd';var bar = b: c: 'd'; // We're going to use `merge` on foo, and `extend` on barapp;app; // merge foo, and extend bar;; // record changesapp;app;
Results:
console;// { first: { b: { c: 'd' } },// last: { b: { c: 'd', e: 'f' } },//// 'before merge:': { b: { c: 'd' } },// 'after merge:': { b: { c: 'd', e: 'f' } } } console;// { first: { b: { c: 'd' } },// last: { b: { e: 'f' } },//// 'before extend:': { b: { c: 'd' } },// 'after extend:': { b: { e: 'f' } } }
API
Changes
Create a new instance of Changes
.
var app = ;
.track
Track the value
of key
with a comment
.
key
{String}comment
{String}: Brief comment about wherekey
is being tracked.value
{*}returns
{Object}Changes
: for chaining.
var foo = 'foo';app; foo = 'bar';app; foo = 'baz';app; // get history of tracked changes for `foo`app;
Author
Jon Schlinkert
License
Copyright (c) 2015 Jon Schlinkert
Released under the license
This file was generated by verb on February 21, 2015.