Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed check for required properties on change #13

Merged
merged 6 commits into from
Mar 12, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@
}
inherits(DiffArray, Diff);

function checkForDiff(object) {
if (object && object.kind && object.path){
switch(object.kind) {
case 'A':
if (object.hasOwnProperty('index') && object.hasOwnProperty('item')){
return true;
}
break;
case 'D':
if (object.hasOwnProperty('lhs')){
return true;
}
break;
case 'E':
if (object.hasOwnProperty('lhs') && object.hasOwnProperty('rhs')){
return true;
}
break;
case 'N':
if (object.hasOwnProperty('rhs')){
return true;
}
break;
}
}
return false;
}

function arrayRemove(arr, from, to) {
var rest = arr.slice((to || from) + 1 || arr.length);
arr.length = from < 0 ? arr.length + from : from;
Expand Down Expand Up @@ -189,8 +217,8 @@
}

function applyChange(target, source, change) {
if (!(change instanceof Diff)) {
throw new TypeError('[Object] change must be instanceof Diff');
if (!checkForDiff(change)) {
throw new TypeError('[Object] Required properties on change are missing');
}
if (target && source && change) {
var it = target, i, u;
Expand Down