SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Painless Migration From
Backbone to React/Redux
Jim Sullivan
Engineering Manager @ Conductor
jim@conductor.com
Painless Migration From
Backbone to React/Redux
Jim Sullivan
Engineering Manager @ Conductor
jim@conductor.com
Painless Migration From
Backbone to React/Redux
Jim Sullivan
Engineering Manager @ Conductor
jim@conductor.com
any Legacy Framework
Painless Migration From
Backbone to React/Redux
Jim Sullivan
Engineering Manager @ Conductor
jim@conductor.com
any Legacy Framework
4
5
6
JS @ CONDUCTOR: A BRIEF HISTORY
7
 Growing JavaScript codebase since 2009
JS @ CONDUCTOR: A BRIEF HISTORY
8
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
JS @ CONDUCTOR: A BRIEF HISTORY
9
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
JS @ CONDUCTOR: A BRIEF HISTORY
10
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
JS @ CONDUCTOR: A BRIEF HISTORY
11
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
JS @ CONDUCTOR: A BRIEF HISTORY
12
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
JS @ CONDUCTOR: A BRIEF HISTORY
13
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
 Now we had
 Object-oriented, non-global
JS @ CONDUCTOR: A BRIEF HISTORY
14
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
 Now we had
 Object-oriented, non-global
 Standard ways to do common actions
JS @ CONDUCTOR: A BRIEF HISTORY
15
 Growing JavaScript codebase since 2009
 As of 2012
 Large, complex JavaScript application
 Homebrew/vanilla
 Time to choose a framework!
 Now we had
 Object-oriented, non-global
 Standard ways to do common actions
 Architecture for layout and messaging
JS @ CONDUCTOR: A BRIEF HISTORY
16
 5 years!
JS @ CONDUCTOR: A BRIEF HISTORY
17
 5 years!
 As of 2017 – front end developers still feeling friction
JS @ CONDUCTOR: A BRIEF HISTORY
18
 5 years!
 As of 2017 – front end developers still feeling friction
 Hard to reason about data flow, messaging between components
 Hard to reason about where state lived
 Hard to reason about composing complex components and UIs
 etc. etc.
JS @ CONDUCTOR: A BRIEF HISTORY
19
 Flow of data and communication between components is more coherent
 State management is clearer
 Handling of state changes is more predictable
 Best practices and patterns around composing components and Uis
 etc. etc.
WHY REACT/REDUX?
20
THE PLAN FOR MIGRATING TO REACT/REDUX
21
Easy!
THE PLAN FOR MIGRATING TO REACT/REDUX
22
Easy!
All frontend engineers
THE PLAN FOR MIGRATING TO REACT/REDUX
23
Easy!
All frontend engineers
drop everything and stop building and
enhancing client-facing features
THE PLAN FOR MIGRATING TO REACT/REDUX
24
Easy!
All frontend engineers
drop everything and stop building and
enhancing client-facing features
until we’ve completely replaced hundreds
of thousands of lines of JS code! 👍 👍
THE PLAN FOR MIGRATING TO REACT/REDUX
25
Easy!
All frontend engineers
drop everything and stop building and
enhancing client-facing features
until we’ve completely replaced hundreds
of thousands of lines of JS code! 👍 👍
THE PLAN FOR MIGRATING TO REACT/REDUX
26
THE (REAL) PLAN FOR MIGRATING TO REACT/REDUX
27
THE (REAL) PLAN FOR MIGRATING TO REACT/REDUX
”…gradually create a new
system around the edges
of the old, letting it grow
slowly over several years
until the old system is
strangled.”
28
THE STRANGLER PATTERN
A B C
👤
29
THE STRANGLER PATTERN
A B C
👤
X
30
THE STRANGLER PATTERN
A1 B C
👤
X
31
THE STRANGLER PATTERN
A1 B1 C1
👤
X Y Z
32
 Where it gets tricky
THE STRANGLER PATTERN ON THE FRONT END
33
 Where it gets tricky
1. “As a user, I see a fancy new version of some common component”
 Rebuild it in React 👍
 New component needs to live on Backbone screens 😱
THE STRANGLER PATTERN ON THE FRONT END
34
 Where it gets tricky
1. “As a user, I see a fancy new version of some common component”
 Rebuild it in React 👍
 New component needs to live on Backbone screens 😱
