본문 바로가기

iOS

Composable Architecture

안녕하세요 태태입니다. 💜

이번 포스팅은 Composable Architecture에 대해 학습해보려 합니다. 👀

Composable Architecture 란?

Point-Free에서 구현한 상태 관리 기반 아키텍처로 상태 관리, 구성 및 테스트에 중점을 두고 있습니다.

자세한 내용은 아래 링크를 통해 확인하실 수 있습니다.

Swift Compsable Architecture github 

 

GitHub - pointfreeco/swift-composable-architecture: A library for building applications in a consistent and understandable way,

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind. - GitHub - pointfreeco/swift-composable-architecture: A library for bu...

github.com


Composable Architecture 특징

- State Management : 간단한 값을 사용하여 앱의 상태를 관리하고 한 화면의 변화를 다른 화면에서 즉시 관찰할 수 있도록 상태를 여러 화면에서 공유
- Composition : 큰 기능을 분리해 자체 모듈로 추출하고 작은 요소로 나누거나 붙여 기능을 합성할수 있음
- Side Effect : 앱의 특정 부분이 테스트 가능하고 이해하기 쉬운 방식으로 외부와 통신가능한 방법
- Testing : 아키텍처 내부에 작성된 기능 뿐만 아니라 많은 부분으로 구성된 기능들을 통합 또는 부분적으로 테스트 작성이 가능

- Ergonomics : 가능한 적은 개념과 움직이는 부분으로 간단한 API에서 수행


Composable Architecture 구성 요소 

- State : 기능이 로직을 수행하고 UI를 렌더링하는데 필요한 데이터 타입
- Action : 사용자 작업, 알림, 이벤트 소스등 같이 기능에서 발생할 수 있는 모든 타입
- Enviornment : API 클라이언트와 같이 기능에 필요한 모든 dependency들을 가진 타입

- Reducer : 액션이 주어지면 앱의 현재 상태를 다음 상태로 업데이트하기 위한 방법을 설명하는 함수, API 요청과 같이 실행해야 하는 모든 결과를 Effect 타입으로 반환해야 하는 역할 

- Store : 기능을 실제로 실행하는 런타임. 모든 사용자 액션을 Store로 보내, Store에서 Reducer와 Effect를 실행. Store를 관찰하여 UI를 업데이트할 수 있음

 

 

Composable Architecture 데이터 흐름 

1. View 정의

2. Store를 사용하여 Actions 보내기 

3. Reducer에서 비니지스 로직 처리

4. Effect에서 Side-effect 처리

5. State를 업데이트하여 View 업데이트

 

- 참고자료

https://github.com/pointfreeco/swift-composable-architecture

 

GitHub - pointfreeco/swift-composable-architecture: A library for building applications in a consistent and understandable way,

A library for building applications in a consistent and understandable way, with composition, testing, and ergonomics in mind. - GitHub - pointfreeco/swift-composable-architecture: A library for bu...

github.com

https://www.raywenderlich.com/24550178-getting-started-with-the-composable-architecture

 

Getting Started With The Composable Architecture

Learn how to structure your iOS app with understandable and predictable state changes using Point-Free’s The Composable Architecture (TCA) framework.

www.raywenderlich.com

https://medium.com/swlh/the-composable-architecture-visualize-data-flows-with-a-diagram-817306831508

 

The Composable Architecture — Visualize Data Flows With a Diagram

Welcome back to my SwiftUI tutorial series. In previous parts, I have proven that right now is the time for SwiftUI to shine. And how The…

medium.com