From 33b6e0d6d87f9ebc836309108ade030c24079333 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 29 Aug 2018 01:12:57 +0300 Subject: [PATCH] minor tweaking and cleanup... Signed-off-by: Alex A. Naanou --- README.md | 2 +- diff.js | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 6341625..370f7a3 100644 --- a/README.md +++ b/README.md @@ -122,7 +122,7 @@ diff.patch(Bill2) ``` -Since we applied *all* the changes to `Bill2`, now he looks just like `Ted`: +Since we applied *all* the changes to `Bill2`, now he is just another `Ted` (or rather `Ted`'s copy): ```javascript //JSON.stringify(Bill2, null, '\t') diff --git a/diff.js b/diff.js index ffc3b13..8fe9cc2 100644 --- a/diff.js +++ b/diff.js @@ -955,6 +955,8 @@ module.Types = { }, + // User API... + // Reverse diff... // reverse: function(diff){ @@ -1092,9 +1094,6 @@ module.Types = { return this.flatten(diff).concat(this.flatten(other)) }, - - // User API... - // Build a diff between A and B... // // NOTE: this will include direct links to items. @@ -1253,6 +1252,16 @@ module.Types = { }) .pop()) }, + // Call the post-patch method of the handlers... + // + postPatch: function(res){ + var that = this + return [...this.types] + .filter(function(e){ + return !!e.postPatch }) + .reduce(function(r, e){ + return e.postPatch.call(that, r) }, res) }, + // XXX need to support different path element types... // ...in addition to Object and Array items, support Map, Set, ... @@ -1329,15 +1338,7 @@ module.Types = { }) .pop()) }, - // Call the post-patch method of the handlers... - // - postPatch: function(res){ - var that = this - return [...this.types] - .filter(function(e){ - return !!e.postPatch }) - .reduce(function(r, e){ - return e.postPatch.call(that, r) }, res) }, + // Check if diff is applicable to obj... //