Skip to content

Commit c069b1f

Browse files
committed
fix(Caching#orderFolder): Fix orderFolder algorithm
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 761955e commit c069b1f

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/lib/adapters/Caching.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,12 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
182182
if (!folder) {
183183
throw new UnknownFolderOrderError()
184184
}
185+
let newChildren = []
185186
order.forEach(item => {
186187
const child = folder.findItem(item.type, item.id)
187188
if (!child || String(child.parentId) !== String(folder.id)) {
188189
throw new UnknownFolderItemOrderError(id + ':' + JSON.stringify(item))
189190
}
190-
})
191-
let newChildren = []
192-
order.forEach(item => {
193-
const child = folder.findItem(item.type, item.id)
194191
newChildren.push(child)
195192
})
196193
const diff = difference(folder.children.map(i => i.type + ':' + i.id), order.map(i => i.type + ':' + i.id))
@@ -201,8 +198,9 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
201198
diff.forEach(item => {
202199
const [type, id] = item.split(':')
203200
const child = folder.findItem(type, id)
201+
if (!child) return
204202
const index = folder.children.indexOf(child)
205-
newChildren = newChildren.slice(0, index - 1).concat([child], newChildren.slice(index - 1))
203+
newChildren = newChildren.slice(0, index).concat([child], newChildren.slice(index))
206204
})
207205
}
208206
folder.children = newChildren

0 commit comments

Comments
 (0)