SlideShare a Scribd company logo
1 of 35
UNIVERSA
WRITE ONCE, RUN EVERYWHERE
HELLO
WHO AM I?
▸Jan Kjærgaard
▸Writing software since I were 14
▸Started getting paid for software five years ago, full time
professional for two years.
▸React for one and a half years now
WHO ARE YOU?
YOUR CORE TECHNOLOGY
BEFORE WE START
TERMINOLOGY
▸Client: What the user uses to access your service
▸Platform: Where your client is running
USERS NEED SOME WAY TO OPERATE THIS SERVICE
USERS NEED SOME WAY TO OPERATE THIS SERVICE
USERS NEED SOME WAY TO OPERATE THIS SERVICE
USERS NEED SOME WAY TO OPERATE THIS SERVICE
USERS NEED SOME WAY TO OPERATE THIS SERVICE
USERS NEED SOME WAY TO OPERATE THIS SERVICE
THE PROBLEM
THE PROBLEM IS COMPLEX
▸Tons of ‘clients’ want access to your service
▸You end up with tons of code and complexity
▸More teams
▸Longer QA time
▸More expensive
▸The should be a better way
SOME SOLUTIONS EXISTS
SHARE SOME CODE
▸Share the native code
▸Xamarin
▸Flutter
▸React-native
▸…
▸Web client is still living in its own world.
Platform
Platform APIs (UI) Standard stuff
Your APP
View logic Business logic
Language runtime
Platform
Platform APIs (UI) Standard stuff
Your APP
View logic Business logic
Language runtime
Framework
Crossplatform app
Platform
Android/iOS Standard stuff
Your APP
View logic Business logic
Language runtime
React Native
Crossplatform app
Virtual DOM
Browser
Your APP
View logic Business logic
React Native Web
Virtual DOM
Runtime
App code
React-Native
Bundler task
entry points
Bootstrap
ESSENTIALLY
▸Crossplatform consists of two parts
▸Make sure you code against some API
▸Make sure the API runs on target platform
▸Perform proper bootstrapping of application to run on
platform
HTTPS://GITHUB.COM/JANKJR/UNIVERSAL-JS
A LOOK AT A UNIVERSAL JAVASCRIPT
SETUP
▸Code is located at: https://github.com/jankjr/universal-js
HTTPS://GITHUB.COM/JANKJR/UNIVERSAL-JS
A LOOK AT A UNIVERSAL JAVASCRIPT
SETUP
▸Code is located at: https://github.com/jankjr/universal-js
express ‘main’
web client ‘router’
native client ‘router’
part of web bootstrapping
BOOTSTRAPPING THE WEB APP
HTML.JS
▸Render static website as a
react-like page
▸Pass in bundled
scripts/styles
▸Pre-render current app
state (children)
▸[include tracking/analytic
scripts here as well]
PRERENDER APP SERVERSIDE
SERVER.JS
▸Resolve path/query into a
route
▸Render route into a string
and a set of css-rules
▸Emit HTML and javascript
bundles
▸THIS IS serverside
rendering in a nutshell
BOOTSTRAP THE CLIENT (ONCE READY)
ENTRY
native index.platform.js
index.web.js
WEBPACK SETUP
Make sure we alias react-native-web to react-native
Can also be done using a plugin
DEMOTIME
!
PROS
▸Single language across server, mobile, and web client
▸Code sharing, Less code
▸Smaller team
▸The platform is (Mostly*) abstracted away
* Look, you will fight cross platform incompatibilities, k?
DEALING DIFFERENCES
EXAMPLE: LINKS AND BUTTONS
▸Web has the notion of links <a>’s
▸not a thing for apps (Not really)
▸We need some way to toggle between behaviour
DEALING DIFFERENCES
DYNAMIC SWITCHES
▸Inside Link.js
DEALING DIFFERENCES
STATIC SWITCHING
▸Rewrite imports at build time, as seen by server web pack
config*
* resolve/alias does not work for building node server
▸We’re back to compile-time switches. Like in the good ol’
days.
CONS!
NOT EVERYTHING IS GOLDEN
▸There ARE differences in the execution environment
▸Try to solve as many problems using vanilla react-native
components.
▸The web accepts more styling than apps, try to style mobile
first.
▸React native runs future JS. More or less needs a
precompile step
▸Browser != Phone, so you will still do a lot of testing.
CONCLUSION?
CONCLUSION
▸This is still not mature tech.
▸But.. The first, true, write once, run everywhere?
THANK
YOU
QUESTION
S?

More Related Content

What's hot

Native client (Евгений Эльцин)
Native client (Евгений Эльцин)Native client (Евгений Эльцин)
Native client (Евгений Эльцин)
Ontico
 

What's hot (8)

JavaScript - No Longer A Toy Language
JavaScript - No Longer A Toy LanguageJavaScript - No Longer A Toy Language
JavaScript - No Longer A Toy Language
 
