SlideShare a Scribd company logo
1 of 47
Scaling React and Redux at IOOF
Techniques for distributed development of Enterprise Single
Page Apps
Who are we?
Vivian Farrell • IOOF Web dev lead
@viv_f
Emily Rosengren • ThoughtWorks software engineer
@emirose
Who is .
Independent Order of Odd Fellows
International Organisation Of Friends
Industry Organisation of Open Funds
Who is .
Independent Order of Odd Fellows
Setting the scene
Setting the scene
What are we showing you tonight?
How we produce a consistent and theme-able UI
How we partition the Redux store for full decoupled dev of
micro frontends
How we integrate React/Redux micro frontends into Angular
What is a micro frontend?
An encapsulated piece of the front
end, defined by a domain concept
Able to run on it’s own with limited
setup
Published as an npm library that
exports a top-level component
Introducing Redux
Redux Crash Course
All application state is stored in an object tree within the
Redux store
Redux Crash Course
Updates to the state are triggered by dispatching actions to
the store
Redux Crash Course
The dispatched actions are passed to reducer functions.
These reducers update the state
Redux Crash Course
UI components that are subscribed to the state changes will
re-render
Decoupling Redux micro frontends
Avoid action cross talk - actions should not
unintentionally update other micro frontends
Micro frontends define and use their own state
Micro frontends are ignorant of state structure
outside of their own state
Action-type namespacing
Not namespaced
Namespaced
A micro frontend is always passed the entire store when it is wrapped in
<Provider> by the parent
State structure decoupling
It needs a way to navigate to its part of the state without knowing the
structure
State Traversal Map
Store with traversal
Traversal Usage
What about shared state
Accessing shared state
Complete picture
The problem with Traversal Map
Redux Subspace
No more traverse
Still use Traverse for shared state
Will return root state
Quick Summary
Redux Subspace to decouple micro frontends
Traversal Map for shared/global state
UI Consistency
Theming
Parent app sets the theme
Component uses theme
Questions?

More Related Content

What's hot

What's hot (20)

Angular redux
Angular reduxAngular redux
Angular redux
 
React and redux
React and reduxReact and redux
React and redux
 
React js use contexts and useContext hook
React js use contexts and useContext hookReact js use contexts and useContext hook
React js use contexts and useContext hook
 
React and Flux life cycle with JSX, React Router and Jest Unit Testing
React and  Flux life cycle with JSX, React Router and Jest Unit TestingReact and  Flux life cycle with JSX, React Router and Jest Unit Testing
React and Flux life cycle with JSX, React Router and Jest Unit Testing
 
Getting started with Redux js
Getting started with Redux jsGetting started with Redux js
Getting started with Redux js
 
React.js
React.jsReact.js
React.js
 
React js
React jsReact js
React js
 
Redux js
Redux jsRedux js
Redux js
 
React js
React jsReact js
React js
 
React Lifecycle and Reconciliation
React Lifecycle and ReconciliationReact Lifecycle and Reconciliation
React Lifecycle and Reconciliation
 
Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)Introduce Flux & react in practices (KKBOX)
Introduce Flux & react in practices (KKBOX)
 
React js Rahil Memon
React js Rahil MemonReact js Rahil Memon
React js Rahil Memon
 
Designing applications with Redux
Designing applications with ReduxDesigning applications with Redux
Designing applications with Redux
 
7 Redux challenges
7 Redux challenges7 Redux challenges
7 Redux challenges
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Using redux
Using reduxUsing redux
Using redux
 
Reactjs
Reactjs Reactjs
Reactjs
 
An Overview of the React Ecosystem
An Overview of the React EcosystemAn Overview of the React Ecosystem
An Overview of the React Ecosystem
 
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
 

Viewers also liked

cancer-colonoscopy-guide
cancer-colonoscopy-guidecancer-colonoscopy-guide
cancer-colonoscopy-guide
Birgit Bogler
 
Taller n° 1 internet marisol gonzález y verónica sánchez
Taller n° 1 internet marisol gonzález y verónica sánchezTaller n° 1 internet marisol gonzález y verónica sánchez
Taller n° 1 internet marisol gonzález y verónica sánchez
Marisol González
 
Adattata m02-
Adattata m02-Adattata m02-
Adattata m02-
imartini
 
Premio nacional a la mejor labor editorial 2011 zr-infantil
Premio nacional a la mejor labor editorial 2011 zr-infantilPremio nacional a la mejor labor editorial 2011 zr-infantil
Premio nacional a la mejor labor editorial 2011 zr-infantil
xicevip
 

Viewers also liked (20)

