@leafer/list 1.8.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/LeafLevelList.ts +4 -3
- package/src/LeafList.ts +8 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leafer/list",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"description": "@leafer/list",
|
|
5
5
|
"author": "Chao (Leafer) Wan",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"leaferjs"
|
|
23
23
|
],
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@leafer/interface": "1.
|
|
25
|
+
"@leafer/interface": "1.9.0",
|
|
26
|
+
"@leafer/data": "1.9.0"
|
|
26
27
|
}
|
|
27
28
|
}
|
package/src/LeafLevelList.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ILeaf, ILeafArrayMap, ILeafLevelList, ILeafListItemCallback, INumberMap } from '@leafer/interface'
|
|
2
|
+
import { isArray, isUndefined } from '@leafer/data'
|
|
2
3
|
|
|
3
4
|
export class LeafLevelList implements ILeafLevelList {
|
|
4
5
|
|
|
@@ -11,15 +12,15 @@ export class LeafLevelList implements ILeafLevelList {
|
|
|
11
12
|
|
|
12
13
|
constructor(item?: ILeaf | ILeaf[]) {
|
|
13
14
|
this.reset()
|
|
14
|
-
if (item) item
|
|
15
|
+
if (item) isArray(item) ? this.addList(item) : this.add(item)
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
public has(leaf: ILeaf): boolean {
|
|
18
|
-
return this.keys[leaf.innerId]
|
|
19
|
+
return !isUndefined(this.keys[leaf.innerId])
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
public without(leaf: ILeaf): boolean {
|
|
22
|
-
return this.keys[leaf.innerId]
|
|
23
|
+
return isUndefined(this.keys[leaf.innerId])
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
public sort(reverse?: boolean): void {
|
package/src/LeafList.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ILeaf, ILeafList, ILeafListItemCallback, INumberMap } from '@leafer/interface'
|
|
2
|
+
import { isArray, isUndefined } from '@leafer/data'
|
|
2
3
|
|
|
3
4
|
export class LeafList implements ILeafList {
|
|
4
5
|
|
|
@@ -9,11 +10,11 @@ export class LeafList implements ILeafList {
|
|
|
9
10
|
|
|
10
11
|
constructor(item?: ILeaf | ILeaf[]) {
|
|
11
12
|
this.reset()
|
|
12
|
-
if (item) item
|
|
13
|
+
if (item) isArray(item) ? this.addList(item) : this.add(item)
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
public has(leaf: ILeaf): boolean {
|
|
16
|
-
return leaf && this.keys[leaf.innerId]
|
|
17
|
+
return leaf && !isUndefined(this.keys[leaf.innerId])
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
public indexAt(index: number): ILeaf {
|
|
@@ -22,13 +23,13 @@ export class LeafList implements ILeafList {
|
|
|
22
23
|
|
|
23
24
|
public indexOf(leaf: ILeaf): number {
|
|
24
25
|
const index = this.keys[leaf.innerId]
|
|
25
|
-
return index
|
|
26
|
+
return isUndefined(index) ? -1 : index
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
|
|
29
30
|
public add(leaf: ILeaf): void {
|
|
30
31
|
const { list, keys } = this
|
|
31
|
-
if (keys[leaf.innerId]
|
|
32
|
+
if (isUndefined(keys[leaf.innerId])) {
|
|
32
33
|
list.push(leaf)
|
|
33
34
|
keys[leaf.innerId] = list.length - 1
|
|
34
35
|
}
|
|
@@ -36,7 +37,7 @@ export class LeafList implements ILeafList {
|
|
|
36
37
|
|
|
37
38
|
public addAt(leaf: ILeaf, index = 0): void {
|
|
38
39
|
const { keys } = this
|
|
39
|
-
if (keys[leaf.innerId]
|
|
40
|
+
if (isUndefined(keys[leaf.innerId])) {
|
|
40
41
|
const { list } = this
|
|
41
42
|
for (let i = index, len = list.length; i < len; i++) keys[list[i].innerId]++
|
|
42
43
|
if (index === 0) {
|
|
@@ -58,7 +59,7 @@ export class LeafList implements ILeafList {
|
|
|
58
59
|
const { list } = this
|
|
59
60
|
let findIndex: number
|
|
60
61
|
for (let i = 0, len = list.length; i < len; i++) {
|
|
61
|
-
if (findIndex
|
|
62
|
+
if (!isUndefined(findIndex)) {
|
|
62
63
|
this.keys[list[i].innerId] = i - 1 // update rest keys
|
|
63
64
|
} else if (list[i].innerId === leaf.innerId) {
|
|
64
65
|
findIndex = i
|
|
@@ -66,7 +67,7 @@ export class LeafList implements ILeafList {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
|
|
69
|
-
if (findIndex
|
|
70
|
+
if (!isUndefined(findIndex)) list.splice(findIndex, 1)
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
|