SlideShare una empresa de Scribd logo
1 de 91
Descargar para leer sin conexión
class Human {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
class Profile extends React.Component {
render() {
const yujin = new Human('yujin', 24);
return (
<div>
<h1>{ yujin.name }</h1>
<h2>{ `${yujin.age} ` }</h2>
<h3>{ yujin.githubUrl }</h3>
</div>
)
}
}
class Human {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
class Profile extends React.Component {
render() {
const yujin = new Human('yujin', 24);
return (
<div>
<h1>{ yujin.name }</h1>
<h2>{ `${yujin.age} ` }</h2>
<h3>{ yujin.githubUrl }</h3>
</div>
)
}
}
class User implements Entity {
id: number;
name: string;
type: User.Type;
constructor(
id: number,
name: string,
type: User.Type
) {
this.id = id;
this.name = name;
this.type = type;
}
}
Repository
- Entity를 제공하기 위한 Interface
- 실제 구현은 DataSource에 의존성을 가지는 Data Layer에서 이루어짐
interface UserRepositoryType extends RepositoryType {
search(query: string): Observable<List<User>>
}
class SearchUsers extends UseCase<List<User>> {
private repository: UserRepositoryType;
query: string;
constructor(repository: UserRepositoryType) {
super();
this.repository = repository;
}
protected build(): Observable<List<User>> {
return this.repository.search(this.query);
}
protected validate(): boolean {
return !!this.query;
}
}
UseCase
- 도메인 영역의 End-Point
- 실제로 서비스를 이용하는 사용자가 하는 행동을 정의
- repository의 interface 기능을 조합하여 원하는 결과값을 하나로
돌려준다
interface UserRepositoryType extends RepositoryType {
search(query: string): Observable<List<User>>
}
class UserRepository implements UserRepositoryType {
private githubApi: GithubApiProvider;
constructor(githubApi: GithubApiProvider) {
this.githubApi = githubApi;
}
search(query: string): Observable<List<User>> {
return this.githubApi.searchUser(query);
}
}
interface ApiProviderDependencies {
github: GithubApiProvider;
}
interface RepositoryDependencies {
user: UserRepository;
}
interface UseCaseDependencies {
searchUsers: SearchUsers;
}
class Context {
private githubAxiosInstance: AxiosInstance;
private apiProviders: ApiProviderDependencies;
private repositories: RepositoryDependencies;
useCases: UseCaseDependencies;
constructor(githubAxiosInstance: AxiosInstance) {
this.githubAxiosInstance = githubAxiosInstance;
this.apiProviders = {
github: new GithubApiProvider(githubAxiosInstance)
};
this.repositories = {
user: new UserRepository(this.apiProviders.github)
};
this.useCases = {
searchUsers: new SearchUsers(this.repositories.user)
}
}
}
const axiosInstance = Axios.create({
baseURL: Config.hosts.github,
timeout: Config.timeout,
headers: {
'Accept': 'application/json'
}
});
export const Application = new Context(axiosInstance);
private renderUsers = (users: List<User>) =>
<ul>
{
users.map((user, i) =>
<li key={ `users-${i}` }>
{ user.name }
</li>
)
}
</ul>;
apply(Application.useCases.searchUsers, it => it.query = query)
.runOnAnimateFrame()
.subscribe(
users =>
this.setState({
users,
fetchState: FetchState.FETCHED
}),
error =>
this.setState({
fetchState: FetchState.ERROR
})
)
.unsubscribeBy(this.subscriptionBag)
interface Event {
id: string;
name: string;
}
class CardCompanyEvent implements Event {
id: string;
name: string;
}
class StockFirmEvent implements Event {
id: string;
name: string;
}
interface Event {
id: string;
name: string;
}
class CardCompanyEvent implements Event {
id: string;
name: string;
}
class StockFirmEvent implements Event {
id: string;
name: string;
}
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture
Why Typescript with Clean Architecture

Más contenido relacionado

La actualidad más candente

REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with SpringJoshua Long
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep DiveMartijn Dashorst
 
All you need to know about JavaScript loading and execution in the browser - ...
All you need to know about JavaScript loading and execution in the browser - ...All you need to know about JavaScript loading and execution in the browser - ...
All you need to know about JavaScript loading and execution in the browser - ...Caelum
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleVodqaBLR
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a StartupSébastien Saunier
 
내가써본 nGrinder-SpringCamp 2015
내가써본 nGrinder-SpringCamp 2015내가써본 nGrinder-SpringCamp 2015
내가써본 nGrinder-SpringCamp 2015Lim SungHyun
 
Knowledge graphs + Chatbots with Neo4j
Knowledge graphs + Chatbots with Neo4jKnowledge graphs + Chatbots with Neo4j
Knowledge graphs + Chatbots with Neo4jChristophe Willemsen
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)beom kyun choi
 
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기OKKY
 
Successful DB migrations with Liquibase
 Successful DB migrations with Liquibase Successful DB migrations with Liquibase
Successful DB migrations with LiquibaseIllia Seleznov
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practicesfelixbillon
 
Cours formulaire html - niveau débutant
Cours formulaire html - niveau débutantCours formulaire html - niveau débutant
Cours formulaire html - niveau débutantTheBest Icanbe
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsYura Nosenko
 
Battle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBootBattle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBootChristos Sotiriou
 
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018Kenneth Ceyer
 
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...GreeceJS
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문SeungHyun Eom
 

La actualidad más candente (20)

REST APIs with Spring
REST APIs with SpringREST APIs with Spring
REST APIs with Spring
 
Java Serialization Deep Dive
Java Serialization Deep DiveJava Serialization Deep Dive
Java Serialization Deep Dive
 
All you need to know about JavaScript loading and execution in the browser - ...
All you need to know about JavaScript loading and execution in the browser - ...All you need to know about JavaScript loading and execution in the browser - ...
All you need to know about JavaScript loading and execution in the browser - ...
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Karate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made SimpleKarate - Web-Service API Testing Made Simple
Karate - Web-Service API Testing Made Simple
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Techical Workflow for a Startup
Techical Workflow for a StartupTechical Workflow for a Startup
Techical Workflow for a Startup
 
내가써본 nGrinder-SpringCamp 2015
내가써본 nGrinder-SpringCamp 2015내가써본 nGrinder-SpringCamp 2015
내가써본 nGrinder-SpringCamp 2015
 
Knowledge graphs + Chatbots with Neo4j
Knowledge graphs + Chatbots with Neo4jKnowledge graphs + Chatbots with Neo4j
Knowledge graphs + Chatbots with Neo4j
 
DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)DDD 구현기초 (거의 Final 버전)
DDD 구현기초 (거의 Final 버전)
 
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기
[OKKYCON] 박재성 - 의식적인 연습으로 TDD, 리팩토링 연습하기
 
