SlideShare a Scribd company logo
1 of 22
Download to read offline
Andrii Sliusar
Module Architecture
of React-Redux
Applications
Problem statement
• Application is getting bigger – the
monolithic approach doesn’t work well
• We need common structure and
development approach
• The input threshold and the connectivity
problem
Why do we need module architecture?
Module architecture is the type of architecture where an application is semantically
split on components.
For what?
• Development speed
• Scaling
• Reduced maintenance costs
• Decrease the input threshold
How to ensure the necessary modularity?
The modularity level depends on the scale of the application.
Everything that can be identified as a separate component / project should be separated.
What should we split?
• Main Components
• Data model
• Business logic
Modern React-Redux elements
Component – generic React component
Container – js-file to connect React component with state and actions
ActionCreators – creates actions for components
Reducers – change Redux store
State – describes Redux store
Selectors – select data from the store to containers, wired with State
The connectivity problem of React-Redux architecture?
In order for the project to be scalable and readable, it is necessary to ensure minimal
connectivity between modules.
Modular application architecture
Root folder
/project
/core
/scenes
app.ts
The main idea to keep everything as simple as possible on each level of the architecture.
Extract business logic and domain
How to organize the architecture of modules?
/scenes
/scene1
/scenes
/scene3
/actions
/containers
/components
/reducers
/state
/scene2
index.tsx
Redux is a Data bus
What to do with styles and static
resources?
• Styles and static resources are in same folder with a component
• SASS is good, but JS-based styles have more options
• Create themes from the very beginning
1. Create a domain oriented State model
2. Create a component (const or class)
3. Add styles in the same folder
4. Create other logic (actions, reducers, ...)
If it becomes more complex
5. Move the connection of props to containers
Algorithm for creating a React component
• It’s a clear way to work with state
• The same data model can be used in DB
• Build domain model from the beginning
Why do we need State model?
• Everything is sorted by domains
• It’s clearly easier to modify state
and selectors
export default class UserState {
public name:string;
public getName = (state) =>
state.user.name;
}
const mapStateToProps = (state, props) => ({
name: UserState.getName(state)
});
Wire selectors with state
• They need be standardized
• The same const between
modules, but different values
• They can be processed inside
different modules
enum ACTION_TYPE {
UPDATE_NAME = Symbol('UPDATE_USER_NAME')
}
export const updateName = (name: string) => ({
type: ACTION_TYPE.UPDATE_NAME,
name
})
then
import {ACTION_TYPE as USER_ACTION_TYPE}
from ‘./actions’;
What to do with actions?
• Code structure
• Simplify code maintenance
• Interface API
• There isn't strictly rule to use it
• First, the domain is developed in the
form of interfaces, then implementation
• Additional features (enam,… etc.)
Why and how to use TypeScript?
• JEST test are faster
• Tests are stored with components
• Different types of test for actions, reducers
and React-components
• Mocking is embedded into JEST
File structure
/scene1
/actions
/__tests__ -- unit
/containers
/components
/__tests__ -- snapshot
/reducers
/__tests__ -- unit
/state
JEST testing
Rules how to make snapshot
testing successful:
• Create very simple
components (no more
then 70 rows)
• Mock children components
• After a release of a
module override
snapshots only after a
code review
it("should render with a href, className, onDownloadClick and id", () => {
const props = {
href: "http://download.com",
className: "DownloadButton",
id: "id",
onDownloadClick: jest.fn()
};
const component = mount(<DownloadButton {...props} />);
expect(component).toMatchSnapshot();
});
SNAPSHOT testing
// snapshot с forEach
["day", "week", "month"].forEach((period) => {
it(`should have selectedPeriod of ${period}`, () => {
const component = mount(
<PeriodDropdown onSelectPeriod={jest.fn()} selectedPeriod={period} />
);
expect(component).toMatchSnapshot();
});
});
SNAPSHOT testing
Pros:
• Scaling
• Reduced maintenance costs
• Decrease the input threshold
Cons:
• Amount of folders/files
• Bigger amount of code
Pros and Cons of Modular architecture
Thank you!

More Related Content

What's hot

Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMJason Myers
 
learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .paradisetechsoftsolutions
 
React js programming concept
React js programming conceptReact js programming concept
React js programming conceptTariqul islam
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITnamespaceit
 
Spring Boot Interview Questions | Edureka
Spring Boot Interview Questions | EdurekaSpring Boot Interview Questions | Edureka
Spring Boot Interview Questions | EdurekaEdureka!
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentationThanh Tuong
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.jsDoug Neiner
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMJimit Shah
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJSKnoldus Inc.
 

