Skip to content

Commit f273e2d

Browse files
authored
Merge pull request #250 from niceplugin/api/reactivity-advanced
문서 번역: api/reactivity-advanced.md
2 parents 913fee3 + 06ea236 commit f273e2d

File tree

1 file changed

+104
-58
lines changed

1 file changed

+104
-58
lines changed

ko-KR/src/api/reactivity-advanced.md

Lines changed: 104 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1-
:::warning 현재 이 문서는 번역 작업이 진행중입니다
2-
:::
3-
4-
5-
6-
# Reactivity API: Advanced
1+
# 반응형 API: 고급
72

83
## shallowRef()
94

10-
Shallow version of [`ref()`](./reactivity-core.html#ref).
5+
[`ref()`](./reactivity-core.html#ref)의 얕은 버전입니다.
116

127
- **타입**:
138

@@ -21,29 +16,31 @@ Shallow version of [`ref()`](./reactivity-core.html#ref).
2116

2217
- **세부 사항**:
2318

24-
Unlike `ref()`, the inner value of a shallow ref is stored and exposed as-is, and will not be made deeply reactive. Only the `.value` access is reactive.
19+
`ref()`와 달리 `shallowRef()`의 내부 값은 있는 그대로 저장되고 노출되며 내부 깊숙이까지 반응형으로 동작하지는 않습니다.
20+
`.value` 접근만 반응형입니다.
2521

26-
`shallowRef()` is typically used for performance optimizations of large data structures, or integration with external state management systems.
22+
`shallowRef`는 일반적으로 대규모 데이터 구조의 성능 최적화 또는 외부 상태 관리 시스템과의 통합에 사용됩니다.
2723

2824
- **예제**:
2925

3026
```js
3127
const state = shallowRef({ count: 1 })
3228

33-
// does NOT trigger change
29+
// change(변경)을 트리거하지 않음
3430
state.value.count = 2
3531

36-
// does trigger change
32+
// change를 트리거 함
3733
state.value = { count: 2 }
3834
```
3935

4036
- **참고**:
41-
- [가이드 - Reduce Reactivity Overhead for Large Immutable Structures](/guide/best-practices/performance.html#reduce-reactivity-overhead-for-large-immutable-structures)
42-
- [가이드 - Integration with External State Systems](/guide/extras/reactivity-in-depth.html#integration-with-external-state-systems)
37+
- [가이드 - 큰 불변 구조에 대한 반응형 오버헤드 감소](/guide/best-practices/performance.html#reduce-reactivity-overhead-for-large-immutable-structures)
38+
- [가이드 - 외부 상태 시스템과의 통합](/guide/extras/reactivity-in-depth.html#integration-with-external-state-systems)
4339

4440
## triggerRef()
4541

46-
Force trigger effects that depends on a [shallow ref](#shallowref). This is typically used after making deep mutations to the inner value of a shallow ref.
42+
[`shallowRef()`](#shallowref)의 강제 트리거 이펙트.
43+
이것은 일반적으로 `shallowRef` 내부 깊숙한 곳의 값을 변경 후, 관련 이펙트를 강제로 트리거 하기위해 사용합니다.
4744

4845
- **타입**:
4946

@@ -55,24 +52,24 @@ Force trigger effects that depends on a [shallow ref](#shallowref). This is typi
5552

5653
```js
5754
const shallow = shallowRef({
58-
greet: 'Hello, world'
55+
greet: '안녕, Vue!'
5956
})
6057
61-
// Logs "Hello, world" once for the first run-through
58+
// 첫 실행 시 로그: "안녕, Vue!"
6259
watchEffect(() => {
6360
console.log(shallow.value.greet)
6461
})
6562
66-
// This won't trigger the effect because the ref is shallow
67-
shallow.value.greet = 'Hello, universe'
63+
// ref가 얕기 때문에 이펙트가 트리거되지 않음
64+
shallow.value.greet = '멋진 Vue!'
6865
69-
// Logs "Hello, universe"
70-
triggerRef(shallow)
66+
// 강제로 shallow와 관련된 이펙트 트리거
67+
triggerRef(shallow) // 로그: "멋진 Vue!"
7168
```
7269

7370
## customRef()
7471

75-
Creates a customized ref with explicit control over its dependency tracking and updates triggering.
72+
종속성 추적 및 업데이트 트리거를 명시적으로 제어하기 위한 커스텀 ref를 만듭니다.
7673

7774
- **타입**:
7875

@@ -90,13 +87,17 @@ Creates a customized ref with explicit control over its dependency tracking and
9087

9188
- **세부 사항**:
9289

93-
`customRef()` expects a factory function, which receives `track` and `trigger` functions as arguments and should return an object with `get` and `set` methods.
90+
`customRef()`는 인자로 펙토리 함수를 받습니다.
91+
이 함수는 `track``trigger`를 인자로 수신하며,
92+
`get``set` 메소드가 포함된 객체를 반환해야 합니다.
9493

95-
In general, `track()` should be called inside `get()`, and `trigger()` should be called inside `set()`. However, you have full control over when they should be called, or whether they should be called at all.
94+
일반적으로 `track()``get()` 내부에서 호출되어야 하고,
95+
`trigger()``set()` 내부에서 호출되어야 하지만,
96+
호출 조건 및 타이밍은 완전히 커스텀 제어 가능합니다.
9697

9798
- **예제**:
9899

99-
Creating a debounced ref that only updates the value after a certain timeout after the latest set call:
100+
최신 set 호출 후, 특정 시간 초과 후에만 값을 업데이트하는 디바운스된 ref 생성:
100101

101102
```js
102103
import { customRef } from 'vue'
@@ -121,7 +122,7 @@ Creates a customized ref with explicit control over its dependency tracking and
121122
}
122123
```
123124

124-
Usage in component:
125+
컴포넌트에서 사용법
125126

126127
```vue
127128
<script setup>
@@ -134,11 +135,11 @@ Creates a customized ref with explicit control over its dependency tracking and
134135
</template>
135136
```
136137

137-
[Try it in the Playground](https://sfc.vuejs.org/#eyJBcHAudnVlIjoiPHNjcmlwdCBzZXR1cD5cbmltcG9ydCB7IHVzZURlYm91bmNlZFJlZiB9IGZyb20gJy4vZGVib3VuY2VkUmVmLmpzJ1xuY29uc3QgdGV4dCA9IHVzZURlYm91bmNlZFJlZignaGVsbG8nLCAxMDAwKVxuPC9zY3JpcHQ+XG5cbjx0ZW1wbGF0ZT5cbiAgPHA+XG4gICAgVGhpcyB0ZXh0IG9ubHkgdXBkYXRlcyAxIHNlY29uZCBhZnRlciB5b3UndmUgc3RvcHBlZCB0eXBpbmc6XG4gIDwvcD5cbiAgPHA+e3sgdGV4dCB9fTwvcD5cbiAgPGlucHV0IHYtbW9kZWw9XCJ0ZXh0XCIgLz5cbjwvdGVtcGxhdGU+IiwiaW1wb3J0LW1hcC5qc29uIjoie1xuICBcImltcG9ydHNcIjoge1xuICAgIFwidnVlXCI6IFwiaHR0cHM6Ly9zZmMudnVlanMub3JnL3Z1ZS5ydW50aW1lLmVzbS1icm93c2VyLmpzXCJcbiAgfVxufSIsImRlYm91bmNlZFJlZi5qcyI6ImltcG9ydCB7IGN1c3RvbVJlZiB9IGZyb20gJ3Z1ZSdcblxuZXhwb3J0IGZ1bmN0aW9uIHVzZURlYm91bmNlZFJlZih2YWx1ZSwgZGVsYXkgPSAyMDApIHtcbiAgbGV0IHRpbWVvdXRcbiAgcmV0dXJuIGN1c3RvbVJlZigodHJhY2ssIHRyaWdnZXIpID0+IHtcbiAgICByZXR1cm4ge1xuICAgICAgZ2V0KCkge1xuICAgICAgICB0cmFjaygpXG4gICAgICAgIHJldHVybiB2YWx1ZVxuICAgICAgfSxcbiAgICAgIHNldChuZXdWYWx1ZSkge1xuICAgICAgICBjbGVhclRpbWVvdXQodGltZW91dClcbiAgICAgICAgdGltZW91dCA9IHNldFRpbWVvdXQoKCkgPT4ge1xuICAgICAgICAgIHZhbHVlID0gbmV3VmFsdWVcbiAgICAgICAgICB0cmlnZ2VyKClcbiAgICAgICAgfSwgZGVsYXkpXG4gICAgICB9XG4gICAgfVxuICB9KVxufSJ9)
138+
[온라인 연습장으로 실행하기](https://sfc.vuejs.org/#eNp9Us1q20AQfpXpXqyALTk9GjtQ6BOU0tNeFHnsKrV2xe7KSRGCHmIwNoEcGlIoKTmklNx6CKV9Jsnv0Fn9RXEge5Hmm5nvm7+UvYljd5kgG7GxDlQYG9BokviIizCKpTKQQqLxLR7LRAQ4fYczyGCmZAQ915t2YPdE97gIpNAGDJ4ZmOwnOr3iap2vrl71+nA4HA4PuBh7lSjJkWEwihe+QbIAxrYGoFfcPMBudVFs7nabv/nmK+Tbf8X21sKhiBNTXF9C8WOV3/4sbs4hv18Xf74Vv77AYfGwht3389J/vcovflMKUUB+eZ9v1/n2blTqeJUQ6aVpVXmWtWCpAMtBJKe4mHBm/ZyBR96x19bL+qya1iDyYxqEFDTP1BLw2qE5G0GJWIwGbm3OPhoT65Hn6Vlgt3CiXanmHv25KhEmjNBFHQ2OlTzVqIiYs36HwyNwiWqgUExRoXqJcy/0Ga+lzbjIqJW9rVIr7SkEiTYy6h4BKdDaucCzMmRGiSaU4tnul/4iwT7QFP3PdBqvaf3VPBZI90KdysRYU9H1KfEo5DhG+cGnPhgVzueoDmBy1Ayyjq0tgDkap2atXpnq0J01QJ1RFtOgWT1SsJfvCDz9YL1PeIIF+up9VaRTF9thrRFqixiaMKrksdLqlbIU1Wh0fXV73WKzelwtRPtpPxmhGcv+AwLzVi0=)
138139

139140
## shallowReactive()
140141

141-
Shallow version of [`reactive()`](./reactivity-core.html#reactive).
142+
[`reactive()`](./reactivity-core.html#reactive)의 얕은 버전입니다.
142143

143144
- **타입**:
144145

@@ -148,10 +149,16 @@ Shallow version of [`reactive()`](./reactivity-core.html#reactive).
148149

149150
- **세부 사항**:
150151

151-
Unlike `reactive()`, there is no deep conversion: only root-level properties are reactive for a shallow reactive object. Property values are stored and exposed as-is - this also means properties with ref values will **not** be automatically unwrapped.
152+
`reactive()`와 달리 내부 깊숙한 곳의 변경이 반응형으로 작동하지 않고,
153+
얕게 루트 수준의 속성 변경에 대해서만 반응형인 객체입니다.
154+
속성 값은 있는 그대로 저장되고 노출되므로,
155+
속성이 ref 값인 경우, 자동으로 **언래핑되지 않습니다**.
152156

153-
:::warning Use with Caution
154-
Shallow data structures should only be used for root level state in a component. Avoid nesting it inside a deep reactive object as it creates a tree with inconsistent reactivity behavior which can be difficult to understand and debug.
157+
:::warning 주의해서 사용
158+
얕은 데이터 구조는 컴포넌트에서 루트 수준 상태로만 사용해야 합니다.
159+
내부 깊숙이까지 반응형으로 동작하는 객체 내부에 중첩하는 경우,
160+
반응형 동작에 일관성이 없는 트리가 생성되어 이해와 디버그가 어려울 수 있으니,
161+
중첩하여 사용하면 안됩니다.
155162
:::
156163

157164
- **예제**:
@@ -164,19 +171,19 @@ Shallow version of [`reactive()`](./reactivity-core.html#reactive).
164171
}
165172
})
166173
167-
// mutating state's own properties is reactive
174+
// 상태의 자체 속성 변경은 방응형으로 동작함
168175
state.foo++
169176
170-
// ...but does not convert nested objects
177+
// ...하지만 중첩된 객체는 그렇지 않음
171178
isReactive(state.nested) // false
172179
173-
// NOT reactive
180+
// 반응형이 아님
174181
state.nested.bar++
175182
```
176183

177184
## shallowReadonly()
178185

179-
Shallow version of [`readonly()`](./reactivity-core.html#readonly).
186+
[`readonly()`](./reactivity-core.html#readonly)의 얕은 버전입니다.
180187

181188
- **타입**:
182189

@@ -186,10 +193,16 @@ Shallow version of [`readonly()`](./reactivity-core.html#readonly).
186193

187194
- **세부 사항**:
188195

189-
Unlike `readonly()`, there is no deep conversion: only root-level properties are made readonly. Property values are stored and exposed as-is - this also means properties with ref values will **not** be automatically unwrapped.
196+
`readonly()`와 달리 내부 깊숙이까지 변환하지 않고,
197+
루트 수준 속성만 읽기 전용으로 만들어집니다.
198+
속성 값은 있는 그대로 저장되고 노출되므로,
199+
속성이 ref 값인 경우, 자동으로 **언래핑되지 않습니다**.
190200

191-
:::warning Use with Caution
192-
Shallow data structures should only be used for root level state in a component. Avoid nesting it inside a deep reactive object as it creates a tree with inconsistent reactivity behavior which can be difficult to understand and debug.
201+
:::warning 주의해서 사용
202+
얕은 데이터 구조는 컴포넌트에서 루트 수준 상태로만 사용해야 합니다.
203+
내부 깊숙이까지 반응형으로 동작하는 객체 내부에 중첩하는 경우,
204+
반응형 동작에 일관성이 없는 트리가 생성되어 이해와 디버그가 어려울 수 있으니,
205+
중첩하여 사용하면 안됩니다.
193206
:::
194207

195208
- **예제**:
@@ -202,19 +215,19 @@ Shallow version of [`readonly()`](./reactivity-core.html#readonly).
202215
}
203216
})
204217
205-
// mutating state's own properties will fail
218+
// 상태의 자체 속성을 변경하는 것은 실패 됨
206219
state.foo++
207220
208-
// ...but works on nested objects
221+
// ...하지만 중첩된 객체는 그렇지 않음
209222
isReadonly(state.nested) // false
210223
211-
// works
224+
// 변경 작업이 됨
212225
state.nested.bar++
213226
```
214227

215228
## toRaw()
216229

217-
Returns the raw, original object of a Vue-created proxy.
230+
Vue에서 만든 프락시의 원시 원본 객체를 반환합니다.
218231

219232
- **타입**:
220233

@@ -224,9 +237,11 @@ Returns the raw, original object of a Vue-created proxy.
224237

225238
- **세부 사항**:
226239

227-
`toRaw()` can return the original object from proxies created by [`reactive()`](./reactivity-core.html#reactive), [`readonly()`](./reactivity-core.html#readonly), [`shallowReactive()`](#shallowreactive) or [`shallowReadonly()`](#shallowreadonly).
240+
`toRaw()`[`reactive()`](./reactivity-core.html#reactive), [`readonly()`](./reactivity-core.html#readonly), [`shallowReactive()`](#shallowreactive), [`shallowReadonly()`](#shallowreadonly)로 생성된 프락시에서 원본 객체를 반환합니다.
228241

229-
This is an escape hatch that can be used to temporarily read without incurring proxy access / tracking overhead or write without triggering changes. It is **not** recommended to hold a persistent reference to the original object. Use with caution.
242+
이것은 일시적으로 프락시의 접근/추적 오버헤드를 발생시키는 읽기/쓰기와 관련된 트리거 없이 사용하기 위한 용도입니다.
243+
원본 객체의 영구 참조를 유지하는 것은 **권장되지 않습니다**.
244+
주의해서 사용해야 합니다.
230245

231246
- **예제**:
232247

@@ -239,7 +254,8 @@ Returns the raw, original object of a Vue-created proxy.
239254

240255
## markRaw()
241256

242-
Marks an object so that it will never be converted to a proxy. Returns the object itself.
257+
객체가 프락시로 변환되지 않도록 마크(mark)합니다.
258+
객체 자체를 반환합니다.
243259

244260
- **타입**:
245261

@@ -253,40 +269,54 @@ Marks an object so that it will never be converted to a proxy. Returns the objec
253269
const foo = markRaw({})
254270
console.log(isReactive(reactive(foo))) // false
255271
256-
// also works when nested inside other reactive objects
272+
// 다른 반응형 객체 내부에 중첩될 때도 작동함
257273
const bar = reactive({ foo })
258274
console.log(isReactive(bar.foo)) // false
259275
```
260276

261-
:::warning Use with Caution
262-
`markRaw()` and shallow APIs such as `shallowReactive()` allow you to selectively opt-out of the default deep reactive/readonly conversion and embed raw, non-proxied objects in your state graph. They can be used for various reasons:
277+
:::warning 주의해서 사용
278+
`markRaw()``shallowReactive()` 같이 얕은 API를 사용하면,
279+
선택적으로 기본적인 내부 깊숙이까지의 "반응형"/"읽기 전용" 변환을 옵트아웃(opt-out)하여,
280+
상태 그래프(선언/정의/사용하는 곳)에 프락시 되지 않은 원시 객체를 포함할 수 있습니다.
281+
이것들은 다양한 이유로 사용될 수 있습니다:
263282

264-
- Some values simply should not be made reactive, for example a complex 3rd party class instance, or a Vue component object.
283+
- 일부 값들은 함부로 반응형으로 만들면 안되는데,
284+
그 예로 복잡한 타사의 클래스 인스턴스나 Vue 컴포넌트 객체가 있습니다.
265285

266-
- Skipping proxy conversion can provide performance improvements when rendering large lists with immutable data sources.
286+
- 프락시 변경을 건너뛰면,
287+
변경해서는 안되는 데이터 소스를 포함하고 있는 커다란 리스트를 렌더링할 때,
288+
성능이 향상될 수 있습니다.
267289

268-
They are considered advanced because the raw opt-out is only at the root level, so if you set a nested, non-marked raw object into a reactive object and then access it again, you get the proxied version back. This can lead to **identity hazards** - i.e. performing an operation that relies on object identity but using both the raw and the proxied version of the same object:
290+
원시(raw) 옵트아웃은 루트 레벨에만 있기 때문에 고급으로 간주되므로,
291+
마크되지 않은 중첩된 원시 객체를 반응형 객체로 설정한 다음 다시 접근을 시도하면,
292+
프락시 버전의 객체로 접근하게 됩니다.
293+
이것은 동일한 객체에 참조했다고 예상했으나,
294+
원시 버전과 프락시 버전을 혼용하여 사용하는 "**잘못된 ID 참조**(identity hazards)"로 이어질 수 있습니다.
269295

270296
```js
271297
const foo = markRaw({
272298
nested: {}
273299
})
274300
275301
const bar = reactive({
276-
// although `foo` is marked as raw, foo.nested is not.
302+
// `foo`는 원시 마크가 있지만, `foo.nested`는 그렇지 않음
277303
nested: foo.nested
278304
})
279305
280306
console.log(foo.nested === bar.nested) // false
281307
```
282308

283-
Identity hazards are in general rare. However, to properly utilize these APIs while safely avoiding identity hazards requires a solid understanding of how the reactivity system works.
284-
309+
잘못된 ID 참조 문제는 일반적으로 드뭅니다.
310+
그러나 이 문제로부터 안전하게 이러한 API를 활용하려면,
311+
반응형 시스템이 어떻게 작동하는지에 확실한 이해가 필요합니다.
285312
:::
286313

287314
## effectScope()
288315

289-
Creates an effect scope object which can capture the reactive effects (i.e. computed and watchers) created within it so that these effects can be disposed together. For detailed use cases of this API, please consult its corresponding [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md).
316+
범위 내 반응형 이펙트(계산된 속성, 감시자)들을 캡처하고,
317+
일괄적으로 처리하는 effectScope 객체를 반환합니다.
318+
319+
API의 자세한 사용 사례 참고: [RFC](https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md)
290320

291321
- **타입**:
292322

@@ -312,13 +342,13 @@ Creates an effect scope object which can capture the reactive effects (i.e. comp
312342
watchEffect(() => console.log('Count: ', doubled.value))
313343
})
314344
315-
// to dispose all effects in the scope
345+
// 범위 내 여러 이펙트 중지(폐기 됨)
316346
scope.stop()
317347
```
318348

319349
## getCurrentScope()
320350

321-
Returns the current active [effect scope](#effectscope) if there is one.
351+
현재 활성 [effectScope](#effectscope)가 있는 경우, 이를 반환합니다.
322352

323353
- **타입**:
324354

@@ -328,12 +358,28 @@ Returns the current active [effect scope](#effectscope) if there is one.
328358

329359
## onScopeDispose()
330360

331-
Registers a dispose callback on the current active [effect scope](#effectscope). The callback will be invoked when the associated effect scope is stopped.
361+
현재 활성 [effectScope](#effectscope)에 중지(폐기) 콜백을 등록합니다.
362+
연결된 effectScope이 중지되면 콜백이 호출됩니다.
332363

333-
This method can be used as a non-component-coupled replacement of `onUnmounted` in reusable composition functions, since each Vue component's `setup()` function is also invoked in an effect scope.
364+
Vue 컴포넌트의 `setup()` 함수도 effectScope에서 호출되기 때문에,
365+
-컴포넌트-결합(non-component-coupled)에서 재사용 가능한 컴포지션 함수인 `onUnmounted`의 대체로 사용할 수 있습니다.
334366

335367
- **타입**:
336368

337369
```ts
338370
function onScopeDispose(fn: () => void): void
339371
```
372+
373+
- **예제**:
374+
375+
```js
376+
const scope = effectScope()
377+
378+
scope.run(() => {
379+
onScopeDispose(() => {
380+
console.log('effectScope가 중지됨!')
381+
})
382+
})
383+
384+
scope.stop() // 로그: 'effectScope가 중지됨!'
385+
```

0 commit comments

Comments
 (0)