Skip to content

Commit 9de631c

Browse files
committed
UPDATE
1 parent 3bd8795 commit 9de631c

File tree

1 file changed

+45
-45
lines changed

1 file changed

+45
-45
lines changed

Framework/react-br.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -370,36 +370,36 @@ Vamos então analisar pare do código da função `createStore`
370370

371371
```js
372372
export default function createStore(reducer, preloadedState, enhancer) {
373-
// normally preloadedState is rarely used
374-
// check type, is the second parameter is a function and there is no third parameter, then exchange positions
373+
// normalmente preloadedState é raramente usado
374+
// verificar o tipo, é o segundo parâmetro da função e não existe terceiro parâmetro, então troque as posições
375375
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
376376
enhancer = preloadedState
377377
preloadedState = undefined
378378
}
379-
// check if enhancer is a function
379+
// verifique se enhancer é uma função
380380
if (typeof enhancer !== 'undefined') {
381381
if (typeof enhancer !== 'function') {
382-
throw new Error('Expected the enhancer to be a function.')
382+
throw new Error('É esperado que enhancer seja uma função.')
383383
}
384-
// if there is no type error, first execute enhancer, then execute createStore
384+
// se não existe um tipo error, primeiro execute o enhancer, então execute o createStore
385385
return enhancer(createStore)(reducer, preloadedState)
386386
}
387-
// check if reducer is a function
387+
// verifique se o reducer é uma função
388388
if (typeof reducer !== 'function') {
389-
throw new Error('Expected the reducer to be a function.')
389+
throw new Error('É esperado que o reducer seja uma função.')
390390
}
391-
// current reducer
391+
// reducer atual
392392
let currentReducer = reducer
393-
// current state
393+
// state atual
394394
let currentState = preloadedState
395-
// current listener array
395+
// atual listener array
396396
let currentListeners = []
397-
// this is a very important design. The purpose is that currentListeners array is an invariant when the listeners are iterated every time
398-
// we can consider if only currentListeners exists. If we execute subscribe again in some subscribe execution, or unsubscribe, it would change the length of the currentListeners array, so there might be an index error
397+
// esse é um design muito importante. O proposito é que o currentListeners array seja invariante quando os listeners estiverem sendo interado
398+
// Nós podemos considerar se apenas um currentListeners existe. Se nós executarmos o subscribe novamente em alguma execução do subscribe, ou unsubscribe isso mudaria o tamanho do currentListeners array, então devemos ter um index erro
399399
let nextListeners = currentListeners
400-
// if reducer is executing
400+
// se o reducer está executando
401401
let isDispatching = false
402-
// if currentListeners is the same as nextListeners, assign the value back
402+
// se o currentListeners é o mesmo que o nextListeners, atribua o valor de volta
403403
function ensureCanMutateNextListeners() {
404404
if (nextListeners === currentListeners) {
405405
nextListeners = currentListeners.slice()
@@ -409,31 +409,31 @@ export default function createStore(reducer, preloadedState, enhancer) {
409409
}
410410
```
411411

412-
We look at `applyMiddleware` function next
412+
Vamos dar uma olhada na função `applyMiddleware`
413413

414-
Before that I need to introduce a concept called function Currying. Currying is a technology for changing a function with multiple parameters to a series of functions with a single parameter.
414+
Antes eu preciso introduzir um conceito chamado Currying. Currying é uma tecnologia para mudar uma função com multiplos parâmetros em uma série de funções com um único parâmetro.
415415

416416
```js
417417
function add(a,b) { return a + b }
418418
add(1, 2) => 3
419-
// for the above function, we can use Currying like so
419+
// para a função abaixo, nós usamos Currying igual a
420420
function add(a) {
421421
return b => {
422422
return a + b
423423
}
424424
}
425425
add(1)(2) => 3
426-
// you can understand Currying like this:
427-
// we store an outside variable with a closure, and return a function that takes a parameter. In this function, we use the stored variable and return the value.
426+
// você pode entender Currying como:
427+
// nós armazenamos uma variável do lado de fora com um closure, e retornamos uma função que leva um parâmetro. Nessa função, nós usamos a variável armazenada e retornamos um valor.
428428
```
429429

