ow
This commit is contained in:
1 parent
1404640f16
commit
2bbf016cbf
167 files changed
+18941
-589
No files matched your search
@@ -0,0 +1,23 @@
|
||||
import { shallowRef } from "vue";
|
||||
|
||||
export const useOrderedChildren = <T extends { uid: number }>() => {
|
||||
const children: Record<number, T> = {};
|
||||
const orderedChildren = shallowRef<T[]>([]);
|
||||
|
||||
const addChild = (child: T) => {
|
||||
children[child.uid] = child;
|
||||
orderedChildren.value.push(child);
|
||||
};
|
||||
const removeChild = (uid: number) => {
|
||||
delete children[uid];
|
||||
orderedChildren.value = orderedChildren.value.filter(
|
||||
(child) => child.uid !== uid
|
||||
);
|
||||
};
|
||||
|
||||
return {
|
||||
children: orderedChildren,
|
||||
addChild,
|
||||
removeChild,
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user