Skip to content

Commit c81cba4

Browse files
committed
Move LeafChunk/BranchChunk back to non-class constructors
So that Doc can do its auto-new trick before calling the superclass constructor. Closes codemirror#4768
1 parent 0426274 commit c81cba4

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/model/chunk.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ import { signalLater } from "../util/operation_group"
1515
//
1616
// See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
1717

18-
export class LeafChunk {
19-
constructor(lines) {
20-
this.lines = lines
21-
this.parent = null
22-
let height = 0
23-
for (let i = 0; i < lines.length; ++i) {
24-
lines[i].parent = this
25-
height += lines[i].height
26-
}
27-
this.height = height
18+
export function LeafChunk(lines) {
19+
this.lines = lines
20+
this.parent = null
21+
let height = 0
22+
for (let i = 0; i < lines.length; ++i) {
23+
lines[i].parent = this
24+
height += lines[i].height
2825
}
26+
this.height = height
27+
}
2928

30-
chunkSize() { return this.lines.length }
29+
LeafChunk.prototype = {
30+
chunkSize() { return this.lines.length },
3131

3232
// Remove the n lines at offset 'at'.
3333
removeInner(at, n) {
@@ -38,20 +38,20 @@ export class LeafChunk {
3838
signalLater(line, "delete")
3939
}
4040
this.lines.splice(at, n)
41-
}
41+
},
4242

4343
// Helper used to collapse a small branch into a single leaf.
4444
collapse(lines) {
4545
lines.push.apply(lines, this.lines)
46-
}
46+
},
4747

4848
// Insert the given array of lines at offset 'at', count them as
4949
// having the given height.
5050
insertInner(at, lines, height) {
5151
this.height += height
5252
this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at))
5353
for (let i = 0; i < lines.length; ++i) lines[i].parent = this
54-
}
54+
},
5555

5656
// Used to iterate over a part of the tree.
5757
iterN(at, n, op) {
@@ -60,21 +60,21 @@ export class LeafChunk {
6060
}
6161
}
6262

63-
export class BranchChunk {
64-
constructor(children) {
65-
this.children = children
66-
let size = 0, height = 0
67-
for (let i = 0; i < children.length; ++i) {
68-
let ch = children[i]
69-
size += ch.chunkSize(); height += ch.height
70-
ch.parent = this
71-
}
72-
this.size = size
73-
this.height = height
74-
this.parent = null
63+
export function BranchChunk(children) {
64+
this.children = children
65+
let size = 0, height = 0
66+
for (let i = 0; i < children.length; ++i) {
67+
let ch = children[i]
68+
size += ch.chunkSize(); height += ch.height
69+
ch.parent = this
7570
}
71+
this.size = size
72+
this.height = height
73+
this.parent = null
74+
}
7675

77-
chunkSize() { return this.size }
76+
BranchChunk.prototype = {
77+
chunkSize() { return this.size },
7878

7979
removeInner(at, n) {
8080
this.size -= n
@@ -98,11 +98,11 @@ export class BranchChunk {
9898
this.children = [new LeafChunk(lines)]
9999
this.children[0].parent = this
100100
}
101-
}
101+
},
102102

103103
collapse(lines) {
104104
for (let i = 0; i < this.children.length; ++i) this.children[i].collapse(lines)
105-
}
105+
},
106106

107107
insertInner(at, lines, height) {
108108
this.size += lines.length
@@ -128,7 +128,7 @@ export class BranchChunk {
128128
}
129129
at -= sz
130130
}
131-
}
131+
},
132132

133133
// When a node has grown, check whether it should be split.
134134
maybeSpill() {
@@ -151,7 +151,7 @@ export class BranchChunk {
151151
sibling.parent = me.parent
152152
} while (me.children.length > 10)
153153
me.parent.maybeSpill()
154-
}
154+
},
155155

156156
iterN(at, n, op) {
157157
for (let i = 0; i < this.children.length; ++i) {

0 commit comments

Comments
 (0)