From 18839fde817bec8674cfe3b838a3b34615c22a8e Mon Sep 17 00:00:00 2001 From: catarak Date: Fri, 2 Sep 2016 12:01:23 -0400 Subject: [PATCH] start to add methods for deleting file recursively --- client/modules/IDE/reducers/files.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/client/modules/IDE/reducers/files.js b/client/modules/IDE/reducers/files.js index 1ae9713a..8ada98c8 100644 --- a/client/modules/IDE/reducers/files.js +++ b/client/modules/IDE/reducers/files.js @@ -69,6 +69,28 @@ function initialState() { }]; } +function getAllDescendantIds(state, nodeId) { + return state.find(file => file.id === nodeId).children + .reduce((acc, childId) => ( + [...acc, childId, ...getAllDescendantIds(state, childId)] + ), []); +} + +function deleteMany(state, ids) { + const newState = [...state]; + ids.forEach(id => { + let fileIndex; + newState.find((file, index) => { + if (file.id === id) { + fileIndex = index; + } + return file.id === id; + }); + newState.splice(fileIndex, 1); + }); + return newState; +} + const files = (state, action) => { if (state === undefined) { state = initialState(); // eslint-disable-line