Commit 7e390dcc authored by Tim Zallmann's avatar Tim Zallmann

Added constants for Render values + Optimised for Loop

parent 53468a77
...@@ -25,3 +25,6 @@ export const CONTEXT_LINE_CLASS_NAME = 'diff-expanded'; ...@@ -25,3 +25,6 @@ export const CONTEXT_LINE_CLASS_NAME = 'diff-expanded';
export const UNFOLD_COUNT = 20; export const UNFOLD_COUNT = 20;
export const COUNT_OF_AVATARS_IN_GUTTER = 3; export const COUNT_OF_AVATARS_IN_GUTTER = 3;
export const LENGTH_OF_AVATAR_TOOLTIP = 17; export const LENGTH_OF_AVATAR_TOOLTIP = 17;
export const LINES_TO_BE_RENDERED_DIRECTLY = 100;
export const MAX_LINES_TO_BE_RENDERED = 2000;
...@@ -2,6 +2,7 @@ import Vue from 'vue'; ...@@ -2,6 +2,7 @@ import Vue from 'vue';
import _ from 'underscore'; import _ from 'underscore';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { findDiffFile, addLineReferences, removeMatchLine, addContextLines } from './utils'; import { findDiffFile, addLineReferences, removeMatchLine, addContextLines } from './utils';
import { LINES_TO_BE_RENDERED_DIRECTLY, MAX_LINES_TO_BE_RENDERED } from '../constants';
import * as types from './mutation_types'; import * as types from './mutation_types';
export default { export default {
...@@ -17,31 +18,40 @@ export default { ...@@ -17,31 +18,40 @@ export default {
[types.SET_DIFF_DATA](state, data) { [types.SET_DIFF_DATA](state, data) {
const diffData = convertObjectPropsToCamelCase(data, { deep: true }); const diffData = convertObjectPropsToCamelCase(data, { deep: true });
let showingLines = 0; let showingLines = 0;
diffData.diffFiles.forEach(file => { const filesLength = diffData.diffFiles.length;
let i;
for (i = 0; i < filesLength; i += 1) {
const file = diffData.diffFiles[i];
if (file.parallelDiffLines) { if (file.parallelDiffLines) {
file.parallelDiffLines.forEach(line => { const linesLength = file.parallelDiffLines.length;
let u = 0;
for (u = 0; u < linesLength; u += 1) {
const line = file.parallelDiffLines[u];
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
if (line.left) delete line.left.text; if (line.left) delete line.left.text;
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
if (line.right) delete line.right.text; if (line.right) delete line.right.text;
}); }
} }
if (file.highlightedDiffLines) { if (file.highlightedDiffLines) {
file.highlightedDiffLines.forEach(line => { const linesLength = file.highlightedDiffLines.length;
let u = 0;
for (u = 0; u < linesLength; u += 1) {
const line = file.highlightedDiffLines[u];
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
delete line.text; delete line.text;
}); }
} }
if (file.highlightedDiffLines) { if (file.highlightedDiffLines) {
showingLines += file.parallelDiffLines.length; showingLines += file.parallelDiffLines.length;
} }
Object.assign(file, { Object.assign(file, {
renderIt: showingLines < 200, renderIt: showingLines < LINES_TO_BE_RENDERED_DIRECTLY,
collapsed: file.text && showingLines > 2000, collapsed: file.text && showingLines > MAX_LINES_TO_BE_RENDERED,
}); });
}); }
Object.assign(state, { Object.assign(state, {
...diffData, ...diffData,
......
import mutations from '~/diffs/store/mutations'; import mutations from '~/diffs/store/mutations';
import * as types from '~/diffs/store/mutation_types'; import * as types from '~/diffs/store/mutation_types';
import { INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants'; import { INLINE_DIFF_VIEW_TYPE } from '~/diffs/constants';
import diffFileMockData from '../mock_data/diff_file';
describe('DiffsStoreMutations', () => { describe('DiffsStoreMutations', () => {
describe('SET_BASE_CONFIG', () => { describe('SET_BASE_CONFIG', () => {
...@@ -24,6 +25,23 @@ describe('DiffsStoreMutations', () => { ...@@ -24,6 +25,23 @@ describe('DiffsStoreMutations', () => {
}); });
}); });
describe('SET_DIFF_DATA', () => {
it('should set diff data type properly', () => {
const state = {};
const diffMock = {
diff_files: [diffFileMockData],
};
mutations[types.SET_DIFF_DATA](state, diffMock);
const firstLine = state.diffFiles[0].parallelDiffLines[0];
expect(firstLine.right.text).toBeUndefined();
expect(state.diffFiles[0].renderIt).toEqual(true);
expect(state.diffFiles[0].collapsed).toEqual(false);
});
});
describe('SET_DIFF_VIEW_TYPE', () => { describe('SET_DIFF_VIEW_TYPE', () => {
it('should set diff view type properly', () => { it('should set diff view type properly', () => {
const state = {}; const state = {};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment