Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Building a workable Chrome Extension in React+R...
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Nikos Kostoulas
May 20, 2016
0
130
Building a workable Chrome Extension in React+Redux
Devit workshop 2016
Nikos Kostoulas
May 20, 2016
Tweet
Share
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
2
250
Google's AI Overviews - The New Search
badams
0
910
The untapped power of vector embeddings
frankvandijk
1
1.6k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Code Reviewing Like a Champion
maltzj
527
40k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
730
Skip the Path - Find Your Career Trail
mkilby
0
57
What does AI have to do with Human Rights?
axbom
PRO
0
2k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
250
How GitHub (no longer) Works
holman
316
140k
Transcript
Building a Workable Chrome Extension in React & Redux Devit
Conference • May 2016
We are... Sokratis Vidros Senior Software Engineer @ Workable sokratisvidros
Nikos Kostoulas Senior Software Engineer @ Workable nkostoulas
Chrome Extensions
Chrome Extensions
Chrome Extensions Building blocks
Background page
Content script
Popup
Options
Background and content script are separate JS runtimes
• Simple one-time requests • Long-lived connections Message passing Background
script Content script
Spoiled™ Chrome Extension https://github.com/Workable/devit2016
1. Select a GoT character name in narratives 2. View
their spoiler on the side Scenario
Demo
Let’s Dev it!
Background page • Fetch spoiler from server • Memoize last
spoiler Responsibilities Content script • Interact with page DOM • Display the spoiler on the side
Background page Flow Content script 1. Select name in text
2. Send it to the background 6.Render the spoiler 5. Pass it to the content script 3. Receive the selected name 4. Fetch spoiler from server
We would also like to... • Render data efficiently •
Achieve content script isolation • Facilitate message passing • Add memory
Can we use React/Redux?
React/Redux View Action Middleware Reducers Store
{ tab, foreground: true, type: ... } Content script Background
script Architecture View Action Middleware Reducers Store Action Middleware Reducers Store { payload: … } { background: true, type: ... }
Toolbelt + Redux Redux notify React Redux thunk Redux Chrome
Gofer
Show us the code!
Step 1: Scaffolding • Add manifest.json • Add the background
Redux Stack • Add the content script React/Redux Stack • Set-up reduxChromeGofer middleware > git checkout step1
Step 2: Content script encapsulation • Leverage React componentization ◦
Root container component ◦ Spoiler presentational component • Enclose root component in a shadow root ◦ Style encapsulation and isolation > git checkout step2
Step 3: Request spoiler Background Script Content Script { background:
true, type: “REQUEST_SPOILER”, name: ... } • Transfer action from content to background • Execute ajax request from the background ◦ No same-origin policy limitations > git checkout step3 GET /spoilers.json?c=eddard Select name
Content Script Background Script Step 4: Receive spoiler dispatch(receiveSpoiler()) {
foreground: true, tab, type: “RECEIVE_SPOILER”, spoiler: ... } • Dispatch receive action upon retrieval • Pass the spoiler to content script > git checkout step4
• Listen to background script state changes • Push background
state to every content script Step 5: Sync state Background Script Content Script Content Script Content Script > git checkout step5
None
✓ Back end engineers ✓ Front end engineers ✓ Machine
learning engineers ✓ Data scientists ✓ DevOps ✓ UI / UX designers We’re constantly looking for: Apply at careers.workable.com