Successful DB migrations with Liquibase
 Successful DB migrations with Liquibase Successful DB migrations with Liquibase
Successful DB migrations with Liquibase
 
TypeScript Best Practices
TypeScript Best PracticesTypeScript Best Practices
TypeScript Best Practices
 
Cours formulaire html - niveau débutant
Cours formulaire html - niveau débutantCours formulaire html - niveau débutant
Cours formulaire html - niveau débutant
 
Whitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applicationsWhitebox testing of Spring Boot applications
Whitebox testing of Spring Boot applications
 
Battle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBootBattle of the frameworks : Quarkus vs SpringBoot
Battle of the frameworks : Quarkus vs SpringBoot
 
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
우아하게 준비하는 테스트와 리팩토링 - PyCon Korea 2018
 
Spring Boot RestApi.pptx
Spring Boot RestApi.pptxSpring Boot RestApi.pptx
Spring Boot RestApi.pptx
 
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
Introduction to react-query. A Redux alternative? (Nikos Kleidis, Front End D...
 
Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문Elastic Search (엘라스틱서치) 입문
Elastic Search (엘라스틱서치) 입문
 

Similar a Why Typescript with Clean Architecture

Create methods to_insert
Create methods to_insertCreate methods to_insert
Create methods to_insertNayanBakhadyo
 
Scala UA: Big Step To Functional Programming
Scala UA: Big Step To Functional ProgrammingScala UA: Big Step To Functional Programming
Scala UA: Big Step To Functional ProgrammingAlex Fruzenshtein
 
Creating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdfCreating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdfShaiAlmog1
 
Creating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdfCreating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdfShaiAlmog1
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsIván López Martín
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo....NET Conf UY
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6sotlsoc
 

Similar a Why Typescript with Clean Architecture (10)

Create methods to_insert
Create methods to_insertCreate methods to_insert
Create methods to_insert
 
Scala UA: Big Step To Functional Programming
Scala UA: Big Step To Functional ProgrammingScala UA: Big Step To Functional Programming
Scala UA: Big Step To Functional Programming
 
Creating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdfCreating a Facebook Clone - Part XI.pdf
Creating a Facebook Clone - Part XI.pdf
 
Creating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdfCreating a Facebook Clone - Part X.pdf
Creating a Facebook Clone - Part X.pdf
 
class object.pptx
class object.pptxclass object.pptx
class object.pptx
 
G3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy AnnotationsG3 Summit 2016 - Taking Advantage of Groovy Annotations
G3 Summit 2016 - Taking Advantage of Groovy Annotations
 
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
Code Smells y Refactoring o haciendo que nuestro codigo huela (y se vea) mejo...
 
Object and class
Object and classObject and class
Object and class
 
OOP Lab Report.docx
OOP Lab Report.docxOOP Lab Report.docx
OOP Lab Report.docx
 
Chapter 6.6
Chapter 6.6Chapter 6.6
Chapter 6.6
 

Último

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 

Último (20)

Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 

Why Typescript with Clean Architecture

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28. class Human { constructor(name, age) { this.name = name; this.age = age; } } class Profile extends React.Component { render() { const yujin = new Human('yujin', 24); return ( <div> <h1>{ yujin.name }</h1> <h2>{ `${yujin.age} ` }</h2> <h3>{ yujin.githubUrl }</h3> </div> ) } }
  • 29. class Human { constructor(name, age) { this.name = name; this.age = age; } } class Profile extends React.Component { render() { const yujin = new Human('yujin', 24); return ( <div> <h1>{ yujin.name }</h1> <h2>{ `${yujin.age} ` }</h2> <h3>{ yujin.githubUrl }</h3> </div> ) } }
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61. class User implements Entity { id: number; name: string; type: User.Type; constructor( id: number, name: string, type: User.Type ) { this.id = id; this.name = name; this.type = type; } }
  • 62. Repository - Entity를 제공하기 위한 Interface - 실제 구현은 DataSource에 의존성을 가지는 Data Layer에서 이루어짐 interface UserRepositoryType extends RepositoryType { search(query: string): Observable<List<User>> }
  • 63. class SearchUsers extends UseCase<List<User>> { private repository: UserRepositoryType; query: string; constructor(repository: UserRepositoryType) { super(); this.repository = repository; } protected build(): Observable<List<User>> { return this.repository.search(this.query); } protected validate(): boolean { return !!this.query; } } UseCase - 도메인 영역의 End-Point - 실제로 서비스를 이용하는 사용자가 하는 행동을 정의 - repository의 interface 기능을 조합하여 원하는 결과값을 하나로 돌려준다
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69. interface UserRepositoryType extends RepositoryType { search(query: string): Observable<List<User>> } class UserRepository implements UserRepositoryType { private githubApi: GithubApiProvider; constructor(githubApi: GithubApiProvider) { this.githubApi = githubApi; } search(query: string): Observable<List<User>> { return this.githubApi.searchUser(query); } }
  • 70.
  • 71. interface ApiProviderDependencies { github: GithubApiProvider; } interface RepositoryDependencies { user: UserRepository; } interface UseCaseDependencies { searchUsers: SearchUsers; } class Context { private githubAxiosInstance: AxiosInstance; private apiProviders: ApiProviderDependencies; private repositories: RepositoryDependencies; useCases: UseCaseDependencies; constructor(githubAxiosInstance: AxiosInstance) { this.githubAxiosInstance = githubAxiosInstance; this.apiProviders = { github: new GithubApiProvider(githubAxiosInstance) }; this.repositories = { user: new UserRepository(this.apiProviders.github) }; this.useCases = { searchUsers: new SearchUsers(this.repositories.user) } } } const axiosInstance = Axios.create({ baseURL: Config.hosts.github, timeout: Config.timeout, headers: { 'Accept': 'application/json' } }); export const Application = new Context(axiosInstance);
  • 72.
  • 73.
  • 74. private renderUsers = (users: List<User>) => <ul> { users.map((user, i) => <li key={ `users-${i}` }> { user.name } </li> ) } </ul>; apply(Application.useCases.searchUsers, it => it.query = query) .runOnAnimateFrame() .subscribe( users => this.setState({ users, fetchState: FetchState.FETCHED }), error => this.setState({ fetchState: FetchState.ERROR }) ) .unsubscribeBy(this.subscriptionBag)
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80. interface Event { id: string; name: string; } class CardCompanyEvent implements Event { id: string; name: string; } class StockFirmEvent implements Event { id: string; name: string; }
  • 81. interface Event { id: string; name: string; } class CardCompanyEvent implements Event { id: string; name: string; } class StockFirmEvent implements Event { id: string; name: string; }