SlideShare ist ein Scribd-Unternehmen logo
1 von 59
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe React
architecture and workflow
typedef React = State -> View Haxe Meetup, 2 March 2017
Definition
• What Haxe is:
• Haxe is an open source toolkit based on a modern high level strictly typed
programming language, a state-of-the-art light-speed cross-compiler, a
complete cross-platform standard library, and ways to access to each
platform's native capabilities.
• What Haxe is NOT:
• Haxe is not a high level framework. It's a toolkit that can be used to build
cross-platform tools and frameworks.
typedef React = State -> View Haxe Meetup, 2 March 2017
Write or reuse?
• Massive.co has contributed many state of the art open-source
libraries for the Haxe language
• Unit testing, code coverage, MVC, dependency injection, event signals,…
• It is a big effort and responsibility to write and maintain OSS
typedef React = State -> View Haxe Meetup, 2 March 2017
Crossplatform or not?
• The Haxe language can target many platforms
• JavaScript, Flash, C++, C#, Java, Python, Lua, Php…
• We usually make sure to write dependency-free, universal, libraries
• But ultimately our business is focusing on HTML/JS
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe on JavaScript
• JavaScript is our VM – one of the fastest, most stable, and richest
• Other companies are building/maintaining very solid libraries
typedef React = State -> View Haxe Meetup, 2 March 2017
Why Haxe on JavaScript?
• JavaScript is predominantly ES6 and TypeScript nowadays
• Yet people (and companies) continue betting on other langs
• Dart, Elm, PureScript, ScalaJS, OcamlJS,…
• And we love Haxe because it’s faster, smarter and easy to learn
typedef React = State -> View Haxe Meetup, 2 March 2017
React on Haxe
• Most popular view-layer library
• No need for Facebook hatin’
• It’s opensource and well maintained
• and many companies contribute to creating
something much wider than its core
typedef React = State -> View Haxe Meetup, 2 March 2017
React on Haxe
• Building great Haxe support alone is a big effort
• Core library by Massive.co (@dpeek then @elsassph)
• https://github.com/massiveinteractive/haxe-react
• React-native and other externs by @kevinresol and @zabojad
• https://github.com/haxe-react
• https://github.com/tokomlabs/haxe-react-addons
typedef React = State -> View Haxe Meetup, 2 March 2017
First, understand JavaScript
• Learn how things work in vanilla
JavaScript first
• Play with React using ‘create-react-app’
typedef React = State -> View Haxe Meetup, 2 March 2017
First, understand JavaScript
• Anything you can do in JavaScript can be
expressed in Haxe (depending on how
dirty you’re willing to feel)
• For articles on Haxe-JS interop:
http://philippe.elsass.me
typedef React = State -> View Haxe Meetup, 2 March 2017
React
typedef React = State -> View Haxe Meetup, 2 March 2017
React JavaScript syntax
• XML in your JavaScript?
(heresy!)
• It’s called JSX
• It’s only metadata
typedef React = State -> View Haxe Meetup, 2 March 2017
React JavaScript syntax
typedef React = State -> View Haxe Meetup, 2 March 2017
React JavaScript syntax
• Fancy binding syntax (uni-directional)
typedef React = State -> View Haxe Meetup, 2 March 2017
React: all the cool kids are doing it
• React is a Virtual DOM engine from Facebook/Instagram
• Only view layer, not an architecture (unlike Angular)
• Straightforward and robust
• Not limited to HTML DOM – there are renderers for canvas, PixiJS…
• Not limited to the browser – react-native is maturing
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe-React
• Nearly as fancy, macro-powered, syntax
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe-React
• Supports the same binding syntax
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe-React
• Or Haxe string-interpolation syntax (advantage: completion)
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe-React
• Optimiser can generate inline objects at compile time in place of
React.createElement() calls for optimal performance
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe-React
• JSX parser is complete with a few minor limitations
• Generator supports all the advanced features* like spread operator,
default values or functional stateless components
• Optimiser does better than JS compilers
* React is feature rich, learn it properly
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: initial render
• Initial render in HTML
• Should be called only once, targeting a root DOM element
• Multiple roots allowed
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: initial render
• Without components, the rendered DOM will never change
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: initial render
• Only components are able to trigger re-renders
• A dynamic application will need at least one in the initial render
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: Component
• A component must have a render function returning one element.
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: Component
• Components can hold “state”; state changes schedule a re-render
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: Component
• Components can receive read-only “props” from their parent
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: Component
• A stateless component can be advantageously replaced by a function
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: avoid inheritance
• High-Order Component: extend other components
typedef React = State -> View Haxe Meetup, 2 March 2017
React basics: avoid inheritance
• Component wrapper with provided children elements
typedef React = State -> View Haxe Meetup, 2 March 2017
Advanced React: containing updates
• Warning: state changes can be costly!
• State changes schedule a re-render
• Children may re-render in depth, unless you prevent it:
• Carefully add ”key” attributes
• extend PureComponent
• override shouldComponentUpdate(nextProps, nextState):Bool
• Prevent re-render only if needed, and as early as possible
typedef React = State -> View Haxe Meetup, 2 March 2017
React: production-ready
• React works great, right now, it’s stable
and well supported. Enjoy.
• React’s approach is inspiring many
other frameworks, some using JSX.
• Haxe React is in serious shape and used
in large productions at Massive.
typedef React = State -> View Haxe Meetup, 2 March 2017
React architectures
typedef React = State -> View Haxe Meetup, 2 March 2017
Architecture
• React is just a view layer – it doesn’t enforce any architecture
• Basic props and callbacks don’t scale
• Haxe React comes with 2 examples: Redux and MMVC
typedef React = State -> View Haxe Meetup, 2 March 2017
Architecture: Redux
https://github.com/elsassph/haxe-react-redux
• Disclaimer: Redux is NOT an architecture itself
• Redux is a popular state library for Model-Intent architectures
• Sample follows one possible architecture pattern with Redux
• Warning: expect to do a lot of refactoring
typedef React = State -> View Haxe Meetup, 2 March 2017
Architecture: MVC
https://github.com/elsassph/haxe-react-mmvc
• Massive’s MMVC offers a battle-tested architecture inspired by
RobotLegs, used on large scale, large complexity applications
• Macro-based Dependency Injection, Command and View mediation
• MMVC fits naturally with React Components: just add an interface
typedef React = State -> View Haxe Meetup, 2 March 2017
Advanced React : the “context”
• Architecturing React apps requires more than “props”
• Libraries and framework need to provide data to any child
• This mechanism is the React “context”
• Recommendation: do not use this “context” liberally
typedef React = State -> View Haxe Meetup, 2 March 2017
Advanced React : the “context”
• This mechanism should be used through black boxes:
• “Provider” React components inject values in context
• “Consumer” React components query those values
• Examples of uses:
• Redux: components need to access the store
• MMVC: components mediation
• React-router: components need to trigger navigation
typedef React = State -> View Haxe Meetup, 2 March 2017
Code splitting
To reduce the initial payload
To load features on-demand
typedef React = State -> View Haxe Meetup, 2 March 2017
Code splitting
• Haxe compiler historically outputs a single, optimized, JS file
• Traditional JavaScript do concat and minify JS files into one
• Problem: single big JS bundle = bad user experience
typedef React = State -> View Haxe Meetup, 2 March 2017
Code splitting
• Modern JavaScript has embraced the
multi-file approach and figured:
• Bundling with code splitting
• Hot module replacement during development
• Can we benefit from that in Haxe?
typedef React = State -> View Haxe Meetup, 2 March 2017
Modular JS
https://github.com/*/modular-js
Goal: comply with JavaScript bundlers
typedef React = State -> View Haxe Meetup, 2 March 2017
Modular JS
• Create one JS file for each Haxe class
• Then use a JavaScript bundler as with regular JS (profit!)
• Risks:
• Experimental with multiple approaches/forks
• Custom JavaScript generator
• No sourcemaps
• Requires excellent understanding of JS bundlers
• Unclear code-splitting strategy (and no project examples)
typedef React = State -> View Haxe Meetup, 2 March 2017
Modular JS - AMD
• Asynchronous module system (RequireJS)
• https://github.com/explorigin/modular-js (creator, unmaintained)
• https://github.com/jcward/modular-js (used in production)
• Bundlers: SystemJS, Webpack
typedef React = State -> View Haxe Meetup, 2 March 2017
Modular JS - CommonJS
• As popularized by nodejs, used by ES6/TypeScript
• https://github.com/kevinresol/modular-js
• https://github.com/MatthijsKamstra/modular-js (fork)
• Bundlers: SystemJS, Webpack, Browserify
typedef React = State -> View Haxe Meetup, 2 March 2017
Modular JS – Why choose it?
• Modular-js is a sensible choice if you’re 100% going JS.
• But it requires you to become an expert in Haxe JS output, the custom JS
generator, JS in general, and your JS bundler of choice.
• Competes with Haxe Modular
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular
https://github.com/elsassph/haxe-modular
Goal: staying true to Haxe
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – Goals
https://github.com/elsassph/haxe-modular
• Use (tweak) regular Haxe compiler output
• No JS bundler dependency (but could)
• Adaptable to other Haxe targets
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – The promise
https://github.com/elsassph/haxe-modular
• Automatically split monolithic Haxe JS (and sourcemap!) output
• Hot-reload capable (React reload built-in)
• Bundle NPM dependencies together separately
• Will be used in production at Massive
• Risks:
• Experimental
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – Usage
• Explicitly load a components on demand:
• The class (and its dependencies) will be loaded (once) asynchronously when
requested
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – Usage
• With React-router:
• The view class (and its dependencies) will be loaded (once) when navigating
to a specific “route”
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – How?
• Bundle.load(classRef) or RouteBundle.load(classRef) are macros
• classRef is memorised and code replaced by Require.load(bundleId)
• Normal Haxe JS output is sent to a temp file to be processed post-build
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – How?
PlayerView
temp/output.js bin/index.js
PlayerView
temp/playerview.js
output.js.map
index.js.map playerview.js.map
haxe-split
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe Modular – How?
output.js
output.js.map
Acorn.js Output AST Graphlib.js
Dependency
graph
Sourcemap.js *.js.map
output.js *.js
typedef React = State -> View Haxe Meetup, 2 March 2017
typedef React = State -> View Haxe Meetup, 2 March 2017
HMR
Hot Module Replacement
aka Hot Reload, Live Reload,…
typedef React = State -> View Haxe Meetup, 2 March 2017
Hot Module Replacement – What?
• Server monitors local files
• Client has socket connection to server
• Server send changes to client
• Client reloads files in a smart way
typedef React = State -> View Haxe Meetup, 2 March 2017
Hot Module Replacement – What?
• Not rocket science
• Requires app code to be broken into reloadable chunks
typedef React = State -> View Haxe Meetup, 2 March 2017
Hot Module Replacement – How?
• Must have feature; makes or breaks JS bundlers and frameworks
• Reload code but also assets, like images and CSS.
• It’s not magic: the application needs special logic to handle changes
and refresh itself
typedef React = State -> View Haxe Meetup, 2 March 2017
Haxe + React + Hot reload

