IT_susu

[번역] Tutorial: Adding Time Travel 1 본문

[ javascript ]/react

[번역] Tutorial: Adding Time Travel 1

고베베 2019. 4. 18. 14:01

As a final exercise, let’s make it possible to “go back in time” to the previous moves in the game.

마지막 연습으로, 게임의 이전 동작에 대해 시간을 되돌리는 것을 해보자.

Storing a History of Moves

동작 기록 저장

 

If we mutated the squares array, implementing time travel would be very difficult.

만약 squares 배열을 바꾼다면, 시간여행을 하는 것은 매우 어려울 것이다.

 

However, we used slice() to create a new copy of the squares array after every move, and treated it as immutable. This will allow us to store every past version of the squares array, and navigate between the turns that have already happened.

그러나, 우리는 slice()를 사용해서 새로운 squares배열 복사본을 만들었다. 먼저 모든게 움직인 후에. 그리고 불변적으로 만들었다. 이렇게 하면 squares배열의 모든 과거 버전을 저장하고, 이미 발생한 차례 사이에서 탐색할 수 있다.

 

We’ll store the past squares arrays in another array called history. The history array represents all board states, from the first to the last move, and has a shape like this:

우리는 history라 불리는 또다른 배열에 과거 squares배열들을 저장할 것이다. history배열은 모든 board의 상태를 대표하며, 처음부터 마지막 움직임까지, 이와 같은 모양을 띄고 있다.

 

Now we need to decide which component should own the history state.

이제 우리는 어떤 컴포넌트가 history state를 가지고 있을지 결정할 필요가 있다.

Comments