Skip to content

Commit

Permalink
Release 20.2.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
babich-a committed Oct 1, 2020
1 parent 6b3dbbc commit 0e85543
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 46 deletions.
3 changes: 0 additions & 3 deletions .vscode/extensions.json

This file was deleted.

23 changes: 0 additions & 23 deletions .vscode/launch.json

This file was deleted.

5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

29 changes: 15 additions & 14 deletions js/data/array_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function createObjectWithChanges(target, changes) {
return deepExtendArraySafe(result, changes, true, true);
}

function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immutable, disableCache }) {
function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immutable, disableCache, logError }) {
const resultItems = immutable === true ? [...data] : data;

changes.forEach(item => {
Expand All @@ -96,16 +96,16 @@ function applyBatch({ keyInfo, data, changes, groupCount, useInsertIndex, immuta
!disableCache && generateDataByKeyMap(keyInfo, items);

switch(item.type) {
case 'update': update(keyInfo, items, item.key, item.data, true, immutable); break;
case 'insert': insert(keyInfo, items, item.data, useInsertIndex && isDefined(item.index) ? item.index : -1, true); break;
case 'remove': remove(keyInfo, items, item.key, true); break;
case 'update': update(keyInfo, items, item.key, item.data, true, immutable, logError); break;
case 'insert': insert(keyInfo, items, item.data, useInsertIndex && isDefined(item.index) ? item.index : -1, true, logError); break;
case 'remove': remove(keyInfo, items, item.key, true, logError); break;
}
});
return resultItems;
}

function getErrorResult(isBatch, errorCode) {
return !isBatch ? rejectedPromise(errors.Error(errorCode)) : errors.log(errorCode);
function getErrorResult(isBatch, logError, errorCode) {
return !isBatch ? rejectedPromise(errors.Error(errorCode)) : logError && errors.log(errorCode);
}

function applyChanges(data, changes, options = {}) {
Expand All @@ -121,25 +121,26 @@ function applyChanges(data, changes, options = {}) {
data,
changes,
immutable,
disableCache: true
disableCache: true,
logError: true
});
}

function update(keyInfo, array, key, data, isBatch, immutable) {
function update(keyInfo, array, key, data, isBatch, immutable, logError) {
let target;
const extendComplexObject = true;
const keyExpr = keyInfo.key();

if(keyExpr) {
if(hasKey(data, keyExpr) && !keysEqual(keyExpr, key, keyInfo.keyOf(data))) {
return getErrorResult(isBatch, 'E4017');
return getErrorResult(isBatch, logError, 'E4017');
}

target = getCacheValue(array, key);
if(!target) {
const index = indexByKey(keyInfo, array, key);
if(index < 0) {
return getErrorResult(isBatch, 'E4009');
return getErrorResult(isBatch, logError, 'E4009');
}

target = array[index];
Expand All @@ -164,7 +165,7 @@ function update(keyInfo, array, key, data, isBatch, immutable) {
}
}

function insert(keyInfo, array, data, index, isBatch) {
function insert(keyInfo, array, data, index, isBatch, logError) {
let keyValue;
const keyExpr = keyInfo.key();

Expand All @@ -179,7 +180,7 @@ function insert(keyInfo, array, data, index, isBatch) {
keyValue = obj[keyExpr] = String(new Guid());
} else {
if(array[indexByKey(keyInfo, array, keyValue)] !== undefined) {
return getErrorResult(isBatch, 'E4008');
return getErrorResult(isBatch, logError, 'E4008');
}
}
} else {
Expand All @@ -198,15 +199,15 @@ function insert(keyInfo, array, data, index, isBatch) {
}
}

function remove(keyInfo, array, key, isBatch) {
function remove(keyInfo, array, key, isBatch, logError) {
const index = indexByKey(keyInfo, array, key);
if(index > -1) {
array.splice(index, 1);
}
if(!isBatch) {
return trivialPromise(key);
} else if(index < 0) {
return getErrorResult(isBatch, 'E4009');
return getErrorResult(isBatch, logError, 'E4009');
}
}

Expand Down
2 changes: 1 addition & 1 deletion js/localization/messages/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"dxSwitch-switchedOffText": "POIS",

"dxForm-optionalMark": "valinnainen",
"dxForm-requiredMessage": "{0} on valinnainen",
"dxForm-requiredMessage": "{0} on pakollinen",

"dxNumberBox-invalidValueMessage": "Arvon on oltava numero",
"dxNumberBox-noDataText": "Ei dataa",
Expand Down
62 changes: 62 additions & 0 deletions testing/tests/DevExpress.data/applyChanges.tests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { extend } from 'core/utils/extend';
import { errors } from 'data/errors';
import applyChanges from 'data/apply_changes';
import { applyBatch } from 'data/array_utils';

QUnit.module('Apply Changes', {
beforeEach: function() {
Expand Down Expand Up @@ -164,5 +165,66 @@ QUnit.module('Apply Changes', {
assert.equal(errorsLogSpy.getCall(0).args[0], 'E4008', 'insert error');
assert.equal(errorsLogSpy.getCall(1).args[0], 'E4009', 'remove error');
assert.equal(errorsLogSpy.getCall(2).args[0], 'E4009', 'update error');

errorsLogSpy.restore();
});

QUnit.test('applyBatch should not log errors when the logError parameter is not set to true', function(assert) {
// arrange
this.data = [
{
id: 1,
name: 'test1'
},
{
id: 2,
name: 'test2'
},
{
id: 3,
name: 'test3'
},
{
id: 4,
name: 'test4'
},
{
id: 5,
name: 'test5'
}
];
this.changes = [
{
type: 'insert',
data: {
id: 5,
name: 'test new'
}
},
{
type: 'remove',
key: 6
},
{
type: 'update',
key: 7,
data: {
name: 'new name'
}
}
];
const keyInfo = {
key: () => 'id',
keyOf: (obj) => obj.id
};
const errorsLogSpy = sinon.spy(errors, 'log');

// act
applyBatch({ keyInfo, data: this.data, changes: this.changes });

// assert
assert.equal(errorsLogSpy.callCount, 0, 'error.log should not be called');

errorsLogSpy.restore();
});
});

0 comments on commit 0e85543

Please sign in to comment.