Weitere ähnliche Inhalte

Was ist angesagt?

Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Matthew Barlocker
 
Entities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in DrupalEntities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in DrupalAcquia
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails PresentationChanHan Hy
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React BasicsRich Ross
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Jukka Zitting
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansWindzoon Technologies
 
Live Coverage at The New York Times
Live Coverage at The New York TimesLive Coverage at The New York Times
Live Coverage at The New York TimesScott Taylor
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on RailsAmit Patel
 
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryBuilding modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryAndres Almiray
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applicationsEugene Lazutkin
 
API Design & Security in django
API Design & Security in djangoAPI Design & Security in django
API Design & Security in djangoTareque Hossain
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)daylerees
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettextNgoc Dao
 
2015 WordCamp Maine Keynote
2015 WordCamp Maine Keynote2015 WordCamp Maine Keynote
2015 WordCamp Maine KeynoteScott Taylor
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaGeorge Wilson
 

Was ist angesagt? (19)

Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1Your First Scala Web Application using Play 2.1
Your First Scala Web Application using Play 2.1
 
Entities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in DrupalEntities 101: Understanding Data Structures in Drupal
Entities 101: Understanding Data Structures in Drupal
 
Ruby On Rails Presentation
Ruby On Rails PresentationRuby On Rails Presentation
Ruby On Rails Presentation
 
