delta-listener
Advanced tools
Comparing version 2.0.0 to 2.1.0-alpha.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function compare(tree1, tree2) { | ||
@@ -8,19 +9,14 @@ var patches = []; | ||
exports.compare = compare; | ||
function deepClone(obj) { | ||
switch (typeof obj) { | ||
case "object": | ||
return JSON.parse(JSON.stringify(obj)); //Faster than ES5 clone - http://jsperf.com/deep-cloning-of-objects/5 | ||
case "undefined": | ||
return null; //this is how JSON.stringify behaves for array items | ||
default: | ||
return obj; //no need to clone primitives | ||
} | ||
function concat(arr, value) { | ||
var newArr = arr.slice(); | ||
newArr.push(value); | ||
return newArr; | ||
} | ||
function objectKeys(obj) { | ||
if (Array.isArray(obj)) { | ||
var keys = new Array(obj.length); | ||
for (var k = 0; k < keys.length; k++) { | ||
keys[k] = "" + k; | ||
var keys_1 = new Array(obj.length); | ||
for (var k = 0; k < keys_1.length; k++) { | ||
keys_1[k] = "" + k; | ||
} | ||
return keys; | ||
return keys_1; | ||
} | ||
@@ -51,3 +47,3 @@ if (Object.keys) { | ||
if (typeof oldVal == "object" && oldVal != null && typeof newVal == "object" && newVal != null) { | ||
generate(oldVal, newVal, patches, path.concat(key)); | ||
generate(oldVal, newVal, patches, concat(path, key)); | ||
} | ||
@@ -57,3 +53,3 @@ else { | ||
changed = true; | ||
patches.push({ operation: "replace", path: path.concat(key), value: deepClone(newVal) }); | ||
patches.push({ operation: "replace", path: concat(path, key), value: newVal }); | ||
} | ||
@@ -63,3 +59,3 @@ } | ||
else { | ||
patches.push({ operation: "remove", path: path.concat(key) }); | ||
patches.push({ operation: "remove", path: concat(path, key) }); | ||
deleted = true; // property has been deleted | ||
@@ -74,5 +70,11 @@ } | ||
if (!mirror.hasOwnProperty(key) && obj[key] !== undefined) { | ||
patches.push({ operation: "add", path: path.concat(key), value: deepClone(obj[key]) }); | ||
var newVal = obj[key]; | ||
var addPath = concat(path, key); | ||
// compare deeper additions | ||
if (typeof newVal == "object" && newVal != null) { | ||
generate({}, newVal, patches, addPath); | ||
} | ||
patches.push({ operation: "add", path: addPath, value: newVal }); | ||
} | ||
} | ||
} |
@@ -10,3 +10,3 @@ import { PatchObject } from "./compare"; | ||
} | ||
export declare class DeltaContainer<T> { | ||
export declare class DeltaContainer<T = any> { | ||
data: T; | ||
@@ -13,0 +13,0 @@ private listeners; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var compare_1 = require("./compare"); | ||
var DeltaContainer = (function () { | ||
var DeltaContainer = /** @class */ (function () { | ||
function DeltaContainer(data) { | ||
@@ -5,0 +6,0 @@ this.listeners = []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var DeltaContainer_1 = require("./DeltaContainer"); | ||
exports.DeltaContainer = DeltaContainer_1.DeltaContainer; |
{ | ||
"name": "delta-listener", | ||
"version": "2.0.0", | ||
"version": "2.1.0-alpha.0", | ||
"description": "Deeply compare JavaScript objects and listen to changes.", | ||
@@ -28,9 +28,9 @@ "main": "lib/index.js", | ||
"chai": "^3.5.0", | ||
"fast-json-patch": "^1.1.2", | ||
"fast-json-patch": "^2.0.5", | ||
"mocha": "^3.2.0", | ||
"rimraf": "^2.5.4", | ||
"ts-node": "^3.1.0", | ||
"typescript": "^2.1.4", | ||
"typescript": "^2.5.3", | ||
"zuul": "^3.11.1" | ||
} | ||
} |
@@ -87,2 +87,3 @@ # delta-listener [](https://travis-ci.org/endel/delta-listener) | ||
- `:string`: `/(\w+)/` | ||
- `:axis`: `/^([xyz])$/` | ||
- `:*`: `/(.*)/` | ||
@@ -89,0 +90,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
234
104
0
14678
13
2