cancer-colonoscopy-guide
cancer-colonoscopy-guidecancer-colonoscopy-guide
cancer-colonoscopy-guide
 
EVALUACIÓN PUBLICITARIA : ETIQUETAS ACONCAGUA
EVALUACIÓN PUBLICITARIA : ETIQUETAS ACONCAGUAEVALUACIÓN PUBLICITARIA : ETIQUETAS ACONCAGUA
EVALUACIÓN PUBLICITARIA : ETIQUETAS ACONCAGUA
 
Social Media for Franchising
Social Media for Franchising Social Media for Franchising
Social Media for Franchising
 
Hcad rights remedies 2016
Hcad rights remedies 2016Hcad rights remedies 2016
Hcad rights remedies 2016
 
Dossier de Prensa Campaña Política Ángel Burgos Mesa Presidente
Dossier de Prensa Campaña Política Ángel Burgos Mesa PresidenteDossier de Prensa Campaña Política Ángel Burgos Mesa Presidente
Dossier de Prensa Campaña Política Ángel Burgos Mesa Presidente
 
PHD - Snapshot Rumbo a Río 2016
PHD - Snapshot Rumbo a Río 2016PHD - Snapshot Rumbo a Río 2016
PHD - Snapshot Rumbo a Río 2016
 
TACCBO 2015
TACCBO 2015TACCBO 2015
TACCBO 2015
 
ETC Brussels slides 4.16.10 final
ETC Brussels slides 4.16.10 finalETC Brussels slides 4.16.10 final
ETC Brussels slides 4.16.10 final
 
Programa solar 23 01 12
Programa solar 23 01 12Programa solar 23 01 12
Programa solar 23 01 12
 
Taller n° 1 internet marisol gonzález y verónica sánchez
Taller n° 1 internet marisol gonzález y verónica sánchezTaller n° 1 internet marisol gonzález y verónica sánchez
Taller n° 1 internet marisol gonzález y verónica sánchez
 
Infusing Humor In Unexpected Events
Infusing Humor In Unexpected EventsInfusing Humor In Unexpected Events
Infusing Humor In Unexpected Events
 
PresentacióN Sondeo Nacional Junio 2010
PresentacióN  Sondeo  Nacional  Junio 2010PresentacióN  Sondeo  Nacional  Junio 2010
PresentacióN Sondeo Nacional Junio 2010
 
Presentación Hes®
Presentación Hes®Presentación Hes®
Presentación Hes®
 
Zukunft der Berufe. Welche Kompetenzen wir brauchen. Eine Sketchnote-Präsenta...
Zukunft der Berufe. Welche Kompetenzen wir brauchen. Eine Sketchnote-Präsenta...Zukunft der Berufe. Welche Kompetenzen wir brauchen. Eine Sketchnote-Präsenta...
Zukunft der Berufe. Welche Kompetenzen wir brauchen. Eine Sketchnote-Präsenta...
 
Adattata m02-
Adattata m02-Adattata m02-
Adattata m02-
 
La Geolocalización como herramienta estratégica para la optimización de los n...
La Geolocalización como herramienta estratégica para la optimización de los n...La Geolocalización como herramienta estratégica para la optimización de los n...
La Geolocalización como herramienta estratégica para la optimización de los n...
 
Finanzas familiares2 distribución de la riqueza, razones de la pobreza, pensa...
Finanzas familiares2 distribución de la riqueza, razones de la pobreza, pensa...Finanzas familiares2 distribución de la riqueza, razones de la pobreza, pensa...
Finanzas familiares2 distribución de la riqueza, razones de la pobreza, pensa...
 
India la danza
India la danzaIndia la danza
India la danza
 
Etimologia
EtimologiaEtimologia
Etimologia
 
Premio nacional a la mejor labor editorial 2011 zr-infantil
Premio nacional a la mejor labor editorial 2011 zr-infantilPremio nacional a la mejor labor editorial 2011 zr-infantil
Premio nacional a la mejor labor editorial 2011 zr-infantil
 

Similar to Scaling React and Redux at IOOF

Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
SHAIKIRFAN715544
 

Similar to Scaling React and Redux at IOOF (20)

JOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and ReduxJOSA TechTalks - Better Web Apps with React and Redux
JOSA TechTalks - Better Web Apps with React and Redux
 
Better web apps with React and Redux
Better web apps with React and ReduxBetter web apps with React and Redux
Better web apps with React and Redux
 
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai..."Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
 
React intro
React introReact intro
React intro
 
Redux
ReduxRedux
Redux
 