Sanity on Rails
Sanity on RailsSanity on Rails
Sanity on Rails
 
20171108 PDN HOL React Basics
20171108 PDN HOL React Basics20171108 PDN HOL React Basics
20171108 PDN HOL React Basics
 
Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3Oak, the architecture of Apache Jackrabbit 3
Oak, the architecture of Apache Jackrabbit 3
 
Laravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web ArtisansLaravel - The PHP Framework for Web Artisans
Laravel - The PHP Framework for Web Artisans
 
Live Coverage at The New York Times
Live Coverage at The New York TimesLive Coverage at The New York Times
Live Coverage at The New York Times
 
Agile sites311training
Agile sites311trainingAgile sites311training
Agile sites311training
 
WebDev Crash Course
WebDev Crash CourseWebDev Crash Course
WebDev Crash Course
 
Introduction to Ruby on Rails
Introduction to Ruby on RailsIntroduction to Ruby on Rails
Introduction to Ruby on Rails
 
Building modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and LayrryBuilding modular applications with the Java Platform Module System and Layrry
Building modular applications with the Java Platform Module System and Layrry
 
Optimization of modern web applications
Optimization of modern web applicationsOptimization of modern web applications
Optimization of modern web applications
 
API Design & Security in django
API Design & Security in djangoAPI Design & Security in django
API Design & Security in django
 
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
 
