Skip to content

Commit 86d70a3

Browse files
committed
Add JSDoc comments to tree component methods
1 parent bd124cb commit 86d70a3

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

src/index.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ const configurable = true;
1616
/* Служебные функции */
1717
/* -------------------------------------------------------------------------- */
1818

19+
/**
20+
*
21+
* @param siblings
22+
* @param parent
23+
*/
1924
const getItems = (siblings: unObject[], parent?: unObject) =>
2025
[...siblings].reverse().map((node) => ({ node, parent, siblings })),
2126
uid = () => {
@@ -29,6 +34,19 @@ const getItems = (siblings: unObject[], parent?: unObject) =>
2934
/* Композабл для работы с древовидным объектом */
3035
/* -------------------------------------------------------------------------- */
3136

37+
/**
38+
*
39+
* @param tree
40+
* @param root0
41+
* @param root0.branch
42+
* @param root0.children
43+
* @param root0.id
44+
* @param root0.index
45+
* @param root0.next
46+
* @param root0.parent
47+
* @param root0.prev
48+
* @param root0.siblings
49+
*/
3250
export default (
3351
tree: unObject[],
3452
{
@@ -48,27 +66,39 @@ export default (
4866

4967
const properties: PropertyDescriptorMap = {
5068
[keyBranch]: {
69+
/**
70+
*
71+
*/
5172
get(this: unObject) {
5273
const ret = [this];
5374
while (ret[0]?.[keyParent]) ret.unshift(ret[0][keyParent] as unObject);
5475
return ret;
5576
},
5677
},
5778
[keyIndex]: {
79+
/**
80+
*
81+
*/
5882
get(this: unObject) {
5983
return (this[keySiblings] as unObject[]).findIndex(
6084
(sibling) => this[keyId] === sibling[keyId],
6185
);
6286
},
6387
},
6488
[keyNext]: {
89+
/**
90+
*
91+
*/
6592
get(this: unObject) {
6693
return (this[keySiblings] as unObject[])[
6794
(this[keyIndex] as number) + 1
6895
];
6996
},
7097
},
7198
[keyPrev]: {
99+
/**
100+
*
101+
*/
72102
get(this: unObject) {
73103
return (this[keySiblings] as unObject[])[
74104
(this[keyIndex] as number) - 1
@@ -81,6 +111,10 @@ export default (
81111
/* Формирование массива элементов дерева простого и ассоциативного */
82112
/* -------------------------------------------------------------------------- */
83113

114+
/**
115+
*
116+
* @param nodes
117+
*/
84118
const getNodes = function* (nodes: unObject[]) {
85119
const stack = getItems(nodes);
86120
while (stack.length) {
@@ -118,6 +152,11 @@ export default (
118152
/* Служебная функция для выполнения действия над элементом дерева */
119153
/* -------------------------------------------------------------------------- */
120154

155+
/**
156+
*
157+
* @param pId
158+
* @param action
159+
*/
121160
const run = (pId: string, action: string) => {
122161
const the = nodesMap.value[pId];
123162
if (the) {
@@ -195,14 +234,42 @@ export default (
195234
/* -------------------------------------------------------------------------- */
196235

197236
return {
237+
/**
238+
*
239+
* @param pId
240+
*/
198241
add: (pId: string) => run(pId, "add"),
242+
/**
243+
*
244+
* @param pId
245+
*/
199246
addChild: (pId: string) => run(pId, "addChild"),
247+
/**
248+
*
249+
* @param pId
250+
*/
200251
down: (pId: string) => run(pId, "down"),
252+
/**
253+
*
254+
* @param pId
255+
*/
201256
left: (pId: string) => run(pId, "left"),
202257
nodes,
203258
nodesMap,
259+
/**
260+
*
261+
* @param pId
262+
*/
204263
remove: (pId: string) => run(pId, "remove"),
264+
/**
265+
*
266+
* @param pId
267+
*/
205268
right: (pId: string) => run(pId, "right"),
269+
/**
270+
*
271+
* @param pId
272+
*/
206273
up: (pId: string) => run(pId, "up"),
207274
};
208275
};

0 commit comments

Comments
 (0)