8000 [util] seperate state changes function · codemic-pl/react-sortablejs@2c2b7b1 · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 6, 2024. It is now read-only.

Commit 2c2b7b1

Browse files
author
Wayne Van Son
committed
[util] seperate state changes function
1 parent 79e5af0 commit 2c2b7b1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/util.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,29 @@ export function handleDOMChanges<T extends ItemInterface>(
4444
export function handleStateChanges<T extends ItemInterface>(
4545
normalized: Normalized<T>[],
4646
list: T[]
47+
): T[] {
48+
const a = handleStateRemove(normalized, list);
49+
const b = handleStateAdd(normalized, a);
50+
return b;
51+
}
52+
53+
export function handleStateRemove<T extends ItemInterface>(
54+
normalized: Normalized<T>[],
55+
list: T[]
4756
): T[] {
4857
const newList = [...list];
4958
normalized
5059
.concat()
5160
.reverse()
5261
.forEach(curr => newList.splice(curr.oldIndex, 1));
62+
return newList;
63+
}
64+
65+
export function handleStateAdd<T extends ItemInterface>(
66+
normalized: Normalized<T>[],
67+
list: T[]
68+
): T[] {
69+
const newList = [...list];
5370
normalized.forEach(curr => newList.splice(curr.newIndex, 0, curr.item));
5471
return newList;
5572
}

0 commit comments

Comments
 (0)
0