What's hot (20)

Introduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORMIntroduction to SQLAlchemy ORM
Introduction to SQLAlchemy ORM
 
React JS - Introduction
React JS - IntroductionReact JS - Introduction
React JS - Introduction
 
learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .learn what React JS is & why we should use React JS .
learn what React JS is & why we should use React JS .
 
React js programming concept
React js programming conceptReact js programming concept
React js programming concept
 
Introduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace ITIntroduction to React JS for beginners | Namespace IT
Introduction to React JS for beginners | Namespace IT
 
React js
React jsReact js
React js
 
React introduction
React introductionReact introduction
React introduction
 
Spring Boot Interview Questions | Edureka
Spring Boot Interview Questions | EdurekaSpring Boot Interview Questions | Edureka
Spring Boot Interview Questions | Edureka
 
ReactJS presentation
ReactJS presentationReactJS presentation
ReactJS presentation
 
A Brief Introduction to React.js
A Brief Introduction to React.jsA Brief Introduction to React.js
A Brief Introduction to React.js
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React js for beginners
React js for beginnersReact js for beginners
React js for beginners
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
React workshop
React workshopReact workshop
React workshop
 
React js
React jsReact js
React js
 
React js
React jsReact js
React js
 
React.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOMReact.js - The Dawn of Virtual DOM
React.js - The Dawn of Virtual DOM
 
Introduction to ReactJS
Introduction to ReactJSIntroduction to ReactJS
Introduction to ReactJS
 
Introduction to Redux
Introduction to ReduxIntroduction to Redux
Introduction to Redux
 
Reactjs
Reactjs Reactjs
Reactjs
 

Similar to Module Architecture of React-Redux Applications

Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"LogeekNightUkraine
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; reduxGirish Talekar
 
Unit-III(Design).pptx
Unit-III(Design).pptxUnit-III(Design).pptx
Unit-III(Design).pptxFajar Baskoro
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...MskDotNet Community
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsJennifer Estrada
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net coreSam Nasr, MCSA, MVP
 
Datastage to ODI
Datastage to ODIDatastage to ODI
Datastage to ODINagendra K
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08Luktalja
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & PatternsInocentshuja Ahmad
 
Architectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym ZhiltsovArchitectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym ZhiltsovLohika_Odessa_TechTalks
 
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020OdessaJS Conf
 
Component based development | what, why and how
Component based development | what, why and howComponent based development | what, why and how
Component based development | what, why and howRakesh Kumar Jha
 
Rapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackRapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackAvinash Kaza
 
Migrating traditional Java EE Applications to mobile
Migrating traditional Java EE Applications to mobileMigrating traditional Java EE Applications to mobile
Migrating traditional Java EE Applications to mobileSerge Pagop
 
Clean architecture
Clean architectureClean architecture
Clean architecture.NET Crowd
 

Similar to Module Architecture of React-Redux Applications (20)

Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"Andrii Sliusar "Module Architecture of React-Redux Applications"
Andrii Sliusar "Module Architecture of React-Redux Applications"
 
Getting started with react &amp; redux
Getting started with react &amp; reduxGetting started with react &amp; redux
Getting started with react &amp; redux
 
J2 ee archi
J2 ee archiJ2 ee archi
J2 ee archi
 
Unit-III(Design).pptx
Unit-III(Design).pptxUnit-III(Design).pptx
Unit-III(Design).pptx
 
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...Дмитрий Тежельников  «Разработка вэб-решений с использованием Asp.NET.Core и ...
Дмитрий Тежельников «Разработка вэб-решений с использованием Asp.NET.Core и ...
 
reactJS
reactJSreactJS
reactJS
 
React & redux
React & reduxReact & redux
React & redux
 
Comparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAsComparing Angular and React JS for SPAs
Comparing Angular and React JS for SPAs
 
Clean architecture with asp.net core
Clean architecture with asp.net coreClean architecture with asp.net core
Clean architecture with asp.net core
 
Datastage to ODI
Datastage to ODIDatastage to ODI
Datastage to ODI
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
Om & React.js
Om & React.jsOm & React.js
Om & React.js
 
Architectural Design & Patterns
Architectural Design&PatternsArchitectural Design&Patterns
Architectural Design & Patterns
 
Architectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym ZhiltsovArchitectural peripherals of react by Vadym Zhiltsov
Architectural peripherals of react by Vadym Zhiltsov
 
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020
'Architecture of modern frontend apps' by YURIY DOBRYANSKYY at OdessaJS'2020
 
