Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswilm committed Apr 5, 2024
1 parent c8699d2 commit 0fef160
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 169 deletions.
2 changes: 1 addition & 1 deletion browser/diffDOM.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/TraceLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class TraceLogger {
| number
| boolean
| false
| (string | HTMLElement | number | boolean | false)[],
| (string | HTMLElement | number | boolean | false)[]
) {
this.padding += this.pad
this.log(`├─> entering ${fn}`, args)
Expand All @@ -79,12 +79,12 @@ export class TraceLogger {
| number
| boolean
| false
| (string | HTMLElement | number | boolean | false)[],
| (string | HTMLElement | number | boolean | false)[]
) {
this.log("│<──┘ generated return value", result)
this.padding = this.padding.substring(
0,
this.padding.length - this.pad.length,
this.padding.length - this.pad.length
)
}
// log message formatting
Expand All @@ -107,7 +107,7 @@ export class TraceLogger {
| number
| boolean
| false
| (string | HTMLElement | number | boolean | false)[],
| (string | HTMLElement | number | boolean | false)[]
) {
if (!v) {
return "<falsey>"
Expand Down
34 changes: 17 additions & 17 deletions src/diffDOM/dom/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { objToNode } from "./fromVirtual"

const getFromRoute = (
node: Element,
route: number[],
route: number[]
): Element | Text | false => {
route = route.slice()
while (route.length > 0) {
Expand All @@ -20,15 +20,15 @@ const getFromRoute = (
export function applyDiff(
tree: Element,
diff: diffType,
options: DiffDOMOptions, // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}
options: DiffDOMOptions // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}
) {
const action = diff[options._const.action] as string | number
const route = diff[options._const.route] as number[]
let node

if (
![options._const.addElement, options._const.addTextElement].includes(
action,
action
)
) {
// For adding nodes, we calculate the route later on. It's different because it includes the position of the newly added item.
Expand Down Expand Up @@ -56,7 +56,7 @@ export function applyDiff(
}
node.setAttribute(
diff[options._const.name] as string,
diff[options._const.value] as string,
diff[options._const.value] as string
)
break
case options._const.modifyAttribute:
Expand All @@ -65,7 +65,7 @@ export function applyDiff(
}
node.setAttribute(
diff[options._const.name] as string,
diff[options._const.newValue] as string,
diff[options._const.newValue] as string
)
if (
checkElementType(node, "HTMLInputElement") &&
Expand All @@ -88,7 +88,7 @@ export function applyDiff(
node,
node.data,
diff[options._const.oldValue] as string,
diff[options._const.newValue] as string,
diff[options._const.newValue] as string
)
if (checkElementType(node.parentNode, "HTMLTextAreaElement")) {
node.parentNode.value = diff[options._const.newValue] as string
Expand All @@ -108,7 +108,7 @@ export function applyDiff(
node,
node.data,
diff[options._const.oldValue] as string,
diff[options._const.newValue] as string,
diff[options._const.newValue] as string
)
break
case options._const.modifyChecked:
Expand All @@ -133,19 +133,19 @@ export function applyDiff(
objToNode(
diff[options._const.newValue] as nodeType,
insideSvg,
options,
options
),
node,
node
)
break
}
case options._const.relocateGroup:
nodeArray = Array(
...new Array(diff[options._const.groupLength]),
...new Array(diff[options._const.groupLength])
).map(() =>
node.removeChild(
node.childNodes[diff[options._const.from] as number],
),
node.childNodes[diff[options._const.from] as number]
)
)
nodeArray.forEach((childNode, index) => {
if (index === 0) {
Expand All @@ -169,9 +169,9 @@ export function applyDiff(
objToNode(
diff[options._const.element] as nodeType,
node.namespaceURI === "http://www.w3.org/2000/svg",
options,
options
),
node.childNodes[c] || null,
node.childNodes[c] || null
)
break
}
Expand All @@ -190,7 +190,7 @@ export function applyDiff(
const parentRoute = route.slice()
const c: number = parentRoute.splice(parentRoute.length - 1, 1)[0]
newNode = options.document.createTextNode(
diff[options._const.value] as string,
diff[options._const.value] as string
)
node = getFromRoute(tree, parentRoute)
if (!node.childNodes) {
Expand Down Expand Up @@ -220,9 +220,9 @@ export function applyDiff(
export function applyDOM(
tree: Element,
diffs: (Diff | diffType)[],
options: DiffDOMOptions,
options: DiffDOMOptions
) {
return diffs.every((diff: Diff | diffType) =>
applyDiff(tree, diff as diffType, options),
applyDiff(tree, diff as diffType, options)
)
}
12 changes: 6 additions & 6 deletions src/diffDOM/dom/fromVirtual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { checkElementType } from "../helpers"
export function objToNode(
objNode: elementNodeType,
insideSvg: boolean,
options: DiffDOMOptions,
options: DiffDOMOptions
) {
let node: Element | Text | Comment
if (objNode.nodeName === "#text") {
Expand All @@ -15,30 +15,30 @@ export function objToNode(
if (insideSvg) {
node = options.document.createElementNS(
"http://www.w3.org/2000/svg",
objNode.nodeName,
objNode.nodeName
)
if (objNode.nodeName === "foreignObject") {
insideSvg = false
}
} else if (objNode.nodeName.toLowerCase() === "svg") {
node = options.document.createElementNS(
"http://www.w3.org/2000/svg",
"svg",
"svg"
)
insideSvg = true
} else {
node = options.document.createElement(objNode.nodeName)
}
if (objNode.attributes) {
Object.entries(objNode.attributes).forEach(([key, value]) =>
(node as Element).setAttribute(key, value),
(node as Element).setAttribute(key, value)
)
}
if (objNode.childNodes) {
node = node as Element
objNode.childNodes.forEach(
(childNode: elementNodeType | textNodeType) =>
node.appendChild(objToNode(childNode, insideSvg, options)),
node.appendChild(objToNode(childNode, insideSvg, options))
)
}
if (options.valueDiffing) {
Expand All @@ -53,7 +53,7 @@ export function objToNode(
"HTMLMeterElement",
"HTMLOptionElement",
"HTMLProgressElement",
"HTMLParamElement",
"HTMLParamElement"
)
) {
;(
Expand Down
4 changes: 2 additions & 2 deletions src/diffDOM/dom/undo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function swap(obj: object, p1: string | number, p2: string | number) {
function undoDiff(
tree: Element,
diff: diffType,
options: DiffDOMOptions, // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}
options: DiffDOMOptions // {preDiffApply, postDiffApply, textDiff, valueDiffing, _const}
) {
switch (diff[options._const.action]) {
case options._const.addAttribute:
Expand Down Expand Up @@ -80,7 +80,7 @@ function undoDiff(
export function undoDOM(
tree: Element,
diffs: (diffType | Diff)[],
options: DiffDOMOptions,
options: DiffDOMOptions
) {
diffs = diffs.slice()
diffs.reverse()
Expand Down
4 changes: 2 additions & 2 deletions src/diffDOM/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Diff {
| boolean
| number[]
| { [key: string]: string | { [key: string]: string } }
| elementNodeType,
| elementNodeType
) {
this[aKey] = aValue
return this
Expand All @@ -35,6 +35,6 @@ export function checkElementType(element, ...elementTypeNames: string[]) {
typeof element?.ownerDocument?.defaultView?.[elementTypeName] ===
"function" &&
element instanceof
element.ownerDocument.defaultView[elementTypeName],
element.ownerDocument.defaultView[elementTypeName]
)
}
6 changes: 3 additions & 3 deletions src/diffDOM/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_OPTIONS = {
node: textNodeType,
currentValue: string,
expectedValue: string,
newValue: string,
newValue: string
) {
node.data = newValue
return
Expand Down Expand Up @@ -92,7 +92,7 @@ export class DiffDOM {
const constNames: ConstNamesPartial = {}
if (options.compress) {
varNames.forEach(
(varName, index) => (constNames[varName] = index),
(varName, index) => (constNames[varName] = index)
)
} else {
varNames.forEach((varName) => (constNames[varName] = varName))
Expand All @@ -113,7 +113,7 @@ export class DiffDOM {

diff(
t1Node: string | elementNodeType | Element,
t2Node: string | elementNodeType | Element,
t2Node: string | elementNodeType | Element
) {
const finder = new DiffFinder(t1Node, t2Node, this.options)
return finder.init()
Expand Down
2 changes: 1 addition & 1 deletion src/diffDOM/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ interface DiffDOMOptions {
node: textNodeType | Text | Comment,
currentValue: string,
expectedValue: string,
newValue: string,
newValue: string
) => void
preVirtualDiffApply: PreDiffApply
postVirtualDiffApply: PostDiffApply
Expand Down
12 changes: 6 additions & 6 deletions src/diffDOM/virtual/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ function getFromVirtualRoute(tree: elementNodeType, route: number[]) {
function applyVirtualDiff(
tree: elementNodeType,
diff: Diff,
options: DiffDOMOptions, // {preVirtualDiffApply, postVirtualDiffApply, _const}
options: DiffDOMOptions // {preVirtualDiffApply, postVirtualDiffApply, _const}
) {
let node, parentNode, nodeIndex

if (
![options._const.addElement, options._const.addTextElement].includes(
diff[options._const.action],
diff[options._const.action]
)
) {
// For adding nodes, we calculate the route later on. It's different because it includes the position of the newly added item.
Expand Down Expand Up @@ -126,11 +126,11 @@ function applyVirtualDiff(
nodeArray = node.childNodes
.splice(
diff[options._const.from],
diff[options._const.groupLength],
diff[options._const.groupLength]
)
.reverse()
nodeArray.forEach((movedNode: nodeType) =>
node.childNodes.splice(diff[options._const.to], 0, movedNode),
node.childNodes.splice(diff[options._const.to], 0, movedNode)
)
if (node.subsets) {
node.subsets.forEach((map: subsetType) => {
Expand Down Expand Up @@ -321,7 +321,7 @@ function applyVirtualDiff(

if (node.subsets) {
node.subsets = node.subsets.filter(
(map: subsetType) => !map.delete && map.oldValue !== map.newValue,
(map: subsetType) => !map.delete && map.oldValue !== map.newValue
)
if (newSubsets.length) {
node.subsets = node.subsets.concat(newSubsets)
Expand All @@ -340,7 +340,7 @@ function applyVirtualDiff(
export function applyVirtual(
tree: elementNodeType,
diffs: Diff[],
options: DiffDOMOptions,
options: DiffDOMOptions
) {
diffs.forEach((diff: Diff) => {
applyVirtualDiff(tree, diff, options)
Expand Down
Loading

0 comments on commit 0fef160

Please sign in to comment.