React gsg presentation with ryan jung &amp; elias malik
React   gsg presentation with ryan jung &amp; elias malikReact   gsg presentation with ryan jung &amp; elias malik
React gsg presentation with ryan jung &amp; elias malik
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
Best practices for creating modular Web applications
Best practices for creating modular Web applicationsBest practices for creating modular Web applications
Best practices for creating modular Web applications
 
Introduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptxIntroduction to ReactJS UI Web Dev .pptx
Introduction to ReactJS UI Web Dev .pptx
 
A React Journey
A React JourneyA React Journey
A React Journey
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Introduction to React JS.pptx
Introduction to React JS.pptxIntroduction to React JS.pptx
Introduction to React JS.pptx
 
an Introduction to Redux
an Introduction to Reduxan Introduction to Redux
an Introduction to Redux
 
React & ES6 Intro
React & ES6 IntroReact & ES6 Intro
React & ES6 Intro
 
downloads_introduction to redux.pptx
downloads_introduction to redux.pptxdownloads_introduction to redux.pptx
downloads_introduction to redux.pptx
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)Developing applications using Embedded Rich Client Platform (eRCP)
Developing applications using Embedded Rich Client Platform (eRCP)
 
React Interview Question & Answers PDF By ScholarHat
React Interview Question & Answers PDF By ScholarHatReact Interview Question & Answers PDF By ScholarHat
React Interview Question & Answers PDF By ScholarHat
 
Building Realtime Mobile Apps with React Native and Elixir
Building Realtime Mobile Apps with React Native and ElixirBuilding Realtime Mobile Apps with React Native and Elixir
Building Realtime Mobile Apps with React Native and Elixir
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
 

Recently uploaded

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
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
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

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
 
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
 
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
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
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
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
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
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
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
 
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 ...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
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
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Scaling React and Redux at IOOF