JavaScript No longer A “toy” Language
JavaScript No longer A “toy” LanguageJavaScript No longer A “toy” Language
JavaScript No longer A “toy” Language
 
Node.js with Express
Node.js with ExpressNode.js with Express
Node.js with Express
 
Javascript Unit Testing Tools
Javascript Unit Testing ToolsJavascript Unit Testing Tools
Javascript Unit Testing Tools
 
Web designing avdhesh
Web designing avdheshWeb designing avdhesh
Web designing avdhesh
 
The JAMStack (Javascript, APIs, Markup).
The JAMStack (Javascript, APIs, Markup).The JAMStack (Javascript, APIs, Markup).
The JAMStack (Javascript, APIs, Markup).
 
Saying goodbye to localhost - developing in the cloud with Cloud9 IDE
Saying goodbye to localhost - developing in the cloud with Cloud9 IDESaying goodbye to localhost - developing in the cloud with Cloud9 IDE
Saying goodbye to localhost - developing in the cloud with Cloud9 IDE
 
Native client (Евгений Эльцин)
Native client (Евгений Эльцин)Native client (Евгений Эльцин)
Native client (Евгений Эльцин)
 

Similar to Universal react

Similar to Universal react (20)

Power-up services with gRPC
Power-up services with gRPCPower-up services with gRPC
Power-up services with gRPC
 
The GrapQL ecosystem
The GrapQL ecosystemThe GrapQL ecosystem
The GrapQL ecosystem
 
Streamlining API with Swagger.io
Streamlining API with Swagger.ioStreamlining API with Swagger.io
Streamlining API with Swagger.io
 
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
London Hashicorp Meetup #8 -  Testing Programmable Infrastructure By Matt LongLondon Hashicorp Meetup #8 -  Testing Programmable Infrastructure By Matt Long
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
 
GraphQL IndyJS April 2016
GraphQL IndyJS April 2016GraphQL IndyJS April 2016
GraphQL IndyJS April 2016
 
QFast
QFastQFast
QFast
 
Future of web development
Future of web developmentFuture of web development
Future of web development
 
React Native
React NativeReact Native
React Native
 
