@@ -42,7 +42,7 @@ Embora a verificação suja ser ineficiente, ele consegue completar a tarefa sem
42
42
43
43
## Sequesto de dados
44
44
45
- Vuew internamente usa ` Obeject.defineProperty() ` para implementar o two-way binding, do qual permite você escutar por eventos de ` set ` e ` get ` .
45
+ Vue internamente usa ` Obeject.defineProperty() ` para implementar o two-way binding, do qual permite você escutar por eventos de ` set ` e ` get ` .
46
46
47
47
``` js
48
48
var data = { name: ' yck' }
@@ -414,7 +414,7 @@ function dfs(oldNode, newNode, index, patches) {
414
414
// três casos
415
415
// 1. não é novo nó, não faça nada
416
416
// 2. novos nós tagName e `key` são diferentes dos antigos, substitua
417
- // 3. novos nós tagName e chave são o mesmo do antigo, comece a recursão
417
+ // 3. novos nós tagName e key são o mesmo do antigo, comece a recursão
418
418
if (! newNode) {
419
419
} else if (newNode .tag === oldNode .tag && newNode .key === oldNode .key ) {
420
420
// verifique se as propriedades mudaram
@@ -437,20 +437,20 @@ function dfs(oldNode, newNode, index, patches) {
437
437
}
438
438
```
439
439
440
- ### checking property changes
440
+ ### verificando mudança das propriedades
441
441
442
- We also have three steps for checking for property changes
442
+ Nós temos também três passos para verificar por mudanças nas propriedades
443
443
444
- 1 . iterate the old property list, check if the property still exists in the new property list .
445
- 2 . iterate the new property list, check if there are changes for properties existing in both lists .
446
- 3 . for the second step, also check if a property doesn't exist in the old property list .
444
+ 1 . itere a lista de propriedades antiga, verifique se a propriedade ainda existe na nova lista de propriedade .
445
+ 2 . itere a nova lista de propriedades, verifique se existe mudanças para propriedades existente nas duas listas .
446
+ 3 . no segundo passo, também verifique se a propriedade não existe na lista de propriedades antiga .
447
447
448
448
``` js
449
449
function diffProps (oldProps , newProps ) {
450
- // three steps for checking for props
451
- // iterate oldProps for removed properties
452
- // iterate newProps for chagned property values
453
- // lastly check if new properties are added
450
+ // três passos para checar as props
451
+ // itere oldProps para remover propriedades
452
+ // itere newProps para mudar os valores das propriedades
453
+ // por último verifique se novas propriedades foram adicionadas
454
454
let change = []
455
455
for (const key in oldProps) {
456
456
if (oldProps .hasOwnProperty (key) && ! newProps[key]) {
@@ -479,50 +479,50 @@ function diffProps(oldProps, newProps) {
479
479
}
480
480
```
481
481
482
- ### Algorithm Implementation for Detecting List Changes
482
+ ### Implementação do Algoritmo de detecção de mudanças na lista
483
483
484
- This algorithm is the core of the Virtual Dom. Let's go down the list .
485
- The main steps are similar to checking property changes. There are also three steps .
484
+ Esse algoritmo é o núcle do Virtual Dom. Vamos descer a lista .
485
+ O passo principal é similar a verificação de mudanças nas propriedades. Também existe três passos .
486
486
487
- 1 . iterate the old node list, check if the node still exists in the new list .
488
- 2 . iterate the new node list, check if there is any new node .
489
- 3 . for the second step, also check if a node moved .
487
+ 1 . itere a antiga lista de nós, verifique se ao nó ainda existe na nova lista .
488
+ 2 . itere a nova lista de nós, verifiquen se existe algum novo nó .
489
+ 3 . para o seguindo passo, também verifique se o nó moveu .
490
490
491
- PS: this algorithm only handles nodes with ` key ` s.
491
+ PS: esse algoritmo apenas manipula nós com ` key ` s.
492
492
493
493
``` js
494
494
function listDiff (oldList , newList , index , patches ) {
495
- // to make the iteration more convenient, first take all keys from both lists
495
+ // para fazer a iteração mais conveniente, primeiro pegue todas as chaves de ambas as listas
496
496
let oldKeys = getKeys (oldList)
497
497
let newKeys = getKeys (newList)
498
498
let changes = []
499
499
500
- // for saving the node daa after changes
501
- // there are several advantages of using this array to save
502
- // 1. we can correctly obtain the index of the deleted node
503
- // 2. we only need to operate on the DOM once for interexchanged nodes
504
- // 3. we only need to iterate for the checking in the `diffChildren` function
505
- // we don't need to check again for nodes existing in both lists
500
+ // para salvar o dado do nó depois das mudanças
501
+ // existe varia vantagem de usar esse array para salvar
502
+ // 1. nós conseguimos obter corretamente o index de nós deletados
503
+ // 2. precisamos apenas opera no DOM uma vez para interexchanged os nós
504
+ // 3. precisamos apenas iterar para verificar na função `diffChildren`
505
+ // nós não precisamos verificar de novo para nós existente nas duas listas
506
506
let list = []
507
507
oldList &&
508
508
oldList .forEach (item => {
509
509
let key = item .key
510
510
if (isString (item)) {
511
511
key = item
512
512
}
513
- // checking if the new children has the current node
514
- // if not then delete
513
+ // verificando se o novo filho tem o nó atual
514
+ // se não, então delete
515
515
let index = newKeys .indexOf (key)
516
516
if (index === - 1 ) {
517
517
list .push (null )
518
518
} else list .push (key)
519
519
})
520
- // array after iterative changes
520
+ // array depois de alterações iterativas
521
521
let length = list .length
522
- // since deleting array elements changes the indices
523
- // we remove from the back to make sure indices stay the same
522
+ // uma vez deletando um array de elementos, o índice muda
523
+ // removemos de trás para ter certeza que os índices permanecem o mesmo
524
524
for (let i = length - 1 ; i >= 0 ; i-- ) {
525
- // check if the current element is null, if so then it means we need to remove it
525
+ // verifica se o elemento atual é null, se sim então significa que precisamos remover ele
526
526
if (! list[i]) {
527
527
list .splice (i, 1 )
528
528
changes .push ({
@@ -531,17 +531,17 @@ function listDiff(oldList, newList, index, patches) {
531
531
})
532
532
}
533
533
}
534
- // iterate the new list, check if a node is added or moved
535
- // also add and move nodes for `list`
534
+ // itere a nova lista, verificando se um nó é adicionado ou movido
535
+ // também adicione ou mova nós para `list`
536
536
newList &&
537
537
newList .forEach ((item , i ) => {
538
538
let key = item .key
539
539
if (isString (item)) {
540
540
key = item
541
541
}
542
- // check if the old children has the current node
542
+ // verifique se o filho antigo tem o nó atual
543
543
let index = list .indexOf (key)
544
- // if not then we need to insert
544
+ // se não então precisamos inserir
545
545
if (index === - 1 || key == null ) {
546
546
changes .push ({
547
547
type: StateEnums .Insert ,
@@ -550,7 +550,7 @@ function listDiff(oldList, newList, index, patches) {
550
550
})
551
551
list .splice (i, 0 , key)
552
552
} else {
553
- // found the node, need to check if it needs to be moved .
553
+ // encontrado o nó, precisamos verificar se ele precisar ser movido .
554
554
if (index !== i) {
555
555
changes .push ({
556
556
type: StateEnums .Move ,
0 commit comments