Introducing Facebook's React and ReactJS.NET @ Microsoft's TechDays 2015 in The Netherlands.
Is the HTML of your SPA also filled with unmaintainable semi code? Is data binding performance causing you headaches? Don’t you remember how data finds its way to the UI? Let's React! There is a new functional approach to tackle traditional complexities in JavaScript: ReactJS (open source). Maligned in 2013, embraced in 2015 by the largest websites in the world. Let's build fast components in a lasting and meaningful way. This session is a full introduction to the React JavaScript library, its virtual DOM and synthetic events. ReactJS.NET for ASP.NET MVC (and OWIN) will be covered as well. With ReactJS.NET your app starts with a server side rendered page, ideal for search engine optimization (SEO). Does your page need to work under IE8? No problem! The best part: You do not have to build your entire site with ReactJS, but you can start with any parts you like. Afterwards this talk you can immediately apply React in your daily work. See http://reactjs.net and http://reactjs.com
2. REACT
A JAVASCRIPT LIBRARY FOR
BUILDING USER INTERFACES
REACT .NET
REACT ♥ C#
AND ASP.NET MVC
REACT NATIVE
A FRAMEWORK FOR
BUILDING NATIVE APPS
USING REACT
What is React?
2
3. Made by Facebook
Used by Facebook
IE8 and up
All recent mobile browsers
GitHub Fork for IE6 & IE7
Native apps for iOS (Android soon)
• Windows already allows for native JavaScript applications.
What is React?
3
6. What do you use now?
What are your current problems?
Why React?
6
7. Synchronizing state is hard
=> Hence Databinding
=> Chain reaction of callbacks
Small changes can lead to unprecedented reaction
What is the effect on performance?
Updating the DOM is hard
Debugging
• Where to place breakpoints?
• Forward, not backward
• Line by line
Problems
7
8. “Our intellectual powers are rather geared to master static relations and our
powers to visualize processes evolving in time are relatively poorly
developed.
For that reason we should do (as wise programmers aware of our
limitations) our utmost to shorten the conceptual gap between the static
program and the dynamic process, to make the correspondence between
the program (spread out in text space) and the process (spread out in time)
as trivial as possible”
Edsger Dijkstra
8
9. Rebuild instead of update
Immutable instead of Mutable
• Flow: Uni-directional instead of bi-directional
Debugging
• Minimum number of change locations (where to place breakpoint?)
• Move from change to change instead of from line to line
Solutions
9
10. 20th century: Old server, easy: Throw away old page and generate a new page on every
request.
2004: HTML = Composed string
2007: HTML = Composed string with XSS protection
2010: Reduce server callbacks by having more JavaScript (databinding/MVC/etc.)
2013: React
History
10
18. Minimum number of differences
Fastest possible changes
Minimize garbage collection
Only write to the browser DOM
Event handlers only attached to browser DOM root
Smart Virtual DOM
18
24. Synthetic, cross-browser wrapper for the browser event
Identical on all browsers
Same as browser event, incl. capturing/bubbling phases.
Extra event property: nativeEvent
Events
24
29. Mutable
Only changeable by setState()
• Currently also by replaceState(), but that is no longer supported by ES6 classes.
Demo:
https://github.com/rickbeerendonk/react-om-examples/tree/master/05.%20State
State
)
29
36. “Flux is the application architecture that Facebook uses for building client-side web
applications. It complements React's composable view components by utilizing a
unidirectional data flow.”
https://facebook.github.io/flux/
Flux
36