Component based development | what, why and how
Component based development | what, why and howComponent based development | what, why and how
Component based development | what, why and how
 
Rapid Application Development with MEAN Stack
Rapid Application Development with MEAN StackRapid Application Development with MEAN Stack
Rapid Application Development with MEAN Stack
 
Migrating traditional Java EE Applications to mobile
Migrating traditional Java EE Applications to mobileMigrating traditional Java EE Applications to mobile
Migrating traditional Java EE Applications to mobile
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 

Recently uploaded

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Recently uploaded (20)

How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Module Architecture of React-Redux Applications

  • 1. Andrii Sliusar Module Architecture of React-Redux Applications
  • 2. Problem statement • Application is getting bigger – the monolithic approach doesn’t work well • We need common structure and development approach • The input threshold and the connectivity problem
  • 3. Why do we need module architecture? Module architecture is the type of architecture where an application is semantically split on components. For what? • Development speed • Scaling • Reduced maintenance costs • Decrease the input threshold
  • 4. How to ensure the necessary modularity? The modularity level depends on the scale of the application. Everything that can be identified as a separate component / project should be separated. What should we split? • Main Components • Data model • Business logic
  • 5. Modern React-Redux elements Component – generic React component Container – js-file to connect React component with state and actions ActionCreators – creates actions for components Reducers – change Redux store State – describes Redux store Selectors – select data from the store to containers, wired with State
  • 6. The connectivity problem of React-Redux architecture? In order for the project to be scalable and readable, it is necessary to ensure minimal connectivity between modules.
  • 8. Root folder /project /core /scenes app.ts The main idea to keep everything as simple as possible on each level of the architecture.
  • 10. How to organize the architecture of modules? /scenes /scene1 /scenes /scene3 /actions /containers /components /reducers /state /scene2 index.tsx
  • 11. Redux is a Data bus
  • 12. What to do with styles and static resources? • Styles and static resources are in same folder with a component • SASS is good, but JS-based styles have more options • Create themes from the very beginning
  • 13. 1. Create a domain oriented State model 2. Create a component (const or class) 3. Add styles in the same folder 4. Create other logic (actions, reducers, ...) If it becomes more complex 5. Move the connection of props to containers Algorithm for creating a React component
  • 14. • It’s a clear way to work with state • The same data model can be used in DB • Build domain model from the beginning Why do we need State model?
  • 15. • Everything is sorted by domains • It’s clearly easier to modify state and selectors export default class UserState { public name:string; public getName = (state) => state.user.name; } const mapStateToProps = (state, props) => ({ name: UserState.getName(state) }); Wire selectors with state
  • 16. • They need be standardized • The same const between modules, but different values • They can be processed inside different modules enum ACTION_TYPE { UPDATE_NAME = Symbol('UPDATE_USER_NAME') } export const updateName = (name: string) => ({ type: ACTION_TYPE.UPDATE_NAME, name }) then import {ACTION_TYPE as USER_ACTION_TYPE} from ‘./actions’; What to do with actions?
  • 17. • Code structure • Simplify code maintenance • Interface API • There isn't strictly rule to use it • First, the domain is developed in the form of interfaces, then implementation • Additional features (enam,… etc.) Why and how to use TypeScript?
  • 18. • JEST test are faster • Tests are stored with components • Different types of test for actions, reducers and React-components • Mocking is embedded into JEST File structure /scene1 /actions /__tests__ -- unit /containers /components /__tests__ -- snapshot /reducers /__tests__ -- unit /state JEST testing
  • 19. Rules how to make snapshot testing successful: • Create very simple components (no more then 70 rows) • Mock children components • After a release of a module override snapshots only after a code review it("should render with a href, className, onDownloadClick and id", () => { const props = { href: "http://download.com", className: "DownloadButton", id: "id", onDownloadClick: jest.fn() }; const component = mount(<DownloadButton {...props} />); expect(component).toMatchSnapshot(); }); SNAPSHOT testing
  • 20. // snapshot с forEach ["day", "week", "month"].forEach((period) => { it(`should have selectedPeriod of ${period}`, () => { const component = mount( <PeriodDropdown onSelectPeriod={jest.fn()} selectedPeriod={period} /> ); expect(component).toMatchSnapshot(); }); }); SNAPSHOT testing
  • 21. Pros: • Scaling • Reduced maintenance costs • Decrease the input threshold Cons: • Amount of folders/files • Bigger amount of code Pros and Cons of Modular architecture