I18nize Scala programs à la gettext
I18nize Scala programs à la gettextI18nize Scala programs à la gettext
I18nize Scala programs à la gettext
 
Javascript
JavascriptJavascript
Javascript
 
2015 WordCamp Maine Keynote
2015 WordCamp Maine Keynote2015 WordCamp Maine Keynote
2015 WordCamp Maine Keynote
 
Modern websites in 2020 and Joomla
Modern websites in 2020 and JoomlaModern websites in 2020 and Joomla
Modern websites in 2020 and Joomla
 

Andere mochten auch

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheLeslie Samuel
 
React Performance
React PerformanceReact Performance
React PerformanceMax Kudla
 
Recursos que intervienen en los diferentes procesos
Recursos que intervienen en los diferentes procesosRecursos que intervienen en los diferentes procesos
Recursos que intervienen en los diferentes procesosDubhe Hernández
 
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...verduguillo
 
Bentley Systems Colleagues Celebrate Engineers Week 2017
Bentley Systems Colleagues Celebrate Engineers Week 2017 Bentley Systems Colleagues Celebrate Engineers Week 2017
Bentley Systems Colleagues Celebrate Engineers Week 2017 Cantya Hermala Siswanto
 
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)Kobkrit Viriyayudhakorn
 
React Webinar With CodePolitan
React Webinar With CodePolitanReact Webinar With CodePolitan
React Webinar With CodePolitanRiza Fahmi
 
Script for gta cutscene
Script for gta cutsceneScript for gta cutscene
Script for gta cutsceneMrrrjones
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_jsMicroPyramid .
 
Tecnologiaweb
TecnologiawebTecnologiaweb
TecnologiawebNicollF
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2DreamLab
 
Sewing thread properties & their effects on seam
Sewing thread properties & their effects on seamSewing thread properties & their effects on seam
Sewing thread properties & their effects on seamMd Nazmul Huda Shuvo
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBoxKobkrit Viriyayudhakorn
 

Andere mochten auch (20)

How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 
React Performance
React PerformanceReact Performance
React Performance
 
La comunicación s01
La comunicación s01La comunicación s01
La comunicación s01
 
Prajwalana min
Prajwalana minPrajwalana min
Prajwalana min
 
Recursos que intervienen en los diferentes procesos
Recursos que intervienen en los diferentes procesosRecursos que intervienen en los diferentes procesos
Recursos que intervienen en los diferentes procesos
 
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...
ACTITUD DEL DOCENTE UNIVERSITARIO Y EL APRENDIZAJE SIGNIFICATIVO DEL ESTUDIAN...
 
Bentley Systems Colleagues Celebrate Engineers Week 2017
Bentley Systems Colleagues Celebrate Engineers Week 2017 Bentley Systems Colleagues Celebrate Engineers Week 2017
Bentley Systems Colleagues Celebrate Engineers Week 2017
 
Linkedin - Em Busca de Campeões
Linkedin - Em Busca de CampeõesLinkedin - Em Busca de Campeões
Linkedin - Em Busca de Campeões
 
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
สร้างซอฟต์แวร์อย่างไรให้โดนใจผู้คน (How to make software that people love)
 
React Webinar With CodePolitan
React Webinar With CodePolitanReact Webinar With CodePolitan
React Webinar With CodePolitan
 
Script for gta cutscene
Script for gta cutsceneScript for gta cutscene
Script for gta cutscene
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Introduction to react_js
Introduction to react_jsIntroduction to react_js
Introduction to react_js
 
Tecnologiaweb
TecnologiawebTecnologiaweb
Tecnologiaweb
 
Cave paintings
Cave paintingsCave paintings
Cave paintings
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
Lesiones personales
Lesiones personalesLesiones personales
Lesiones personales
 
React native - What, Why, How?
React native - What, Why, How?React native - What, Why, How?
React native - What, Why, How?
 
Sewing thread properties & their effects on seam
Sewing thread properties & their effects on seamSewing thread properties & their effects on seam
Sewing thread properties & their effects on seam
 
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
[React Native] Lecture 4: Basic Elements and UI Layout by using FlexBox
 

Ähnlich wie Haxe React architecture and workflow

Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with reduxMike Melusky
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworksKirk Madera
 
An Introduction to ReactNative
An Introduction to ReactNativeAn Introduction to ReactNative
An Introduction to ReactNativeMichał Taberski
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theoryjobinThomas54
 