Editor's Notes

  1. So to start, who is IOOF? Lets see if you can guess what IOOF stands for.
  2. IOOF is primarily a superannuation company. It’s also the biggest independent financial services company in australia not tied to a bank. We have offices in every major city and software engineering teams in Melbourne, Sydney, Hobart and Adelaide. Over the past couple of years, we’ve been rebuilding some of our front ends to in an effort to provide a better experience for our customers.
  3. Let me take you through the journey we’ve been on… In early 2015, in our biannual innovation day (which is our equivalent of a hackathon), one of the teams threw together an Angular app which became the basis of our new Members application This is used by superannuation members to access and manage their account. 6 months later, we started building our next gen financial adviser platform which started as a fork of the Member app because they had overlapping functionality. The Member app went live soon after in sept 2015 and here’s what it looked like
  4. It’s a Angular single page app. This is the IOOF branded app, but it also supports whitelabeling so we can create branded versions of the site for other employer groups.
  5. Emily and I started in January this year. At this stage there was very much stand alone teams for the Adviser and Member apps They were both pure Angular apps. However there were 2 other teams working on front ends one of which was building a react/flux app. This team pushed for us to start using NPM and webpack which we introduced in Feb. This got us off bower and gave us a consistent way for teams to publish and integrate their javascript packages. At this stage we knew we wanted to move towards React, but we hadn’t really settled on state management and our integration strategy. In April, we settled on Redux and came up with an integration strategy, which is part of what we’re going to talk about tonight. This strategy allowed us to scale to 8 teams all building react and redux micro frontends concurrently, that are assembled into a single page app. Our adviser app is currently in pilot phase with the official launch at the end of the month. Here’s a quick look at it.
  6. Like the Member app, it also supports white labelling, which we’ll explain a bit later.
  7. Tonight we’re showing you some of the techniques we used to scale the development of these apps across several teams. More specifically, we’re going to talk to you about how we integrate react and redux into Angular. How we partition the Redux store for decoupled development How we produce a consistent and theme-able UI If you’re not familiar with React or Redux, don’t worry, we’ll explain the fundamentals along the way.
  8. So when we first starting developing microfrontends to be included in the adviser application, our architecture looked something like this. The original angular app became the “parent app.” It contained client-side routing as well as several key parts of the site that had already been built at this point. Separate teams started building microfrontends in react. These were published as npm modules and integrated into the adviser app at compile time, using webpack. This means the entire application was deployed together. This allowed us to do two things right away: We were able to scale development of the adviser front end out to several different teams that were all able to work relatively independently of each other This pattern gave us a path for gradually reducing our dependency on Angular 1 without needing to do a major rewrite right away
  9. We’ve used the term “micro frontend” a few times already, so I want to talk about what we mean but that. A micro front-end is an encapsulated piece of the front end, defined by a domain concept. An example is the “account settings” pages. It should be a decoupled as possible from other micro frontons and the parent application and able to run on its own with limited setup. There are lots of different ways you could approach building and integrating micro frontends. In our case at IOOF, we chose to publish each micro front-end as an npm library that exports a top level React component.
  10. Here’s an example of what that looks like in the application. Everything below the top bar is actually the account settings module. The parents app handles rendering the top portion and importing the account settings component.
  11. Now let’s look at some code. Inside the parent angular app we wrote a directive that takes in a react component. It renders the component using ReactDom. The important part is highlighted right here.
  12. As we started building more complex components, we identified we needed a solution for dealing with application state. Another team had been experimenting with Redux successfully and so we decided to choose Redux to manage state across the whole application Before we talk about how we did that, I want to talk through some redux fundamentals, just in case you haven’t worked with it before. Who here has worked with React before?
  13. Pretend we’re building a todo list app because the world definitely needs another js todo list app.
  14. Now that we all know how redux works, lets talk about how we introduced it into our application. When we introduced redux we decided to use a single global store. The store is initialized by the parent angular app and passed to each react micro fronted. We could have had each micro front-end maintain it’s own state, but we opted not to do this because using a single stop meant: We didn’t have to worry about different micro frontends getting out of sync with each other. Redux gave us some simple techniques for solving cross-cutting application concerns like analytics One of the big advantages we got from choosing redux to manage our application state was that it worked nicely with both the angular and react portions of our application
  15. So, here’s what it looked liked to render a micro-fronted in the parent app once we introduced react. Now each time a micro-fronted is rendered, it’s wrapped in the redux provider and passed the redux store.
  16. Introducing redux also meant that the contract for what a micro-fronted has to export changed slightly in addition to exporting a react component, each micro-frontend also has to export a top level reducer. The parent application imports all of these reducers and combines them
  17. So based on the way we’ve integrated the microfrontend in the previous slide, you end up with a state structure like this. The yellow represents the parts of the state owned by the parent and the boxes represent each micro frontends state. This structure occurs as a consequence of reducer composition through the usage of combineReducers on the previous slide.
  18. One of the key benefits of the micro frontend architecture is it provides clear boundaries between parts of the UI which helps when divvying up development across teams. However, tying everything together with a single global store can get in the way of this. The problem we needed to solve at IOOF was how can we develop our micro frontends in isolation and then integrate them together using a single global store. In order to do this, we had to address 3 things. The first is to avoid cross talk of actions across micro frontends. You don’t want multiple micro frontends inadvertently handling each other’s actions. Secondly, micro frontends need to define and access their own state. You don’t want them navigating into each others state. Thirdly, micro frontends have to be ignorant of state structure outside of their own state. This is very important because a micro frontend with knowledge about the parent state structure results in coupling to that structure. I’m going to step you through the techniques we used to solve these things.
  19. So to prevent action cross talk, we use a very simple namespacing convention So take this action creator, creating an action type of SUBMIT. If 2 micro frontends are expecting a SUBMIT action, they’ll interfere with each other. To prevent this, we prefix the action types with the namespace of INVESTMENTS so that only the investments micro frontend handles this action.
  20. Our second and third goals were about micro frontends using the part of the state they define and being ignorant of the rest of the state. So the problem to solve here is that React components connected to redux are automatically passed the entire store. This is how Provider works. This means that you have to first navigate from the root of the state, which is defined outside of the microfrontend, before accessing the micro frontends state. This structure is most likely created and maintained by another team. Obviously, this means you now have the parent state structure hardcoded in your micro frontend. If the parent app decides to change the structure of the store, your micro frontend is busted. The way we solved this initially was to abstract the location of the micro frontends state to a lookup map. We called it the Traversal map
  21. The traversal map is a simple javascript map where the key is a shared javascript constant (which we call a LocatorKey) and the value is the dot notation to the location in the state tree. It is initialised by the parent app with the Locator Key (exported by the micro frontend) imported by the parent app when initialising the traversal map. Here’s what it would look like for our investments micro frontend, Having the parent app initialise the traversal map gives it the freedom to rearrange the store structure without breaking any of the micro frontends. It also allows 2 parent apps to have different store structures without micro frontends being impacted.
  22. Here’s what the store looks like when we add the traversal map
  23. Now that we have a traversal map defined, how do we use it? We wrote our own little library called redux-traversal. Here’s an example of its usage. The library exports a function called traverse, which we call here passing in the global state and the micro frontends locator key. The sub state is returned. Cool, so now we have a way to avoid having to navigate from the root of the state in our micro frontends which means they are decoupled from any parent state structure.
  24. So what happens if we want to share some state across micro frontends. For example, we might want to share the logged in user profile or some config. The obvious answer would be to put it in a common part of the store where all micro frontends can access it. But how do we do this without creating coupling in the micro frontends. The answer is to use the traversal map
  25. However, there is a slight difference. Since all the micro frontends will be accessing shared state, the locator keys need to be shared. To do this we created a shared library called redux-traversal-constants that all the micro frontends use. The keys are imported where needed and passed into the call to traverse.
  26. This is the complete store structure with our shared state and traversal map added
  27. So this pattern was working great for us until we ran into a problem. Basically we had no way of nesting micro frontends without ending up with the coupling we had tried so hard to avoid. If you want to be able to nest micro frontends in each other and maintain a logical store structure, like in this diagram, there is no way for advanced search to avoid having a hardcoded location to it’s state. It has to navigate first to the Investments state and then to it’s own state nested inside the investments state. Instead of trying to bend the traversal map to our will, I incepted an idea into one of our hobart devs to look at creating a wrapper component similar to Provider that would provide the substate to a micro frontend instead of the global state.
  28. Michael and his twin brother together came up with a library that we’re in the process of open sourcing called Redux Subspace. The name Subspace comes from the concatenation of substate and namespace.
  29. Here’s a look at how it works Start by importing subspace provider In this example, pretend this is your root react component. Here, we’ve wrapped it in Redux provider and provided the global store. Then inside, we have our investments micro frontend. It’s wrapped in our new Subspace provider. Subspace provider has a mapState prop that lets you tell it which part of the state to make available to the micro frontend The namespace prop lets you specify an actionNamespace that will automatically get applied to any action dispatched from inside the investments micro frontend. For namespacing to work, we need to wrap the reducer in the namespaced function from redux-subspace.
  30. So then if we go into our Investment micro frontend, we’ve got our nested advanced search micro frontend, also wrapped in subspace provider. It’s getting it’s state mapped in based off the investments sub state, not the global state To use the state, we don’t have a call to traverse anymore because the micro frontend is passed its substate by substate provider. This is great because it means the micro frontend only needs to care about the structure of the state that it defined.
  31. So what about shared state. The traversal map gave us a really good way to abstract shared state locations. Subspace puts the root state onto the root property by convention which lets you continue to use a traversal map for shared state.
  32. Redux subspace is the result of our journey figuring out how to decouple Redux development. From where we started to where we are now, we’ve come a long way, but it just goes to show that software patterns are fluid and you should never expect to do the same thing for too long
  33. So far we’ve talked through techniques that we used to allow several different teams to work on the same singe page app. Now I want to talk through some of the things we did to make sure the user experience stayed consistent throughout. One of the first things we did when we started scaling development of Adviser out to multiple teams was create a react ui components library. You can see that here (it might look familiar because we used react story book). It contains buttons, loading indicators, and icons, anything we want to look the same no matter where you see it on the site.
  34. The other thing we did to make sure the user experience look consistent was make sure we had single solution to deal with theming. The adviser site has to support two themes, an IOOF one that uses a lot of greens and another one that uses more grey and yellows. We wanted to to make sure each micro-fronted wasn’t implementing this on it’s one, so we wrote two custom reach components.
  35. The first is the ThemeProvider. It takes a theme object as a prop and passes that to all of its children using React context.
  36. If you’ve looked at the react docs at all you might be a bit wary of using context. They give all sorts of disclaimers about why you shouldn’t use context because the API is unstable and subject to change.
  37. We we felt in this scenario it was a pretty clean option and this tweet kind of illustrates why. We decided we fell nicely into the second if block and promised to write a HOC.
  38. Here’s what it looks like to use the theme. To access to the theme, out primaryButton is wrapped in the themed HOC. All the themed component does is take the theme from the context and pass it to our PrimaryButton as a prop. This allows us to isolate our components from changes to the context API. This PrimaryButton will show up primaryLight, whether that’s green or yellow
  39. Here’s what that looks like, when we’re integrating our micro-frontends into the parent app. Now each time a micro-fronted is rendered, in addition to wrapping it in the redux provider, we wrap it in out custom theme provider and pass it the theme. This means that it’s the parent app’s responsibility to know what the theme should be and pass it to each micro frontend. The micro frontends don’t need to care what the theme is or even know that there are multiple themes, they just need to use whatever is passed in.
  40. Here’s what that looks like in the site. You’re actually looking at the same page on the two different pages. Pretty much the only code needed to accomplish this is the two components you already saw.
  41. With these techniques and quite a bit of team collaboration we were able to bring everything together into this nice user experience. Hopefully our users will never notice that this single site was actually built by 8 different teams distributed across 3 locations.