Skip to content

Commit 6614066

Browse files
authored
Merge branch 'master' into master
2 parents bd8e322 + f2a3824 commit 6614066

14 files changed

+2648
-200
lines changed

Algorithm/algorithm-ch.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102
```js
103103
8 ^ 7 // -> 15
104104
8 ^ 8 // -> 0
105-
// 1000 & 0111 -> 1111 -> 15
106-
// 1000 & 1000 -> 0000 -> 0
105+
// 1000 ^ 0111 -> 1111 -> 15
106+
// 1000 ^ 1000 -> 0000 -> 0
107107
```
108108

109109
从以上代码中可以发现按位异或就是不进位加法

Algorithm/algorithm-en.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Shift arithmetic left is to move all the binary to the left, `10` is represented
3131
10 >> 1 // -> 5
3232
```
3333

34-
The right shift of the arithmetic is to move all the binary to the right and remove the extra right. `10` is represented as `1010` in binary, and becomes `101` after shifting one bit to the right, and converted to decimal is 5, so the right shift is seen as the following formula `a >> b => a / (2 ^ b)` by basically.
34+
The bitwise right shift moves all the binary digits to the right and remove the extra left digit. `10` is represented as `1010` in binary, and becomes `101` after shifting one bit to the right, and becomes 5 in decimal value, so the right shift is basically the following formula: `a >> b => a / (2 ^ b)`.
3535

3636
Right shift is very useful, for example, you can calculate the intermediate value in the binary algorithm.
3737

@@ -66,8 +66,8 @@ Each bit is different, and the result is 1
6666
```js
6767
8 ^ 7 // -> 15
6868
8 ^ 8 // -> 0
69-
// 1000 & 0111 -> 1111 -> 15
70-
// 1000 & 1000 -> 0000 -> 0
69+
// 1000 ^ 0111 -> 1111 -> 15
70+
// 1000 ^ 1000 -> 0000 -> 0
7171
```
7272

7373
From the above code, we can find that the bitwise XOR is the not carry addition.
@@ -863,4 +863,4 @@ In the string correlation algorithm, Trie tree can solve many problems, and has
863863
- Word frequency statistics
864864
- Prefix matching
865865

866-
If you don't know much about the Trie tree, you can go [here](../DataStruct/dataStruct-zh.md#trie) to read
866+
If you don't know much about the Trie tree, you can go [here](../DataStruct/dataStruct-zh.md#trie) to read

Browser/browser-ch.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737
事件触发有三个阶段
3838

39-
- `document` 往事件触发处传播,遇到注册的捕获事件会触发
39+
- `window` 往事件触发处传播,遇到注册的捕获事件会触发
4040
- 传播到事件触发处时触发注册的事件
41-
- 从事件触发处往 `document` 传播,遇到注册的冒泡事件会触发
41+
- 从事件触发处往 `window` 传播,遇到注册的冒泡事件会触发
4242

4343
事件触发一般来说会按照上面的顺序进行,但是也有特例,如果给一个目标节点同时注册冒泡和捕获事件,事件触发会按照注册的顺序执行。
4444

Framework/framework-en.md

+20-20
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.

JS/JS-br.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,7 @@ Quando lidando com uma função ou `undefined`, o objeto pode não ser serializa
603603
```js
604604
let a = {
605605
age: undefined,
606+
sex: Symbol('male'),
606607
jobs: function() {},
607608
name: 'yck'
608609
}
@@ -627,9 +628,12 @@ function structuralClone(obj) {
627628
var obj = {a: 1, b: {
628629
c: b
629630
}}
631+
630632
// preste atenção que esse método é assíncrono
631633
// ele consegue manipular `undefined` e referência circular do objeto
632-
const clone = await structuralClone(obj);
634+
(async () => {
635+
const clone = await structuralClone(obj)
636+
})()
633637
```
634638
635639
# Modularização

0 commit comments

Comments
 (0)