An evening with React Native
An evening with React NativeAn evening with React Native
An evening with React NativeMike Melusky
 
Managing Open Source Software in the GitHub Era
Managing Open Source Software in the GitHub EraManaging Open Source Software in the GitHub Era
Managing Open Source Software in the GitHub EranexB Inc.
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementZach Lendon
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Zach Lendon
 
Top 5 react developer tools in 2021
 Top 5 react developer tools in 2021 Top 5 react developer tools in 2021
Top 5 react developer tools in 2021BOSC Tech Labs
 
Isomorphic JavaScript with Node, WebPack, and React
Isomorphic JavaScript with Node, WebPack, and ReactIsomorphic JavaScript with Node, WebPack, and React
Isomorphic JavaScript with Node, WebPack, and ReactTyler Peterson
 
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...DevDay.org
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails DevelopersArkency
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time rebootKentaro Goto
 
Py conkr 2020-automated newsletter service for your valuable community-chans...
Py conkr 2020-automated newsletter service  for your valuable community-chans...Py conkr 2020-automated newsletter service  for your valuable community-chans...
Py conkr 2020-automated newsletter service for your valuable community-chans...Park Chansung
 

Ähnlich wie Haxe React architecture and workflow (20)

slides.pptx
slides.pptxslides.pptx
slides.pptx
 
slides.pptx
slides.pptxslides.pptx
slides.pptx
 
React.js at Cortex
React.js at CortexReact.js at Cortex
React.js at Cortex
 
Welcome to React.pptx
Welcome to React.pptxWelcome to React.pptx
Welcome to React.pptx
 
Introduction to react native with redux
Introduction to react native with reduxIntroduction to react native with redux
Introduction to react native with redux
 
They why behind php frameworks
They why behind php frameworksThey why behind php frameworks
They why behind php frameworks
 
An Introduction to ReactNative
An Introduction to ReactNativeAn Introduction to ReactNative
An Introduction to ReactNative
 
Reactjs
ReactjsReactjs
Reactjs
 
Reactjs notes.pptx for web development- tutorial and theory
Reactjs  notes.pptx for web development- tutorial and theoryReactjs  notes.pptx for web development- tutorial and theory
Reactjs notes.pptx for web development- tutorial and theory
 
An evening with React Native
An evening with React NativeAn evening with React Native
An evening with React Native
 
Managing Open Source Software in the GitHub Era
Managing Open Source Software in the GitHub EraManaging Open Source Software in the GitHub Era
Managing Open Source Software in the GitHub Era
 
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer ReplacementMidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
MidwestJS 2014 Reconciling ReactJS as a View Layer Replacement
 
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
Reconciling ReactJS as a View Layer Replacement (MidwestJS 2014)
 
Top 5 react developer tools in 2021
 Top 5 react developer tools in 2021 Top 5 react developer tools in 2021
Top 5 react developer tools in 2021
 
Isomorphic JavaScript with Node, WebPack, and React
Isomorphic JavaScript with Node, WebPack, and ReactIsomorphic JavaScript with Node, WebPack, and React
Isomorphic JavaScript with Node, WebPack, and React
 
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...
[DevDay 2017] ReactJS Hands on - Speaker: Binh Phan - Developer at mgm techno...
 
React.js for Rails Developers
React.js for Rails DevelopersReact.js for Rails Developers
React.js for Rails Developers
 
Ruby in office time reboot
Ruby in office time rebootRuby in office time reboot
Ruby in office time reboot
 
Software citation
Software citationSoftware citation
Software citation
 
Py conkr 2020-automated newsletter service for your valuable community-chans...
Py conkr 2020-automated newsletter service  for your valuable community-chans...Py conkr 2020-automated newsletter service  for your valuable community-chans...
Py conkr 2020-automated newsletter service for your valuable community-chans...
 

Kürzlich hochgeladen

Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfrs7054576148
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VDineshKumar4165
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 

Kürzlich hochgeladen (20)

Intro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdfIntro To Electric Vehicles PDF Notes.pdf
Intro To Electric Vehicles PDF Notes.pdf
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

