Skip to content

Commit ec7e878

Browse files
committed
Changed check for required properties on change
requirement of instanceof Diff is way to strong
1 parent 42b0ca7 commit ec7e878

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

index.js

+30-2
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@
6767
}
6868
inherits(DiffArray, Diff);
6969

70+
function checkForDiff(object) {
71+
if (object && object.kind && object.path){
72+
switch(object.kind) {
73+
case 'A':
74+
if (object.hasOwnProperty('index') && object.hasOwnProperty('item')){
75+
return true;
76+
}
77+
break;
78+
case 'D':
79+
if (object.hasOwnProperty('lhs')){
80+
return true;
81+
}
82+
break;
83+
case 'E':
84+
if (object.hasOwnProperty('lhs') && object.hasOwnProperty('rhs')){
85+
return true;
86+
}
87+
break;
88+
case 'N':
89+
if (object.hasOwnProperty('rhs')){
90+
return true;
91+
}
92+
break;
93+
}
94+
}
95+
return false;
96+
}
97+
7098
function arrayRemove(arr, from, to) {
7199
var rest = arr.slice((to || from) + 1 || arr.length);
72100
arr.length = from < 0 ? arr.length + from : from;
@@ -189,8 +217,8 @@
189217
}
190218

191219
function applyChange(target, source, change) {
192-
if (!(change instanceof Diff)) {
193-
throw new TypeError('[Object] change must be instanceof Diff');
220+
if (!checkForDiff(change)) {
221+
throw new TypeError('[Object] Required properties on change are missing');
194222
}
195223
if (target && source && change) {
196224
var it = target, i, u;

0 commit comments

Comments
 (0)