2. “As a user, I see a fancy new/updated screen containing some old
common components”
 Build screen in React/Redux 👍
 Old backbone components live on that screen 😱
THE STRANGLER PATTERN ON THE FRONT END
35
 Straightforward application of Strangler Pattern in UI:
 Building new or updating old screens to 100% React/Redux
 Having 100% React/Redux screens live in the same application as 100%
Backbone/Marionette screens
THE STRANGLER PATTERN ON THE FRONT END
36
 Straightforward application of Strangler Pattern in UI:
 Building new or updating old screens to 100% React/Redux
 Having 100% React/Redux screens live in the same application as 100%
Backbone/Marionette screens
 Trickier application of Strangler Pattern in UI: hybrid screens
 What we needed:
1. Ability to wrap React Components in Backbone Views
2. Ability to wrap Backbone views in React Components and have them
interact with Redux
THE STRANGLER PATTERN ON THE FRONT END
37
WARNING
38
 We need a Backbone-style render method
 React Component’s render method returns React elements intended
for the Virtual DOM
 Backbone View’s render method directly modifies a DOM element
 We need it to be easy so people use it!
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
39
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
function createComponentBackboneWrapper(ComponentClass) {
const WrapperView = Backbone.View.extend({
// initialize(options)
// render()
// update(newProps)
});
return WrapperView;
};
40
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
initialize(options) {
WrapperView.__super__.initialize.call(this, options);
const getPropsFromOptions = (options) => pick(options, (value, key) =>
contains(Object.keys(ComponentClass.propTypes, key));
this._componentProps = Object.freeze(getPropsFromOptions(options));
},
41
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
initialize(options) {
WrapperView.__super__.initialize.call(this, options);
const getPropsFromOptions = (options) => pick(options, (value, key) =>
contains(Object.keys(ComponentClass.propTypes, key));
this._componentProps = Object.freeze(getPropsFromOptions(options));
},
render() {
ReactDOM.render(React.createElement(ComponentClass,
this._componentProps), this.el);
return this;
},
42
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
update(newComponentProps) {
this._componentProps = Object.freeze(Object.assign(
{},
this._componentProps,
getPropsFromOptions(newComponentProps, propTypeKeys)
));
return this.render();
}
43
import MyButton from = ‘./ReactButtonComponent’;
const WrapperView = createComponentBackboneWrapper(MyButton);
const view = new WrapperView({
text: 'Click me',
el: $('#the-button')
});
view.render();
view.update({ text: 'Don’t click me' });
WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
44
Three things to consider about wrapped Backbone views:
1. They will render HTML directly to the DOM, which is not consistent
with React Component.render
2. They may be stateful, and therefore are not disposable, i.e. must not
be re-instantiated
3. They may need to affect shared state, i.e. dispatch Redux actions
WRAPPING BACKBONE VIEWS IN REACT/REDUX
45
WRAPPING BACKBONE VIEWS: RENDERING
46
WRAPPING BACKBONE VIEWS: RENDERING
47
WRAPPING BACKBONE VIEWS: RENDERING
48
class WrappedBackboneTextArea extends Component {
render() {
return ( <div ref={(ref) => { this._wrapperRef = ref; } } /> );
}
}
WRAPPING BACKBONE VIEWS: RENDERING
49
class WrappedBackboneTextArea extends Component {
render() {
return ( <div ref={(ref) => { this._wrapperRef = ref; } } /> );
}
componentDidMount() {
this.wrappedTextArea = new MyBackboneTextArea ({
el: this._wrapperRef
});
this.wrappedTextArea.render();
}
}
WRAPPING BACKBONE VIEWS: RENDERING
50
WRAPPING BACKBONE VIEWS: MAINTAINING STATE
51
class WrappedBackboneTextArea extends Component {
shouldComponentUpdate() {
return false;
}
WRAPPING BACKBONE VIEWS: MAINTAINING STATE
52
class WrappedBackboneTextArea extends Component {
shouldComponentUpdate() {
return false;
}
componentWillReceiveProps(nextProps) {
...
}
}
WRAPPING BACKBONE VIEWS: MAINTAINING STATE
53
class WrappedBackboneTextArea extends Component {
shouldComponentUpdate() {
return false;
}
componentWillReceiveProps(nextProps) {
this.wrappedTextArea.model.set(nextProps);
}
}
WRAPPING BACKBONE VIEWS: MAINTAINING STATE
54
WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
55
class WrappedBackboneTextArea extends Component {
static propTypes = {
onChange: PropTypes.func.isRequired
};
}
WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
56
class WrappedBackboneTextArea extends Component {
static propTypes = {
onChange: PropTypes.func.isRequired
};
componentDidMount() {
...
this.wrappedTextArea.model.on('change:text', () => {
this.props.onChange(this.wrappedTextArea.model.get(‘text’));
});
}
}
WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
57
WHERE ARE WE NOW? WHAT’S NEXT?
58
 ~ 80% of front end development is happening in React/Redux right now
 That number is growing quickly
WHERE ARE WE NOW? WHAT’S NEXT?
59
 ~ 80% of front end development is happening in React/Redux right now
 That number is growing quickly
 How do we measure success? Shipping React/Redux code isn’t enough.
WHERE ARE WE NOW? WHAT’S NEXT?
60
 ~ 80% of front end development is happening in React/Redux right now
 That number is growing quickly
 How do we measure success? Shipping React/Redux code isn’t enough.
 Quality
WHERE ARE WE NOW? WHAT’S NEXT?
61
 ~ 80% of front end development is happening in React/Redux right now
 That number is growing quickly
 How do we measure success? Shipping React/Redux code isn’t enough.
 Quality
 Velocity
WHERE ARE WE NOW? WHAT’S NEXT?
62
 ~ 80% of front end development is happening in React/Redux right now
 That number is growing quickly
 How do we measure success? Shipping React/Redux code isn’t enough.
 Quality
 Velocity
 Anecdotally: most engineers using R/R are saying they are faster, more
confident about quality, less frustrated
WHERE ARE WE NOW? WHAT’S NEXT?
63
QUESTIONS?

Weitere ähnliche Inhalte

Ähnlich wie Painless Migrations from Backbone to React/Redux

React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison500Tech
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJSLinkMe Srl
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react jsStephieJohn
 
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 malikLama K Banna
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and ReduxBoris Dinkevich
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs[T]echdencias
 
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!Ryan Roemer
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in ProductionSeokjun Kim
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today Nitin Tyagi
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptJohn Stevenson
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practicesfloydophone
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Devang Garach
 
Performance #3 layout&amp;animation
Performance #3  layout&amp;animationPerformance #3  layout&amp;animation
Performance #3 layout&amp;animationVitali Pekelis
 

Ähnlich wie Painless Migrations from Backbone to React/Redux (20)

Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
ReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparisonReactJS vs AngularJS - Head to Head comparison
ReactJS vs AngularJS - Head to Head comparison
 
Corso su ReactJS
Corso su ReactJSCorso su ReactJS
Corso su ReactJS
 
Fundamental concepts of react js
Fundamental concepts of react jsFundamental concepts of react js
Fundamental concepts of react js
 
Rethinking React
Rethinking ReactRethinking React
Rethinking React
 
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
 
Introduction to ReactJS and Redux
Introduction to ReactJS and ReduxIntroduction to ReactJS and Redux
Introduction to ReactJS and Redux
 
React & Redux for noobs
React & Redux for noobsReact & Redux for noobs
React & Redux for noobs
 
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
Backbone.js with React Views - Server Rendering, Virtual DOM, and More!
 
Lec7Handout.ppt
Lec7Handout.pptLec7Handout.ppt
Lec7Handout.ppt
 
React Native in Production
React Native in ProductionReact Native in Production
React Native in Production
 
React - Start learning today
React - Start learning today React - Start learning today
React - Start learning today
 
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in ClojurescriptProgscon 2017: Taming the wild fronteer - Adventures in Clojurescript
Progscon 2017: Taming the wild fronteer - Adventures in Clojurescript
 
The productive developer guide to React
The productive developer guide to ReactThe productive developer guide to React
The productive developer guide to React
 
Rethinking Best Practices
Rethinking Best PracticesRethinking Best Practices
Rethinking Best Practices
 
Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5Overview of React.JS - Internship Presentation - Week 5
Overview of React.JS - Internship Presentation - Week 5
 
Performance #3 layout&amp;animation
Performance #3  layout&amp;animationPerformance #3  layout&amp;animation
Performance #3 layout&amp;animation
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
React workshop
React workshopReact workshop
React workshop
 

Kürzlich hochgeladen

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 

Kürzlich hochgeladen (20)

Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Painless Migrations from Backbone to React/Redux

  • 1. Painless Migration From Backbone to React/Redux Jim Sullivan Engineering Manager @ Conductor jim@conductor.com Painless Migration From Backbone to React/Redux Jim Sullivan Engineering Manager @ Conductor jim@conductor.com
  • 2. Painless Migration From Backbone to React/Redux Jim Sullivan Engineering Manager @ Conductor jim@conductor.com any Legacy Framework
  • 3. Painless Migration From Backbone to React/Redux Jim Sullivan Engineering Manager @ Conductor jim@conductor.com any Legacy Framework
  • 4. 4
  • 5. 5
  • 6. 6 JS @ CONDUCTOR: A BRIEF HISTORY
  • 7. 7  Growing JavaScript codebase since 2009 JS @ CONDUCTOR: A BRIEF HISTORY
  • 8. 8  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application JS @ CONDUCTOR: A BRIEF HISTORY
  • 9. 9  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla JS @ CONDUCTOR: A BRIEF HISTORY
  • 10. 10  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework! JS @ CONDUCTOR: A BRIEF HISTORY
  • 11. 11  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework! JS @ CONDUCTOR: A BRIEF HISTORY
  • 12. 12  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework! JS @ CONDUCTOR: A BRIEF HISTORY
  • 13. 13  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework!  Now we had  Object-oriented, non-global JS @ CONDUCTOR: A BRIEF HISTORY
  • 14. 14  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework!  Now we had  Object-oriented, non-global  Standard ways to do common actions JS @ CONDUCTOR: A BRIEF HISTORY
  • 15. 15  Growing JavaScript codebase since 2009  As of 2012  Large, complex JavaScript application  Homebrew/vanilla  Time to choose a framework!  Now we had  Object-oriented, non-global  Standard ways to do common actions  Architecture for layout and messaging JS @ CONDUCTOR: A BRIEF HISTORY
  • 16. 16  5 years! JS @ CONDUCTOR: A BRIEF HISTORY
  • 17. 17  5 years!  As of 2017 – front end developers still feeling friction JS @ CONDUCTOR: A BRIEF HISTORY
  • 18. 18  5 years!  As of 2017 – front end developers still feeling friction  Hard to reason about data flow, messaging between components  Hard to reason about where state lived  Hard to reason about composing complex components and UIs  etc. etc. JS @ CONDUCTOR: A BRIEF HISTORY
  • 19. 19  Flow of data and communication between components is more coherent  State management is clearer  Handling of state changes is more predictable  Best practices and patterns around composing components and Uis  etc. etc. WHY REACT/REDUX?
  • 20. 20 THE PLAN FOR MIGRATING TO REACT/REDUX
  • 21. 21 Easy! THE PLAN FOR MIGRATING TO REACT/REDUX
  • 22. 22 Easy! All frontend engineers THE PLAN FOR MIGRATING TO REACT/REDUX
  • 23. 23 Easy! All frontend engineers drop everything and stop building and enhancing client-facing features THE PLAN FOR MIGRATING TO REACT/REDUX
  • 24. 24 Easy! All frontend engineers drop everything and stop building and enhancing client-facing features until we’ve completely replaced hundreds of thousands of lines of JS code! 👍 👍 THE PLAN FOR MIGRATING TO REACT/REDUX
  • 25. 25 Easy! All frontend engineers drop everything and stop building and enhancing client-facing features until we’ve completely replaced hundreds of thousands of lines of JS code! 👍 👍 THE PLAN FOR MIGRATING TO REACT/REDUX
  • 26. 26 THE (REAL) PLAN FOR MIGRATING TO REACT/REDUX
  • 27. 27 THE (REAL) PLAN FOR MIGRATING TO REACT/REDUX ”…gradually create a new system around the edges of the old, letting it grow slowly over several years until the old system is strangled.”
  • 31. 31 THE STRANGLER PATTERN A1 B1 C1 👤 X Y Z
  • 32. 32  Where it gets tricky THE STRANGLER PATTERN ON THE FRONT END
  • 33. 33  Where it gets tricky 1. “As a user, I see a fancy new version of some common component”  Rebuild it in React 👍  New component needs to live on Backbone screens 😱 THE STRANGLER PATTERN ON THE FRONT END
  • 34. 34  Where it gets tricky 1. “As a user, I see a fancy new version of some common component”  Rebuild it in React 👍  New component needs to live on Backbone screens 😱 2. “As a user, I see a fancy new/updated screen containing some old common components”  Build screen in React/Redux 👍  Old backbone components live on that screen 😱 THE STRANGLER PATTERN ON THE FRONT END
  • 35. 35  Straightforward application of Strangler Pattern in UI:  Building new or updating old screens to 100% React/Redux  Having 100% React/Redux screens live in the same application as 100% Backbone/Marionette screens THE STRANGLER PATTERN ON THE FRONT END
  • 36. 36  Straightforward application of Strangler Pattern in UI:  Building new or updating old screens to 100% React/Redux  Having 100% React/Redux screens live in the same application as 100% Backbone/Marionette screens  Trickier application of Strangler Pattern in UI: hybrid screens  What we needed: 1. Ability to wrap React Components in Backbone Views 2. Ability to wrap Backbone views in React Components and have them interact with Redux THE STRANGLER PATTERN ON THE FRONT END
  • 38. 38  We need a Backbone-style render method  React Component’s render method returns React elements intended for the Virtual DOM  Backbone View’s render method directly modifies a DOM element  We need it to be easy so people use it! WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
  • 39. 39 WRAPPING REACT COMPONENTS IN BACKBONE VIEWS function createComponentBackboneWrapper(ComponentClass) { const WrapperView = Backbone.View.extend({ // initialize(options) // render() // update(newProps) }); return WrapperView; };
  • 40. 40 WRAPPING REACT COMPONENTS IN BACKBONE VIEWS initialize(options) { WrapperView.__super__.initialize.call(this, options); const getPropsFromOptions = (options) => pick(options, (value, key) => contains(Object.keys(ComponentClass.propTypes, key)); this._componentProps = Object.freeze(getPropsFromOptions(options)); },
  • 41. 41 WRAPPING REACT COMPONENTS IN BACKBONE VIEWS initialize(options) { WrapperView.__super__.initialize.call(this, options); const getPropsFromOptions = (options) => pick(options, (value, key) => contains(Object.keys(ComponentClass.propTypes, key)); this._componentProps = Object.freeze(getPropsFromOptions(options)); }, render() { ReactDOM.render(React.createElement(ComponentClass, this._componentProps), this.el); return this; },
  • 42. 42 WRAPPING REACT COMPONENTS IN BACKBONE VIEWS update(newComponentProps) { this._componentProps = Object.freeze(Object.assign( {}, this._componentProps, getPropsFromOptions(newComponentProps, propTypeKeys) )); return this.render(); }
  • 43. 43 import MyButton from = ‘./ReactButtonComponent’; const WrapperView = createComponentBackboneWrapper(MyButton); const view = new WrapperView({ text: 'Click me', el: $('#the-button') }); view.render(); view.update({ text: 'Don’t click me' }); WRAPPING REACT COMPONENTS IN BACKBONE VIEWS
  • 44. 44 Three things to consider about wrapped Backbone views: 1. They will render HTML directly to the DOM, which is not consistent with React Component.render 2. They may be stateful, and therefore are not disposable, i.e. must not be re-instantiated 3. They may need to affect shared state, i.e. dispatch Redux actions WRAPPING BACKBONE VIEWS IN REACT/REDUX
  • 48. 48 class WrappedBackboneTextArea extends Component { render() { return ( <div ref={(ref) => { this._wrapperRef = ref; } } /> ); } } WRAPPING BACKBONE VIEWS: RENDERING
  • 49. 49 class WrappedBackboneTextArea extends Component { render() { return ( <div ref={(ref) => { this._wrapperRef = ref; } } /> ); } componentDidMount() { this.wrappedTextArea = new MyBackboneTextArea ({ el: this._wrapperRef }); this.wrappedTextArea.render(); } } WRAPPING BACKBONE VIEWS: RENDERING
  • 50. 50 WRAPPING BACKBONE VIEWS: MAINTAINING STATE
  • 51. 51 class WrappedBackboneTextArea extends Component { shouldComponentUpdate() { return false; } WRAPPING BACKBONE VIEWS: MAINTAINING STATE
  • 52. 52 class WrappedBackboneTextArea extends Component { shouldComponentUpdate() { return false; } componentWillReceiveProps(nextProps) { ... } } WRAPPING BACKBONE VIEWS: MAINTAINING STATE
  • 53. 53 class WrappedBackboneTextArea extends Component { shouldComponentUpdate() { return false; } componentWillReceiveProps(nextProps) { this.wrappedTextArea.model.set(nextProps); } } WRAPPING BACKBONE VIEWS: MAINTAINING STATE
  • 54. 54 WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
  • 55. 55 class WrappedBackboneTextArea extends Component { static propTypes = { onChange: PropTypes.func.isRequired }; } WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
  • 56. 56 class WrappedBackboneTextArea extends Component { static propTypes = { onChange: PropTypes.func.isRequired }; componentDidMount() { ... this.wrappedTextArea.model.on('change:text', () => { this.props.onChange(this.wrappedTextArea.model.get(‘text’)); }); } } WRAPPING BACKBONE VIEWS: AFFECTING SHARED STATE
  • 57. 57 WHERE ARE WE NOW? WHAT’S NEXT?
  • 58. 58  ~ 80% of front end development is happening in React/Redux right now  That number is growing quickly WHERE ARE WE NOW? WHAT’S NEXT?
  • 59. 59  ~ 80% of front end development is happening in React/Redux right now  That number is growing quickly  How do we measure success? Shipping React/Redux code isn’t enough. WHERE ARE WE NOW? WHAT’S NEXT?
  • 60. 60  ~ 80% of front end development is happening in React/Redux right now  That number is growing quickly  How do we measure success? Shipping React/Redux code isn’t enough.  Quality WHERE ARE WE NOW? WHAT’S NEXT?
  • 61. 61  ~ 80% of front end development is happening in React/Redux right now  That number is growing quickly  How do we measure success? Shipping React/Redux code isn’t enough.  Quality  Velocity WHERE ARE WE NOW? WHAT’S NEXT?
  • 62. 62  ~ 80% of front end development is happening in React/Redux right now  That number is growing quickly  How do we measure success? Shipping React/Redux code isn’t enough.  Quality  Velocity  Anecdotally: most engineers using R/R are saying they are faster, more confident about quality, less frustrated WHERE ARE WE NOW? WHAT’S NEXT?

Hinweis der Redaktion

  1. Topic sounds focused
  2. While I’m at it
  3. All migrations are painful Legacy code is painful Maybe you’ve never felt that pain >
  4. Green field If you’ve been eng long enough >
  5. Some Green field Brownfield Unless you want to stay forever browner First a little about how we got to our BF
  6. Disorganized code Managing state globally Jquery manipulating dom inconsistent, hard to understand
  7. Conductor growing Business growing Application growing
  8. Data lived in models HTML lived in views and templates
  9. Making requests to APIs Rendering, re-rendering, removing elements in the DOM
  10. Continued to grow Doing something right!
  11. Examples very briefly
  12. Not backbone’s fault? But easy to fuck up.
  13. We knew where we Wanted to be…
  14. needed a practical plan
  15. What’s this?
  16. Often used to describe BE Can be applied to FE migration Brief explanation of SP on FE
  17. Example features Backbone Want to migrate
  18. Utopia! Using SP on on FE gets tricky
  19. Not just talking about diff screens sidebyside in app Components sbs in page
  20. Not just talking about diff screens sidebyside in app Components sbs in page
  21. Not just talking about diff screens sidebyside in app Components sbs in page
  22. To summarize
  23. Let’s dig in
  24. Last one: we want you to use react Tempting not to when just working on a small piece
  25. A little too big for one slide 😄
  26. Have not yet initialized react component
  27. Created react component using props from options ReactDOM.Render usually used for root of react app
  28. hack for emulating passing props No way to explicitly update props Backbone render destructive - consistent Freeze is used to make props immutable
  29. Go through Let’s talk about first one
  30. Overall theme of page: “Are you sure?”
  31. You might not know this if you’re new Overall theme of page: “Are you sure?”
  32. Callback will be called when component mounts Arg will be that DOM element
  33. We also call remove on unmount
  34. Now we have wrapped BB rendering 2nd thing – must not re-instantiate BB view Statefulness
  35. 2nd thing – must not re-instantiate BB view Statefulness
  36. Usually not this simple Ok third thing – redux
  37. Ok third thing – redux
  38. Ok third thing – redux
  39. Mention lack of bugs
  40. ADD: specifically less race conditions around events firing Consistent information across everything