Haxe React architecture and workflow

  • 1. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe React architecture and workflow
  • 2. typedef React = State -> View Haxe Meetup, 2 March 2017 Definition • What Haxe is: • Haxe is an open source toolkit based on a modern high level strictly typed programming language, a state-of-the-art light-speed cross-compiler, a complete cross-platform standard library, and ways to access to each platform's native capabilities. • What Haxe is NOT: • Haxe is not a high level framework. It's a toolkit that can be used to build cross-platform tools and frameworks.
  • 3. typedef React = State -> View Haxe Meetup, 2 March 2017 Write or reuse? • Massive.co has contributed many state of the art open-source libraries for the Haxe language • Unit testing, code coverage, MVC, dependency injection, event signals,… • It is a big effort and responsibility to write and maintain OSS
  • 4. typedef React = State -> View Haxe Meetup, 2 March 2017 Crossplatform or not? • The Haxe language can target many platforms • JavaScript, Flash, C++, C#, Java, Python, Lua, Php… • We usually make sure to write dependency-free, universal, libraries • But ultimately our business is focusing on HTML/JS
  • 5. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe on JavaScript • JavaScript is our VM – one of the fastest, most stable, and richest • Other companies are building/maintaining very solid libraries
  • 6. typedef React = State -> View Haxe Meetup, 2 March 2017 Why Haxe on JavaScript? • JavaScript is predominantly ES6 and TypeScript nowadays • Yet people (and companies) continue betting on other langs • Dart, Elm, PureScript, ScalaJS, OcamlJS,… • And we love Haxe because it’s faster, smarter and easy to learn
  • 7. typedef React = State -> View Haxe Meetup, 2 March 2017 React on Haxe • Most popular view-layer library • No need for Facebook hatin’ • It’s opensource and well maintained • and many companies contribute to creating something much wider than its core
  • 8. typedef React = State -> View Haxe Meetup, 2 March 2017 React on Haxe • Building great Haxe support alone is a big effort • Core library by Massive.co (@dpeek then @elsassph) • https://github.com/massiveinteractive/haxe-react • React-native and other externs by @kevinresol and @zabojad • https://github.com/haxe-react • https://github.com/tokomlabs/haxe-react-addons
  • 9. typedef React = State -> View Haxe Meetup, 2 March 2017 First, understand JavaScript • Learn how things work in vanilla JavaScript first • Play with React using ‘create-react-app’
  • 10. typedef React = State -> View Haxe Meetup, 2 March 2017 First, understand JavaScript • Anything you can do in JavaScript can be expressed in Haxe (depending on how dirty you’re willing to feel) • For articles on Haxe-JS interop: http://philippe.elsass.me
  • 11. typedef React = State -> View Haxe Meetup, 2 March 2017 React
  • 12. typedef React = State -> View Haxe Meetup, 2 March 2017 React JavaScript syntax • XML in your JavaScript? (heresy!) • It’s called JSX • It’s only metadata
  • 13. typedef React = State -> View Haxe Meetup, 2 March 2017 React JavaScript syntax
  • 14. typedef React = State -> View Haxe Meetup, 2 March 2017 React JavaScript syntax • Fancy binding syntax (uni-directional)
  • 15. typedef React = State -> View Haxe Meetup, 2 March 2017 React: all the cool kids are doing it • React is a Virtual DOM engine from Facebook/Instagram • Only view layer, not an architecture (unlike Angular) • Straightforward and robust • Not limited to HTML DOM – there are renderers for canvas, PixiJS… • Not limited to the browser – react-native is maturing
  • 16. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe-React • Nearly as fancy, macro-powered, syntax
  • 17. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe-React • Supports the same binding syntax
  • 18. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe-React • Or Haxe string-interpolation syntax (advantage: completion)
  • 19. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe-React • Optimiser can generate inline objects at compile time in place of React.createElement() calls for optimal performance
  • 20. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe-React • JSX parser is complete with a few minor limitations • Generator supports all the advanced features* like spread operator, default values or functional stateless components • Optimiser does better than JS compilers * React is feature rich, learn it properly
  • 21. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: initial render • Initial render in HTML • Should be called only once, targeting a root DOM element • Multiple roots allowed
  • 22. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: initial render • Without components, the rendered DOM will never change
  • 23. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: initial render • Only components are able to trigger re-renders • A dynamic application will need at least one in the initial render
  • 24. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: Component • A component must have a render function returning one element.
  • 25. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: Component • Components can hold “state”; state changes schedule a re-render
  • 26. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: Component • Components can receive read-only “props” from their parent
  • 27. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: Component • A stateless component can be advantageously replaced by a function
  • 28. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: avoid inheritance • High-Order Component: extend other components
  • 29. typedef React = State -> View Haxe Meetup, 2 March 2017 React basics: avoid inheritance • Component wrapper with provided children elements
  • 30. typedef React = State -> View Haxe Meetup, 2 March 2017 Advanced React: containing updates • Warning: state changes can be costly! • State changes schedule a re-render • Children may re-render in depth, unless you prevent it: • Carefully add ”key” attributes • extend PureComponent • override shouldComponentUpdate(nextProps, nextState):Bool • Prevent re-render only if needed, and as early as possible
  • 31. typedef React = State -> View Haxe Meetup, 2 March 2017 React: production-ready • React works great, right now, it’s stable and well supported. Enjoy. • React’s approach is inspiring many other frameworks, some using JSX. • Haxe React is in serious shape and used in large productions at Massive.
  • 32. typedef React = State -> View Haxe Meetup, 2 March 2017 React architectures
  • 33. typedef React = State -> View Haxe Meetup, 2 March 2017 Architecture • React is just a view layer – it doesn’t enforce any architecture • Basic props and callbacks don’t scale • Haxe React comes with 2 examples: Redux and MMVC
  • 34. typedef React = State -> View Haxe Meetup, 2 March 2017 Architecture: Redux https://github.com/elsassph/haxe-react-redux • Disclaimer: Redux is NOT an architecture itself • Redux is a popular state library for Model-Intent architectures • Sample follows one possible architecture pattern with Redux • Warning: expect to do a lot of refactoring
  • 35. typedef React = State -> View Haxe Meetup, 2 March 2017 Architecture: MVC https://github.com/elsassph/haxe-react-mmvc • Massive’s MMVC offers a battle-tested architecture inspired by RobotLegs, used on large scale, large complexity applications • Macro-based Dependency Injection, Command and View mediation • MMVC fits naturally with React Components: just add an interface
  • 36. typedef React = State -> View Haxe Meetup, 2 March 2017 Advanced React : the “context” • Architecturing React apps requires more than “props” • Libraries and framework need to provide data to any child • This mechanism is the React “context” • Recommendation: do not use this “context” liberally
  • 37. typedef React = State -> View Haxe Meetup, 2 March 2017 Advanced React : the “context” • This mechanism should be used through black boxes: • “Provider” React components inject values in context • “Consumer” React components query those values • Examples of uses: • Redux: components need to access the store • MMVC: components mediation • React-router: components need to trigger navigation
  • 38. typedef React = State -> View Haxe Meetup, 2 March 2017 Code splitting To reduce the initial payload To load features on-demand
  • 39. typedef React = State -> View Haxe Meetup, 2 March 2017 Code splitting • Haxe compiler historically outputs a single, optimized, JS file • Traditional JavaScript do concat and minify JS files into one • Problem: single big JS bundle = bad user experience
  • 40. typedef React = State -> View Haxe Meetup, 2 March 2017 Code splitting • Modern JavaScript has embraced the multi-file approach and figured: • Bundling with code splitting • Hot module replacement during development • Can we benefit from that in Haxe?
  • 41. typedef React = State -> View Haxe Meetup, 2 March 2017 Modular JS https://github.com/*/modular-js Goal: comply with JavaScript bundlers
  • 42. typedef React = State -> View Haxe Meetup, 2 March 2017 Modular JS • Create one JS file for each Haxe class • Then use a JavaScript bundler as with regular JS (profit!) • Risks: • Experimental with multiple approaches/forks • Custom JavaScript generator • No sourcemaps • Requires excellent understanding of JS bundlers • Unclear code-splitting strategy (and no project examples)
  • 43. typedef React = State -> View Haxe Meetup, 2 March 2017 Modular JS - AMD • Asynchronous module system (RequireJS) • https://github.com/explorigin/modular-js (creator, unmaintained) • https://github.com/jcward/modular-js (used in production) • Bundlers: SystemJS, Webpack
  • 44. typedef React = State -> View Haxe Meetup, 2 March 2017 Modular JS - CommonJS • As popularized by nodejs, used by ES6/TypeScript • https://github.com/kevinresol/modular-js • https://github.com/MatthijsKamstra/modular-js (fork) • Bundlers: SystemJS, Webpack, Browserify
  • 45. typedef React = State -> View Haxe Meetup, 2 March 2017 Modular JS – Why choose it? • Modular-js is a sensible choice if you’re 100% going JS. • But it requires you to become an expert in Haxe JS output, the custom JS generator, JS in general, and your JS bundler of choice. • Competes with Haxe Modular
  • 46. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular https://github.com/elsassph/haxe-modular Goal: staying true to Haxe
  • 47. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – Goals https://github.com/elsassph/haxe-modular • Use (tweak) regular Haxe compiler output • No JS bundler dependency (but could) • Adaptable to other Haxe targets
  • 48. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – The promise https://github.com/elsassph/haxe-modular • Automatically split monolithic Haxe JS (and sourcemap!) output • Hot-reload capable (React reload built-in) • Bundle NPM dependencies together separately • Will be used in production at Massive • Risks: • Experimental
  • 49. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – Usage • Explicitly load a components on demand: • The class (and its dependencies) will be loaded (once) asynchronously when requested
  • 50. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – Usage • With React-router: • The view class (and its dependencies) will be loaded (once) when navigating to a specific “route”
  • 51. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – How? • Bundle.load(classRef) or RouteBundle.load(classRef) are macros • classRef is memorised and code replaced by Require.load(bundleId) • Normal Haxe JS output is sent to a temp file to be processed post-build
  • 52. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – How? PlayerView temp/output.js bin/index.js PlayerView temp/playerview.js output.js.map index.js.map playerview.js.map haxe-split
  • 53. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe Modular – How? output.js output.js.map Acorn.js Output AST Graphlib.js Dependency graph Sourcemap.js *.js.map output.js *.js
  • 54. typedef React = State -> View Haxe Meetup, 2 March 2017
  • 55. typedef React = State -> View Haxe Meetup, 2 March 2017 HMR Hot Module Replacement aka Hot Reload, Live Reload,…
  • 56. typedef React = State -> View Haxe Meetup, 2 March 2017 Hot Module Replacement – What? • Server monitors local files • Client has socket connection to server • Server send changes to client • Client reloads files in a smart way
  • 57. typedef React = State -> View Haxe Meetup, 2 March 2017 Hot Module Replacement – What? • Not rocket science • Requires app code to be broken into reloadable chunks
  • 58. typedef React = State -> View Haxe Meetup, 2 March 2017 Hot Module Replacement – How? • Must have feature; makes or breaks JS bundlers and frameworks • Reload code but also assets, like images and CSS. • It’s not magic: the application needs special logic to handle changes and refresh itself
  • 59. typedef React = State -> View Haxe Meetup, 2 March 2017 Haxe + React + Hot reload

