Skip to content

Commit 9b73b0e

Browse files
Daniel WangYuChengKai
authored andcommitted
Fix typos in framework-en.md
1 parent 023e236 commit 9b73b0e

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Framework/framework-en.md

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,12 @@ ul.childNodes[2].remove()
294294
let fromNode = ul.childNodes[4]
295295
let toNode = node.childNodes[3]
296296
let cloneFromNode = fromNode.cloneNode(true)
297-
let cloenToNode = toNode.cloneNode(true)
297+
let cloneToNode = toNode.cloneNode(true)
298298
ul.replaceChild(cloneFromNode, toNode)
299-
ul.replaceChild(cloenToNode, fromNode)
299+
ul.replaceChild(cloneToNode, fromNode)
300300
```
301301

302-
Of course, in actual operations, we need an indentifier for each node, as an index for checking if two nodes are identical. This is why both Vue and React's official documentation suggests using a unique identifier `key` for nodes in a list to ensure efficiency.
302+
Of course, in actual operations, we need an identifier for each node, as an index for checking if two nodes are identical. This is why both Vue and React's official documentation suggests using a unique identifier `key` for nodes in a list to ensure efficiency.
303303

304304
DOM element can not only be simulated, but they can also be rendered by JS objects.
305305

@@ -393,7 +393,7 @@ We then have two steps of the algorithm.
393393

394394
First let's implement the recursion algorithm of the tree. Before doing that, let's consider the different cases of comparing two nodes.
395395

396-
1. new nodes's `tagName` or `key` is different from that of the old one. This menas the old node is replaced, and we don't have to recurse on the node any more because the whole subtree is removed.
396+
1. new node's `tagName` or `key` is different from that of the old one. This means the old node is replaced, and we don't have to recurse on the node any more because the whole subtree is removed.
397397
2. new node's `tagName` and `key` (maybe nonexistent) are the same as the old's. We start recursing on the subtree.
398398
3. no new node appears. No operation needed.
399399

@@ -403,10 +403,10 @@ import Element from './element'
403403

404404
export default function diff(oldDomTree, newDomTree) {
405405
// for recording changes
406-
let pathchs = {}
406+
let patches = {}
407407
// the index starts at 0
408-
dfs(oldDomTree, newDomTree, 0, pathchs)
409-
return pathchs
408+
dfs(oldDomTree, newDomTree, 0, patches)
409+
return patches
410410
}
411411

412412
function dfs(oldNode, newNode, index, patches) {
@@ -450,7 +450,7 @@ We also have three steps for checking for property changes
450450
function diffProps(oldProps, newProps) {
451451
// three steps for checking for props
452452
// iterate oldProps for removed properties
453-
// iterate newProps for chagned property values
453+
// iterate newProps for changed property values
454454
// lastly check if new properties are added
455455
let change = []
456456
for (const key in oldProps) {
@@ -498,7 +498,7 @@ function listDiff(oldList, newList, index, patches) {
498498
let newKeys = getKeys(newList)
499499
let changes = []
500500

501-
// for saving the node daa after changes
501+
// for saving the node data after changes
502502
// there are several advantages of using this array to save
503503
// 1. we can correctly obtain the index of the deleted node
504504
// 2. we only need to operate on the DOM once for interexchanged nodes
@@ -589,7 +589,7 @@ For this function, there are two main functionalities.
589589
1. checking differences between two lists
590590
2. marking nodes
591591

592-
In general, the functionalities impelemented are simple.
592+
In general, the functionalities implemented are simple.
593593

594594
```js
595595
function diffChildren(oldChild, newChild, index, patches) {
@@ -635,20 +635,20 @@ This code snippet is pretty easy to understand as a whole.
635635

636636
```js
637637
let index = 0
638-
export default function patch(node, patchs) {
639-
let changes = patchs[index]
638+
export default function patch(node, patches) {
639+
let changes = patches[index]
640640
let childNodes = node && node.childNodes
641641
// this deep search is the same as the one in diff algorithm
642642
if (!childNodes) index += 1
643-
if (changes && changes.length && patchs[index]) {
643+
if (changes && changes.length && patches[index]) {
644644
changeDom(node, changes)
645645
}
646646
let last = null
647647
if (childNodes && childNodes.length) {
648648
childNodes.forEach((item, i) => {
649649
index =
650650
last && last.children ? index + last.children.length + 1 : index + 1
651-
patch(item, patchs)
651+
patch(item, patches)
652652
last = item
653653
})
654654
}
@@ -688,9 +688,9 @@ function changeDom(node, changes, noChild) {
688688
let fromNode = node.childNodes[change.from]
689689
let toNode = node.childNodes[change.to]
690690
let cloneFromNode = fromNode.cloneNode(true)
691-
let cloenToNode = toNode.cloneNode(true)
691+
let cloneToNode = toNode.cloneNode(true)
692692
node.replaceChild(cloneFromNode, toNode)
693-
node.replaceChild(cloenToNode, fromNode)
693+
node.replaceChild(cloneToNode, fromNode)
694694
break
695695
default:
696696
break
@@ -717,14 +717,14 @@ let test2 = new Element('div', { id: '11' }, [test5, test4])
717717

718718
let root = test1.render()
719719

720-
let pathchs = diff(test1, test2)
721-
console.log(pathchs)
720+
let patches = diff(test1, test2)
721+
console.log(patches)
722722

723723
setTimeout(() => {
724724
console.log('start updating')
725-
patch(root, pathchs)
725+
patch(root, patches)
726726
console.log('end updating')
727727
}, 1000)
728728
```
729729

730-
Although the current implementation is simple, it's definitely enough for understanding Virtual Dom algorithms.
730+
Although the current implementation is simple, it's definitely enough for understanding Virtual Dom algorithms.

0 commit comments

Comments
 (0)