jsketcher/web/app/cad/craft/craftHistoryUtils.js
2018-10-30 23:01:57 -07:00

40 lines
No EOL
843 B
JavaScript

export function addModification({history, pointer}, request) {
let changingHistory = pointer !== history.length - 1;
if (changingHistory) {
history = [
...history.slice(0, pointer+1),
request,
...history.slice(pointer+1)
];
return {
history,
pointer: ++pointer
}
} else {
return {
history: [...history, request],
pointer: ++pointer
}
}
}
export function stepOverriding({history, pointer}, request) {
history[pointer + 1] = request;
return {
history,
pointer: ++pointer
};
}
export function finishHistoryEditing({history}) {
return ({history, pointer: history.length - 1});
}
export function removeAndDropDependants({history}, indexToRemove) {
history = history.slice(0, indexToRemove);
return {
history,
pointer: history.length - 1
}
}