# Facade API

> 애플리케이션에 Facade API를 추가하여 Web SDK를 더 간편하게 사용하는 방법을 알아봅니다.

- Human documentation: [https://docs.univer.ai/ko-KR/guides/docs/getting-started/facade](https://docs.univer.ai/ko-KR/guides/docs/getting-started/facade)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/docs/getting-started/facade.md](https://docs.univer.ai/ko-KR/guides/docs/getting-started/facade.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [docs/getting-started/facade.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/docs/getting-started/facade.ko-KR.mdx)

---

복잡한 요구 사항을 충족하기 위해 Univer의 아키텍처 역시 상당히 복잡하게 구성되어 있어 사용에 어려움이 있을 수 있습니다. 이를 해결하기 위해 더 단순하고 사용하기 쉬운 Facade API를 제공합니다.

이 장에서는 애플리케이션에 Facade API를 추가하는 방법을 자세히 설명합니다. 이어지는 “기능” 장에서는 각 기능의 주요 Facade API를 소개합니다. 모든 Facade API를 확인하려면 각 플러그인의 API 레퍼런스를 참고하세요.

> [!WARNING: 주의]
> 일부 Facade API, 특히 데이터를 변경하는 API는 비동기이며 Promise를 반환하는 경우가 많습니다. 데이터를 변경한 직후 가져와야 한다면 `await` 또는 `.then()`을 사용하세요. 그렇지 않으면 예상치 못한 결과가 발생할 수 있습니다. Promise를 반환하는 API가 무엇인지 확인하려면 해당 API 레퍼런스 문서를 참고하세요.

## 플러그인 모드에서 Facade API 통합하기

### 설치

플러그인 모드로 설치한 Univer에 Facade API를 통합할 때 Facade API 구현은 여러 플러그인에 나뉘어 배포되며 전역 Facade API 루트 객체에 마운트됩니다. 따라서 Facade API를 제공하는 플러그인의 해당 구현을 필요에 따라 가져올 수 있습니다.

```typescript
import { FUniver } from '@univerjs/core/facade'

import '@univerjs/ui/facade'
import '@univerjs/docs/facade'
import '@univerjs/docs-ui/facade'
```

> [!WARNING: 주의]
> 모든 플러그인에 facade 패키지가 포함되는 것은 아닙니다. 포함 여부는 각 기능의 문서에 명시합니다.

### 사용법

```typescript
import { FUniver } from '@univerjs/core/facade'

const univerAPI = FUniver.newAPI(univer)
```

### 주의 사항

모든 Facade API를 즉시 호출할 수 있는 것은 아닙니다. 일부 API는 특정 생명 주기 단계에서 사용해야 합니다. 즉시 실행할 때 문제가 발생하면 다음 방법을 참고하여 적절한 생명 주기 단계에서 실행하세요.

```typescript
const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => {
  if (stage === univerAPI.Enum.LifecycleStages.Rendered) {
    // Code to be executed when the lifecycle stage is Rendered
  }
  if (stage === univerAPI.Enum.LifecycleStages.Steady) {
    // Code to be executed when the lifecycle stage is Steady
  }
})
```

## 프리셋 모드에서 Facade API 통합하기

프리셋 모드로 Univer를 통합하면 포함된 기능의 Facade API를 자동으로 가져오며, Univer 인스턴스를 생성할 때 해당 Facade API 인스턴스인 `univerAPI`를 반환합니다. 이를 바로 사용할 수 있습니다.
