Skip to content

Commit 0721bbe

Browse files
committed
UPDATE
1 parent f18ada9 commit 0721bbe

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

Framework/react-br.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ class ExampleComponent extends React.Component {
6767

6868
`getSnapshotBeforeUpdate` é usado para substituir o `componentWillUpdate`, do qual é chamado depois do `update` mas antes do DOM atualizar para leitura o último dado do DOM.
6969

70-
## O conselho usado dos metodos do ciclos de vida no React V16
71-
72-
## The usage advice of Lifecycle methods in React V16
70+
## O conselho usado nos métodos do ciclo de vida no React V16
7371

7472
```js
7573
class ExampleComponent extends React.Component {
@@ -79,23 +77,23 @@ class ExampleComponent extends React.Component {
7977
// Porque a função é estática, você não pode acessar o `this`
8078
// Se você precisar comparar `prevProps`, você precisa manter ele separado no `state`
8179
static getDerivedStateFromProps(nextProps, prevState) {}
82-
// Determine whether you need to update components, mostly for component performance optimization
80+
// Determina se você precisa atualizar os componentes, usado na maioria das vezes para otimização de performance do componente
8381
shouldComponentUpdate(nextProps, nextState) {}
84-
// Called after the component is mounted
85-
// Can request or subscribe in this function
82+
// Chamado depois do componente ser montado
83+
// Pode requisitar ou subscrever nessa função
8684
componentDidMount() {}
87-
// Used to get the latest DOM data
85+
// Obter o último dado do DOM
8886
getSnapshotBeforeUpdate() {}
89-
// Component is about to be destroyed
90-
// Can remove subscriptions, timers, etc. here
87+
// É sobre o componente ser destruido
88+
// Pode remover subscrições, timers, etc.
9189
componentWillUnmount() {}
92-
// Called after the component is destroyed
90+
// Chamado depois do componente ser destruido
9391
componentDidUnMount() {}
94-
// Called after component update
92+
// Chamado depois da atualização do componente
9593
componentDidUpdate() {}
96-
// render component
94+
// renderiza o componente
9795
render() {}
98-
// The following functions are not recommended
96+
// As seguintes funções não são recomendadas
9997
UNSAFE_componentWillMount() {}
10098
UNSAFE_componentWillUpdate(nextProps, nextState) {}
10199
UNSAFE_componentWillReceiveProps(nextProps) {}
@@ -104,13 +102,13 @@ class ExampleComponent extends React.Component {
104102

105103
# setState
106104

107-
`setState` is an API that is often used in React, but it has some problems that can lead to mistakes. The core reason is that the API is asynchronous.
105+
`setState` é uma API que é frequentemente usada no React, mas ele tem alguns problemas que podem levar a erros. O centro das razões é que a API é assíncrona.
108106

109-
First, calling `setState` does not immediately cause a change to `state`, and if you call multiple `setState` at a time, the result may not be as you expect.
107+
Primeiro, chamando `setState` não casa mudança imediata no `state`, e se você chamar multiplos `setState` de uma vez, o resultado pode não ser como o esperado.
110108

111109
```js
112110
handle() {
113-
// Initialize `count` to 0
111+
// Iniciado o `count` em 0
114112
console.log(this.state.count) // -> 0
115113
this.setState({ count: this.state.count + 1 })
116114
this.setState({ count: this.state.count + 1 })
@@ -119,9 +117,10 @@ handle() {
119117
}
120118
```
121119

122-
First, both prints are 0, because `setState` is an asynchronous API and will only execute after the sync code has finished running. The reason for `setState` is asynchronous is that `setState` may cause repainting of the DOM. If the call is repainted immediately after the call, the call will cause unnecessary performance loss. Designed to be asynchronous, you can put multiple calls into a queue and unify the update process when appropriate.
120+
Primeiro, ambos os prints são 0, porque o `setState` é uma API assíncrona e irá apenas executar depois do código síncrono terminar sua execução. O motivo para o `setState` ser assíncrono é que `setState` pode causar repintar no DOM. Se a chamada repintar imediatamente depois da chamada, a chamada vai causar uma perca de performance desnecessária. Desenhando para ser assíncrono, você pode colocar multiplas chamadas dentro da fila e unificar os processos de atualização quando apropriado.
121+
122+
Segundo, apesar do `setState` ser chamado três vezes, o valor do `count` ainda é 1. Porque multiplas chamadas são fundidas em uma, o `state` só vai mudar quando a atualização terminar, e três chamadas são equivalente para o seguinte código.
123123

124-
Second, although `setState` is called three times, the value of `count` is still 1. Because multiple calls are merged into one, only `state` will change when the update ends, and three calls are equivalent to the following code.
125124

126125
```js
127126
Object.assign(
@@ -132,7 +131,7 @@ Object.assign(
132131
)
133132
```
134133

135-
Of course, you can also call `setState` three times by the following way to make `count` 3
134+
De fato, você pode também chamar `setState` três vezes da seguinte maneira para fazer `count` 3
136135

137136
```js
138137
handle() {
@@ -142,7 +141,8 @@ handle() {
142141
}
143142
```
144143

145-
If you want to get the correct `state` after each call to `setState`, you can do it with the following code:
144+
Se você quer acessar o `state` correto depois de cada chamada ao `setState`, você pode fazer isso com o seguinte código:
145+
146146

147147
```js
148148
handle() {
@@ -151,20 +151,20 @@ handle() {
151151
})
152152
}
153153
```
154-
# Redux Source Code Analysis
154+
# Análise de código do Redux
155155

156-
Let's take a look at the `combineReducers` function first.
156+
Vamos dar uma olhada na função `combineReducers` primeiro.
157157

158158
```js
159-
// pass an object
159+
// passe um objeto
160160
export default function combineReducers(reducers) {
161-
// get this object's keys
161+
// capture as chaves desse objeto
162162
const reducerKeys = Object.keys(reducers)
163-
// reducers after filtering
163+
// reducers depois filtrados
164164
const finalReducers = {}
165-
// get the values corresponding to every key
166-
// in dev environment, check if the value is undefined
167-
// then put function type values into finalReducers
165+
// obtenha os valores correspondentes para cada chave
166+
// no ambiente de desenvolvimento, verifique se o valor é undefined
167+
// então coloque os valores do tipo de função dentro do finalReducers
168168
for (let i = 0; i < reducerKeys.length; i++) {
169169
const key = reducerKeys[i]
170170

@@ -178,25 +178,25 @@ export default function combineReducers(reducers) {
178178
finalReducers[key] = reducers[key]
179179
}
180180
}
181-
// get the keys of the reducers after filtering
181+
// obtenha as chaves dos reducers depois de filtrado
182182
const finalReducerKeys = Object.keys(finalReducers)
183183

184-
// in dev environment check and save unexpected key to cache for warnings later
184+
// no ambiente de desenvolvimento verifique e salvo as chaves inesperadas em cache para alertas futuros
185185
let unexpectedKeyCache
186186
if (process.env.NODE_ENV !== 'production') {
187187
unexpectedKeyCache = {}
188188
}
189189

190190
let shapeAssertionError
191191
try {
192-
// explanations of the function is below
192+
// explicações de funções estão abaixo
193193
assertReducerShape(finalReducers)
194194
} catch (e) {
195195
shapeAssertionError = e
196196
}
197-
// combineReducers returns another function, which is reducer after merging
198-
// this function returns the root state
199-
// also notice a closure is used here. The function uses some outside properties
197+
// combineReducers retorna outra função, que é reduzido depois de fundido
198+
// essa função retorna o state raiz
199+
// também percena que um encerramento é usado aqui. A função usa algumas propriedades externas
200200
return function combination(state = {}, action) {
201201
if (shapeAssertionError) {
202202
throw shapeAssertionError

0 commit comments

Comments
 (0)