Skip to content

Commit 84ab4d4

Browse files
author
Zaydek Michels-Gualtieri
committed
Renamed some internals
1 parent 1b73526 commit 84ab4d4

1 file changed

Lines changed: 14 additions & 17 deletions

File tree

src/Editor/Editor.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ import "./Editor.css"
2727
noopTextContent()
2828
})()
2929

30-
// Computes a type map and array of types for a component.
31-
function getTypeInfo(component) {
30+
// Computes an array of types and type map for a pseudo-
31+
// React element.
32+
function computeTypeInfo(element) {
3233
const types = []
3334
const typeMap = {}
34-
if (typeof component === "string") {
35+
if (typeof element === "string") {
3536
return [types, typeMap]
3637
}
37-
let ref = component.type !== undefined && // NOTE: "type" can be 0
38-
component
38+
let ref = element.type !== undefined && // NOTE: "type" can be 0
39+
element
3940
while (ref) {
4041
types.push(ref.type)
4142
typeMap[ref.type] = ref
@@ -45,17 +46,16 @@ function getTypeInfo(component) {
4546
return [types, typeMap]
4647
}
4748

48-
// Decorates components; sets component.pos to "at-start",
49-
// "at-center", or "at-end" for common types.
50-
51-
function decoratePos(components) {
52-
for (let x = 0; x < components.length; x++) {
53-
if (!x || typeof components[x] === "string") {
49+
// Decorates pseudo-React elements; sets element.pos to
50+
// "at-start", "at-center", or "at-end".
51+
function decoratePos(elements) {
52+
for (let x = 0; x < elements.length; x++) {
53+
if (!x || typeof elements[x - 1] === "string" || typeof elements[x] === "string") {
5454
// No-op
5555
continue
5656
}
57-
const [types1, typeMap1] = getTypeInfo(components[x - 1])
58-
const [types2, typeMap2] = getTypeInfo(components[x])
57+
const [types1, typeMap1] = computeTypeInfo(elements[x - 1])
58+
const [types2, typeMap2] = computeTypeInfo(elements[x])
5959
const common = types1.filter(a => types2.some(b => a === b))
6060
for (const type of common) {
6161
typeMap1[type].props.pos = !typeMap1[type].props.pos ? "at-start" : "at-center"
@@ -64,11 +64,8 @@ function decoratePos(components) {
6464
}
6565
}
6666

67-
// Parses spans to psuedo-React elements.
67+
// Parses spans to pseudo-React elements.
6868
function parseSpans(spans) {
69-
// if (!spans.length) {
70-
// return null
71-
// }
7269
const elements = []
7370
for (const span of spans) {
7471
if (!span.formats.length) {

0 commit comments

Comments
 (0)