430430
```js
431-
// this function should be the most abstruse part of the whole source code
432-
// this function returns a function Curried
433-
// therefore the funciton should be called like so: applyMiddleware(...middlewares)(createStore)(...args)
431+
// essa função deve ser a parte mais obstrusa de todo código
432+
// essa função retorna um função Curried
433+
// assim sendo a função deve se chamada como: applyMiddleware(...middlewares)(createStore)(...args)
434434
export default function applyMiddleware(...middlewares) {
435435
return createStore => (...args) => {
436-
// here we execute createStore, and pass the parameters passed lastly to the applyMiddleware function
436+
// aqui nós executamos createStore, e passamos o parâmetro passado por último a função applyMiddleware
437437
const store = createStore(...args)
438438
let dispatch = () => {
439439
throw new Error(
@@ -442,24 +442,24 @@ export default function applyMiddleware(...middlewares) {
442442
)
443443
}
444444
let chain = []
445-
// every middleware should have these two functions
445+
// todo middleware deve ter essas duas funções
446446
const middlewareAPI = {
447447
getState: store.getState,
448448
dispatch: (...args) => dispatch(...args)
449449
}
450-
// pass every middleware in middlewares to middlewareAPI
450+
// passar cada middleware nos middlewares para o middlewareAPI
451451
chain = middlewares.map(middleware => middleware(middlewareAPI))
452-
// same as before, calle very middleWare from right to left, and pass to store.dispatch
452+
// assim como antes, chame cada middleware da esquerda para direita, e passo para o store.dispatch
453453
dispatch = compose(...chain)(store.dispatch)
454-
// this piece is a little abstract, we'll analyze together with the code of redux-thunk
455-
// createThunkMiddleware returns a 3-level function, the first level accepts a middlewareAPI parameter
456-
// the second level accepts store.dispatch
457-
// the third level accepts parameters in dispatch
454+
// essa parte é um pouco abstrata, nós iremos analisar juntos com o código do redux-thunk
455+
// createThunkMiddleware retorna uma função de 3-nível, o primeiro nível aceita um parâmetro middlewareAPI
456+
// o segundo nível aceita store.dispatch
457+
// o terceiro nível aceita parâmentros no dispatch
458458
{function createThunkMiddleware(extraArgument) {
459459
return ({ dispatch, getState }) => next => action => {
460-
// check if the parameters in dispatch is a function
460+
// verifique se o parâmetro no dispatch é uma função
461461
if (typeof action === 'function') {
462-
// if so, pass those parameters, until action is no longer a function, then execute dispatch({type: 'XXX'})
462+
// se assim for, passe esses parâmetros, até as acões não sejam mais uma função, então execute dispatch({type: 'XXX'})
463463
return action(dispatch, getState, extraArgument);
464464
}
465465

@@ -469,7 +469,7 @@ export default function applyMiddleware(...middlewares) {
469469
const thunk = createThunkMiddleware();
470470

471471
export default thunk;}
472-
// return the middleware-empowered dispatch and the rest of the properties in store.
472+
// retorn o middleware-empowered dispatch e o resto das propriedades no store.
473473
return {
474474
...store,
475475
dispatch
@@ -478,10 +478,10 @@ export default thunk;}
478478
}
479479
```
480480

481-
Now we've passed the hardest part. Let's take a look at some easier pieces.
481+
Agora nós passamos a parte difícil. Vamos olhar uma parte mais fácil.
482482

483483
```js
484-
// Not much to say here, return the current state, but we can't call this function when reducer is running
484+
// Não há muito para dizer aqui, retorne o state atual, mas nós não podemos chamar essa função quando o reducer estiver executando
485485
function getState() {
486486
if (isDispatching) {
487487
throw new Error(
@@ -493,12 +493,12 @@ function getState() {
493493

494494
return currentState
495495
}
496-
// accept a function parameter
496+
// aceita uma função parâmetro
497497
function subscribe(listener) {
498498
if (typeof listener !== 'function') {
499499
throw new Error('Expected listener to be a function.')
500500
}
501-
// the major design of this part is already covered in the description of nextListeners. Not much to talk about otherwise
501+
// a maior parte desse design já foi coberto na descrição sobre nextListeners. Não há muito para falar sobre.
502502
if (isDispatching) {
503503
throw new Error(
504504
'You may not call store.subscribe() while the reducer is executing. ' +
@@ -513,7 +513,7 @@ function subscribe(listener) {
513513
ensureCanMutateNextListeners()
514514
nextListeners.push(listener)
515515

516-
// return a cancel subscription function
516+
// retorne a função de cancelar a subscription
517517
return function unsubscribe() {
518518
if (!isSubscribed) {
519519
return
@@ -535,7 +535,7 @@ function subscribe(listener) {
535535
}
536536

537537
function dispatch(action) {
538-
// the prototype dispatch will check if action is an object
538+
// o prototype dispatch vai verificar se a ação é um objeto
539539
if (!isPlainObject(action)) {
540540
throw new Error(
541541
'Actions must be plain objects. ' +
@@ -549,19 +549,19 @@ function dispatch(action) {
549549
'Have you misspelled a constant?'
550550
)
551551
}
552-
// note that you can't call dispatch function in reducers
553-
// it would cause a stack overflow
552+
// perceba que você não pode chamar uma função dispatch nos reducers
553+
// isso causaria um estouro de pilha
554554
if (isDispatching) {
555555
throw new Error('Reducers may not dispatch actions.')
556556
}
557-
// execute the composed function after combineReducers
557+
// execute a função composta depois do combineReducers
558558
try {
559559
isDispatching = true
560560
currentState = currentReducer(currentState, action)
561561
} finally {
562562
isDispatching = false
563563
}
564-
// iterate on currentListeners and execute saved functions in the array
564+
// itere nos currentListeners e execute as funções salvas no array de funções
565565
const listeners = (currentListeners = nextListeners)
566566
for (let i = 0; i < listeners.length; i++) {
567567
const listener = listeners[i]
@@ -570,6 +570,6 @@ function dispatch(action) {
570570

571571
return action
572572
}
573-
// at the end of createStore, invoke an action dispatch({ type: ActionTypes.INIT });
574-
// to initialize state
573+
// no fim do createStore, invoce uma ação dispatch({ type: ActionTypes.INIT });
574+
// para inicializar o state
575575
```

0 commit comments

Comments
 (0)