Commit f6240a82 authored by Phil Hughes's avatar Phil Hughes

improve the rendering performance by passing by reference

parent 99dc4430
import { sortTree } from './utils';
export const openFilesMap = state => state.openFiles.map(path => state.entries[path]); export const openFilesMap = state => state.openFiles.map(path => state.entries[path]);
export const changedFilesMap = state => state.changedFiles.map(path => state.entries[path]); export const changedFilesMap = state => state.changedFiles.map(path => state.entries[path]);
...@@ -21,13 +19,5 @@ export const treeList = (state) => { ...@@ -21,13 +19,5 @@ export const treeList = (state) => {
if (!tree) return []; if (!tree) return [];
const map = arr => sortTree(arr.tree.map((key) => { return tree.tree;
const entity = state.entries[key];
return {
...entity,
tree: !arr.tree.length ? [] : map(entity),
};
}));
return map(tree);
}; };
...@@ -2,25 +2,13 @@ import * as types from '../mutation_types'; ...@@ -2,25 +2,13 @@ import * as types from '../mutation_types';
export default { export default {
[types.SET_FILE_ACTIVE](state, { path, active }) { [types.SET_FILE_ACTIVE](state, { path, active }) {
Object.assign(state, { Object.assign(state.entries[path], {
entries: { active,
...state.entries,
[path]: {
...state.entries[path],
active,
},
},
}); });
}, },
[types.TOGGLE_FILE_OPEN](state, path) { [types.TOGGLE_FILE_OPEN](state, path) {
Object.assign(state, { Object.assign(state.entries[path], {
entries: { opened: !state.entries[path].opened,
...state.entries,
[path]: {
...state.entries[path],
opened: !state.entries[path].opened,
},
},
}); });
if (state.entries[path].opened) { if (state.entries[path].opened) {
...@@ -30,91 +18,49 @@ export default { ...@@ -30,91 +18,49 @@ export default {
} }
}, },
[types.SET_FILE_DATA](state, { data, file }) { [types.SET_FILE_DATA](state, { data, file }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { id: data.id,
...state.entries, blamePath: data.blame_path,
[file.path]: { commitsPath: data.commits_path,
...state.entries[file.path], permalink: data.permalink,
id: data.id, rawPath: data.raw_path,
blamePath: data.blame_path, binary: data.binary,
commitsPath: data.commits_path, renderError: data.render_error,
permalink: data.permalink,
rawPath: data.raw_path,
binary: data.binary,
renderError: data.render_error,
},
},
}); });
}, },
[types.SET_FILE_RAW_DATA](state, { file, raw }) { [types.SET_FILE_RAW_DATA](state, { file, raw }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { raw,
...state.entries,
[file.path]: {
...state.entries[file.path],
raw,
},
},
}); });
}, },
[types.UPDATE_FILE_CONTENT](state, { path, content }) { [types.UPDATE_FILE_CONTENT](state, { path, content }) {
const changed = content !== state.entries[path].raw; const changed = content !== state.entries[path].raw;
Object.assign(state, { Object.assign(state.entries[path], {
entries: { content,
...state.entries, changed,
[path]: {
...state.entries[path],
content,
changed,
},
},
}); });
}, },
[types.SET_FILE_LANGUAGE](state, { file, fileLanguage }) { [types.SET_FILE_LANGUAGE](state, { file, fileLanguage }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { fileLanguage,
...state.entries,
[file.path]: {
...state.entries[file.path],
fileLanguage,
},
},
}); });
}, },
[types.SET_FILE_EOL](state, { file, eol }) { [types.SET_FILE_EOL](state, { file, eol }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { eol,
...state.entries,
[file.path]: {
...state.entries[file.path],
eol,
},
},
}); });
}, },
[types.SET_FILE_POSITION](state, { file, editorRow, editorColumn }) { [types.SET_FILE_POSITION](state, { file, editorRow, editorColumn }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { editorRow,
...state.entries, editorColumn,
[file.path]: {
...state.entries[file.path],
editorRow,
editorColumn,
},
},
}); });
}, },
[types.DISCARD_FILE_CHANGES](state, file) { [types.DISCARD_FILE_CHANGES](state, file) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { content: state.entries[file.path].raw,
...state.entries, changed: false,
[file.path]: {
...state.entries[file.path],
content: state.entries[file.path].raw,
changed: false,
},
},
}); });
}, },
[types.CREATE_TMP_FILE](state, { file, parent }) { [types.CREATE_TMP_FILE](state, { file, parent }) {
...@@ -127,14 +73,8 @@ export default { ...@@ -127,14 +73,8 @@ export default {
state.changedFiles.splice(state.changedFiles.indexOf(path), 1); state.changedFiles.splice(state.changedFiles.indexOf(path), 1);
}, },
[types.TOGGLE_FILE_CHANGED](state, { file, changed }) { [types.TOGGLE_FILE_CHANGED](state, { file, changed }) {
Object.assign(state, { Object.assign(state.entries[file.path], {
entries: { changed,
...state.entries,
[file.path]: {
...state.entries[file.path],
changed,
},
},
}); });
}, },
}; };
...@@ -2,14 +2,8 @@ import * as types from '../mutation_types'; ...@@ -2,14 +2,8 @@ import * as types from '../mutation_types';
export default { export default {
[types.TOGGLE_TREE_OPEN](state, tree) { [types.TOGGLE_TREE_OPEN](state, tree) {
Object.assign(state, { Object.assign(state.entries[tree.path], {
entries: { opened: !state.entries[tree.path].opened,
...state.entries,
[tree.path]: {
...state.entries[tree.path],
opened: !state.entries[tree.path].opened,
},
},
}); });
}, },
[types.CREATE_TREE](state, { treePath }) { [types.CREATE_TREE](state, { treePath }) {
......
import { decorateData } from '../utils'; import {
decorateData,
sortTree,
} from '../utils';
self.addEventListener('message', (e) => { self.addEventListener('message', (e) => {
const { data, projectId, branchId } = e.data; const { data, projectId, branchId } = e.data;
...@@ -31,9 +34,9 @@ self.addEventListener('message', (e) => { ...@@ -31,9 +34,9 @@ self.addEventListener('message', (e) => {
}); });
if (parentFolder) { if (parentFolder) {
parentFolder.tree.push(tree.path); parentFolder.tree.push(tree);
} else { } else {
treeList.push(tree.path); treeList.push(tree);
} }
pathAcc.push(tree.path); pathAcc.push(tree.path);
...@@ -62,9 +65,9 @@ self.addEventListener('message', (e) => { ...@@ -62,9 +65,9 @@ self.addEventListener('message', (e) => {
}); });
if (fileFolder) { if (fileFolder) {
fileFolder.tree.push(path); fileFolder.tree.push(file);
} else { } else {
treeList.push(file.path); treeList.push(file);
} }
return acc; return acc;
...@@ -72,6 +75,6 @@ self.addEventListener('message', (e) => { ...@@ -72,6 +75,6 @@ self.addEventListener('message', (e) => {
self.postMessage({ self.postMessage({
entries, entries,
treeList, treeList: sortTree(treeList),
}); });
}); });
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