Hinweis der Redaktion

  1. It’s difficult to maintain all we made opensource
  2. It’s difficult to maintain all we made opensource
  3. We don’t want to write everything ourselves again
  4. (we’ll get back to the packages later)
  5. Reinventing something like React or Vue is a fulltime job
  6. It’s good to try “vanilla” in case something weird happens
  7. This doesn’t create any components! It’s only metadata.
  8. It has a cost, every render call will create all these objects which will be compared with the existing DOM
  9. Braces can contain any Haxe expression
  10. Babel offers only a more optimized function. Netflix is experimenting with post-compilation optimizer with serious limitations.
  11. React is suitable for progressive conversion of regular JS apps to React: components/screens can be progressively converted
  12. This will be fully static DOM
  13. React-native has a similar approach but you basically have to provide a root component class reference
  14. Mutating this.state is not allowed. The state property can be strongly typed.
  15. Think XML attributes == JSX props Each time a parent renders, the child will re-render with the new props Props can be strongly typed.
  16. Props become an argument instead of being a class field
  17. Don’t use inheritance in React Components, use composition. This HOC could be stateful or a simple stateless function component.
  18. When providing children elements to a component, it will receive props.children
  19. React tries to prevent useless re-renders but you often have to be explicit PureComponent does a shallow comparison of the state and props
  20. Haxe React could be adapted to other libraries but it’s not in our short term plans yet. Admittedly we are only introducing Haxe JSX in production.
  21. Here’s the plan
  22. You can go framework-less but it will quickly become a mess
  23. Redux is extremely inspiring, even used in Angular projects
  24. Good React architectures need a better backbone than props
  25. It’s like a Service Provider pattern
  26. Practices have evolved in the JS world and Haxe compiler team is considering to support it.
  27. Custom generator is flexible but high-maintenance, ideally should be built-in the compiler
  28. Crazy. Futuristic approach to fully blend in the JS ecosystem
  29. Incompatible (I think) with Babel – the reference JS processor
  30. Compatible with Babel.
  31. Risk is still lower than modular-js: normal Haxe compiler with light patch
  32. Risk is still lower than modular-js: normal Haxe compiler with light patch
  33. Again: using this syntax will automatically split the output to extract this feature as an async
  34. React-router require a specific syntax for asynchronous routes – this API returns a function that can be called to load the module
  35. Require.load is a direct API to load a JS module asynchronously. You can load any JS file in the global context with it.
  36. Each JS look like a regular Haxe output with a little bit of wiring code to allow scopes to join.
  37. Analysis and generation run on node.js, leveraging very powerful JS libs. It can process over 2Mbs of JS output in 1.5s on my small ultrabook.
  38. Reloading some parts of your application code without refreshing your browser.
  39. It’s relatively easy to reload CSS or static images – just need a small client-side code to handle asset updates
  40. This has made Webpack the king of JS bundlers, even if others are catching up