1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-17 07:41:26 +00:00

revert component file

This commit is contained in:
shanshuirenjia
2019-05-06 14:59:42 +08:00
parent a82d70a18a
commit 690cd7a4c7
3 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import OperationTypes from './operation-types';
import GridColumn from '../model/grid-column';
import GridRow from '../model/grid-row';
function apply(value, op) {
let { type } = op;
let next = value.slice(0); // clone a copy
switch(type) {
case OperationTypes.DELETE_ROW : {
let { rowIdx } = op;
next.splice(rowIdx, 1);
return next;
}
case OperationTypes.INSERT_ROW : {
let { newRowIdx } = op;
let row = new GridRow({newRowIdx});
next.push(row);
return next;
}
case OperationTypes.DELETE_COLUMN : {
let { idx } = op;
next.splice(idx, 1);
return next;
}
case OperationTypes.INSERT_COLUMN : {
let { idx, columnName, columnType } = op;
let column = new GridColumn({idx, columnName, columnType});
next.push(column);
return next;
}
case OperationTypes.MODIFY_CELL : {
let { rowIdx, key, newCellValue } = op;
next[rowIdx][key] = newCellValue;
return next;
}
case OperationTypes.MODIFY_COLUMN : {
let { idx, newColumnName } = op;
next[idx]['key'] = newColumnName;
next[idx]['name'] = newColumnName;
return next;
}
}
}
export default apply;

View File

@@ -0,0 +1,35 @@
import Operation from './operation';
import OperationTypes from './operation-types';
function invert(operation) {
let op = new Operation(operation);
let { type } = operation;
switch(type) {
case OperationTypes.DELETE_COLUMN : {
op.type = OperationTypes.INSERT_COLUMN;
return op;
}
case OperationTypes.INSERT_COLUMN : {
op.type = OperationTypes.DELETE_COLUMN;
return op;
}
case OperationTypes.DELETE_ROW : {
op.type = OperationTypes.INSERT_ROW;
return op;
}
case OperationTypes.INSERT_ROW : {
op.type = OperationTypes.DELETE_ROW;
return op;
}
default :
break;
}
}
export default invert;

View File

@@ -0,0 +1,20 @@
import apply from './apply';
import invert from './invert';
export default class Operation {
constructor(operation) {
this.operation = operation;
}
apply(value) {
let next = apply(value, this.operation);
return next;
}
invert() {
let inverted = invert(this);
return inverted;
}
}