"Building Cross-platform Without Sacrificing Performance" by Simon Sturmer (K...
"Building Cross-platform Without Sacrificing Performance" by Simon Sturmer (K..."Building Cross-platform Without Sacrificing Performance" by Simon Sturmer (K...
"Building Cross-platform Without Sacrificing Performance" by Simon Sturmer (K...
 
Building and Deploying PHP Applications, PHPTour 2016
Building and Deploying PHP Applications, PHPTour 2016Building and Deploying PHP Applications, PHPTour 2016
Building and Deploying PHP Applications, PHPTour 2016
 
Intro to DevOps
Intro to DevOpsIntro to DevOps
Intro to DevOps
 
WordPress with WP Engine and the Agency Partner Program: Getting Set Up
WordPress with WP Engine and the Agency Partner Program: Getting Set UpWordPress with WP Engine and the Agency Partner Program: Getting Set Up
WordPress with WP Engine and the Agency Partner Program: Getting Set Up
 
Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017
Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017
Docker as a Multitool: DevOps with Docker at Azure Bootcamp Linz 2017
 
2nd AMIMOTO: WordPress + Amazon Web Services Singapore
2nd AMIMOTO: WordPress + Amazon Web Services Singapore2nd AMIMOTO: WordPress + Amazon Web Services Singapore
2nd AMIMOTO: WordPress + Amazon Web Services Singapore
 
Progressive Web Apps - deep dive
Progressive Web Apps - deep diveProgressive Web Apps - deep dive
Progressive Web Apps - deep dive
 
Testing servers like software
Testing servers like softwareTesting servers like software
Testing servers like software
 
Brujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalabilityBrujug Jenkins pipeline scalability
Brujug Jenkins pipeline scalability
 
(Micro?)services architecture in practice
(Micro?)services architecture in practice(Micro?)services architecture in practice
(Micro?)services architecture in practice
 
The Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year RetrospectiveThe Best Feature of Go – A 5 Year Retrospective
The Best Feature of Go – A 5 Year Retrospective
 
Container Orchestration with Traefik 2.x
Container Orchestration with Traefik 2.xContainer Orchestration with Traefik 2.x
Container Orchestration with Traefik 2.x
 

Recently uploaded

Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara ServicesVVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
VVIP Call Girls Nalasopara : 9892124323, Call Girls in Nalasopara Services
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 

Universal react

Editor's Notes

  1. Hey everyone! (I hope you all have had a beer. *drink*. They are over there, and somebody else paid for them. So don’t be shy.) I hope you are doing well! Today we are going to be talking about a subject I have been exploring for the past fours months, and have been fascinating me a lot for at least as long as apps and mobile platforms have been around. That is the notion of true, single codebase, cross platform app. Inside the JS world, some, me included, have dubbed these technologies universal JS.
  2. But first things first. My name is Jan. I have been programming since about 14, my first languages we’re C and Java. Back end I mostly wanted to make games, then I realised that it was nice to earn a salary as well. I have been professionally developing software for five years now. I first heard about this mysterious ‘react’ technology two years ago, but it took me about six month before I really started exploring it.
  3. I expect most of you work in tech some way or another, and therefore probably have developed some wonderful product/service. I expect your situation to be approximately like this.
  4. And your core technology/service is simply mind blowing
  5. At some point you will have to give your customers access, and instantly it becomes a huge task. Who knew customers wanted to access your service using more than one platform and expect a good user experience?
  6. Users usually start here, and open up a browser.
  7. So you think, ah, mobile first websites. Easy enough.
  8. Well, at some point they will also access your site using one of these. At some point they will start complaining, the user experience kinda sucks on the first set of devices.
  9. So you need an app. Now you have two(or more) code bases serving the same content.
  10. At some point you start getting weird visitors. Clients with very weird user agents. You have been invaded by indexers. You have to love these guys, they promote your site. But they don’t really care for your carefully crafted JS. So, your mobile first, desktop friendly mess now has to be served by clients that don’t even want to execute your JS.
  11. But lets hold take a step back for a moment and just focus on the users. One way to approach this is just to focus on the web. Every user has a device which is capable of executing HTML5 in some way or another.
  12. This is where you scream cross platform. Because YES! The mobile experience does not have to be spread out between multiple codebases. There is Xamarin, React-native and so on! But the web client is still living on its own in this setups. Depending on use cases this might not be too bad. But what I am going to show is that it is possible to use the same code everywhere!
  13. Lets take a look at a typical app. Usually the code is split into multiple categories handling different responsibilities. The core is the business logic, handling, app state, authentication, and communication with your services. Then the view logic handles displaying the the app state. In react this is what you would emit during a render call. The trick to make something cross platform is making these two layers run on the platform without changing too much of the core business logic. This is usually it is easy enough to make the core business logic run. Most of what language libraries offer is easy to implement, since all platforms more or work with similar low-level primitives. The hard part is the view logic.
  14. Lets take a look at a typical app. Usually the code is split into multiple categories handling different responsibilities. The core is the business logic, handling, app state, authentication, and communication with your services. Then the view logic handles displaying the the app state. In react this is what you would emit during a render call. The trick to make something cross platform is making these two layers run on the platform without changing too much of the core business logic. This is usually it is easy enough to make the core business logic run. Most of what language libraries offer is easy to implement, since all platforms more or work with similar low-level primitives. The hard part is the view logic.
  15. Lets take a look at a typical app. Usually the code is split into multiple categories handling different responsibilities. The core is the business logic, handling, app state, authentication, and communication with your services. Then the view logic handles displaying the the app state. In react this is what you would emit during a render call. The trick to make something cross platform is making these two layers run on the platform without changing too much of the core business logic. This is usually it is easy enough to make the core business logic run. Most of what language libraries offer is easy to implement, since all platforms more or work with similar low-level primitives. The hard part is the view logic.
  16. Lets take a look at a typical app. Usually the code is split into multiple categories handling different responsibilities. The core is the business logic, handling, app state, authentication, and communication with your services. Then the view logic handles displaying the the app state. In react this is what you would emit during a render call. The trick to make something cross platform is making these two layers run on the platform without changing too much of the core business logic. This is usually it is easy enough to make the core business logic run. Most of what language libraries offer is easy to implement, since all platforms more or work with similar low-level primitives. The hard part is the view logic.
  17. Lets take a look at a typical app. Usually the code is split into multiple categories handling different responsibilities. The core is the business logic, handling, app state, authentication, and communication with your services. Then the view logic handles displaying the the app state. In react this is what you would emit during a render call. The trick to make something cross platform is making these two layers run on the platform without changing too much of the core business logic. This is usually it is easy enough to make the core business logic run. Most of what language libraries offer is easy to implement, since all platforms more or work with similar low-level primitives. The hard part is the view logic.
  18. I’ve set up a react-native-web project to show one way of configuring such a project, and if you are interested in this topic, I would suggest you should even take a look.
  19. Here is how the code more or less looks like. One important thing to notice is that we are essentially developing four ‘main’ entries into our program. There is the static renderer, which is connected to the web and server code. We will explore this in more detail. Then there is the native and web js. These two define the web app and native app router component respectively. Both essentially listen for changes in the route, and render the corresponding view based on ‘where’ we are in the application.
  20. Lets take a look at how SSR rendering could look in a react app. Here is a weird trick, in vanilla react, all html5 tags are valid. Also top level tags such as html. This means react is actually a very suitable tempting language all on its own. Neat huh? No more handlebars! Anyway, the thing that this does is essentially to lay out the base for our web app. This is also where you would configure analytics and the like.
  21. If we take a step up and look at how the serverside router is set up. You will notice that we essentially do one thing. Resolve the current route. Render current route/state into string. Emit html page for web-client.