SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
React meets OCaml
@MichalZalecki
Agenda
• What’s the Reason?
• How it becomes a JavaScript?
• Type system and other cool features
• ReasonReact vs TypeScript + React
• Interop with JavaScript
ASON
Why Reason is worth giving a try?
• Rock solid type system
• Access to OCaml ecosystem and standard library
• Possibility to compile to barebone assembly
ReasonReact
TypeScript – Stateless component
export const Expense = (props: ExpenseProps) => {
const { expense } = props;
return (
<li>
{expense.subject} | {expense.amount.toFixed(2)}
</li>
);
};
Setup
TypeScript
npm install -g create-react-app
create-react-app expenses-typescript --scripts-version=react-scripts-ts
cd expenses-typescript && npm start
ReasonReact
npm install -g bs-platform
bsb -init expenses-reason -theme react
cd expenses-reason && npm install && npm start
npm run webpack
Reason – Stateless component
let component = ReasonReact.statelessComponent("Expense");
let make = (~expense, _children) => {
...component,
render: (_self) =>
<li>
{ReasonReact.stringToElement(
Printf.sprintf("%s | %.2f", expense.subject, expense.amount)
)}
</li>
};
TypeScript – Types
export interface ExpenseType {
id: string
subject: string
amount: number
}
interface ExpenseProps {
expense: ExpenseType
}
Reason – Types
type expense = {
id: string,
subject: string,
amount: float
};
TypeScript – Stateful component
export class ExpensesList extends React.Component<{}, ExpensesListState> {
state: ExpensesListState = {
amount: "0",
expenses: []
};
submit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
this.setState(state => {
const amount = parseFloat(state.amount);
if (!Number.isNaN(amount)) {
return { /* ... */ };
}
return null;
});
}
}
Reason – Reducer component
type action =
| ChangeAmount(string)
| Submit;
let component = ReasonReact.reducerComponent("ExpensesList");
let make = (_children) => {
...component,
initialState: () => {expenses: [], amount: "0"},
reducer: (action, state) =>
switch action {
| ChangeAmount(amount) => ReasonReact.Update({...state, amount})
| Submit =>
switch (float_of_string(state.amount)) {
| amount =>
ReasonReact.UpdateWithSideEffects(/* ... */, (_self) => { /* ... */ })
| exception (Failure(_msg)) => ReasonReact.NoUpdate
}
Interop - libraries
[@bs.module] external uuidv4 : unit => string = "uuid/v4";
[@bs.module "uuid"] external uuidv4 : unit => string = "";
Interop – #usetheplatform/raw JavaScript
Js.log("this is reason");
[%%bs.raw {|
console.log('here is some javascript for you');
|}];
Thank you!
Questions time

Más contenido relacionado

La actualidad más candente

How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
Laura Lorenz
 

La actualidad más candente (20)

Building an analytics workflow using Apache Airflow
Building an analytics workflow using Apache AirflowBuilding an analytics workflow using Apache Airflow
Building an analytics workflow using Apache Airflow
 
Airflow - a data flow engine
Airflow - a data flow engineAirflow - a data flow engine
Airflow - a data flow engine
 
Apache airflow
Apache airflowApache airflow
Apache airflow
 
Apache Airflow overview
Apache Airflow overviewApache Airflow overview
Apache Airflow overview
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoop
 
Airflow at WePay
Airflow at WePayAirflow at WePay
Airflow at WePay
 
面向引擎——编写高效率JS
面向引擎——编写高效率JS面向引擎——编写高效率JS
面向引擎——编写高效率JS
 
Go With The Flow
Go With The FlowGo With The Flow
Go With The Flow
 
From airflow to google cloud composer
From airflow to google cloud composerFrom airflow to google cloud composer
From airflow to google cloud composer
 
Airflow 101
Airflow 101Airflow 101
Airflow 101
 
Gearman & PHP
Gearman & PHPGearman & PHP
Gearman & PHP
 
Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular Top 10 RxJs Operators in Angular
Top 10 RxJs Operators in Angular
 
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at XamarinC# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
C# Async on iOS and Android - Craig Dunn, Developer Evangelist at Xamarin
 
Reactive
ReactiveReactive
Reactive
 
So you want to write a cloud function
So you want to write a cloud functionSo you want to write a cloud function
So you want to write a cloud function
 
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overviewFlink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
Flink Forward SF 2017: Kenneth Knowles - Back to Sessions overview
 
How I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with AirflowHow I learned to time travel, or, data pipelining and scheduling with Airflow
How I learned to time travel, or, data pipelining and scheduling with Airflow
 
Getting to Know Airflow
Getting to Know AirflowGetting to Know Airflow
Getting to Know Airflow
 
Enhancements in Java 9 Streams
Enhancements in Java 9 StreamsEnhancements in Java 9 Streams
Enhancements in Java 9 Streams
 
(CMP310) Data Processing Pipelines Using Containers & Spot Instances
(CMP310) Data Processing Pipelines Using Containers & Spot Instances(CMP310) Data Processing Pipelines Using Containers & Spot Instances
(CMP310) Data Processing Pipelines Using Containers & Spot Instances
 

Similar a React meets o OCalm

End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
vfabro
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
Zachary Klein
 
El camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - IntroductionEl camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - Introduction
Plain Concepts
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
Raimonds Simanovskis
 

Similar a React meets o OCalm (20)

End to-end async and await
End to-end async and awaitEnd to-end async and await
End to-end async and await
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 
Full Stack Scala
Full Stack ScalaFull Stack Scala
Full Stack Scala
 
Advanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutesAdvanced technic for OS upgrading in 3 minutes
Advanced technic for OS upgrading in 3 minutes
 
Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)
Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)
Developing SharePoint Framework Solutions for the Enterprise (SPC 2019)
 
[Intuit] Control Everything
[Intuit] Control Everything[Intuit] Control Everything
[Intuit] Control Everything
 
Why scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with thisWhy scala is not my ideal language and what I can do with this
Why scala is not my ideal language and what I can do with this
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
SharePoint Framework at a glance
SharePoint Framework at a glanceSharePoint Framework at a glance
SharePoint Framework at a glance
 
Using React with Grails 3
Using React with Grails 3Using React with Grails 3
Using React with Grails 3
 
PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)PVS-Studio for Linux (CoreHard presentation)
PVS-Studio for Linux (CoreHard presentation)
 
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
 
How to lock a Python in a cage? Managing Python environment inside an R project
How to lock a Python in a cage?  Managing Python environment inside an R projectHow to lock a Python in a cage?  Managing Python environment inside an R project
How to lock a Python in a cage? Managing Python environment inside an R project
 
El camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - IntroductionEl camino a las Cloud Native Apps - Introduction
El camino a las Cloud Native Apps - Introduction
 
Let's play with adf 3.0
Let's play with adf 3.0Let's play with adf 3.0
Let's play with adf 3.0
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Fast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on OracleFast Web Applications Development with Ruby on Rails on Oracle
Fast Web Applications Development with Ruby on Rails on Oracle
 
(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us(2018) Webpack Encore - Asset Management for the rest of us
(2018) Webpack Encore - Asset Management for the rest of us
 
Angular 2 for Java Developers
Angular 2 for Java DevelopersAngular 2 for Java Developers
Angular 2 for Java Developers
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
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)
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

React meets o OCalm

  • 2. Agenda • What’s the Reason? • How it becomes a JavaScript? • Type system and other cool features • ReasonReact vs TypeScript + React • Interop with JavaScript
  • 4.
  • 5. Why Reason is worth giving a try? • Rock solid type system • Access to OCaml ecosystem and standard library • Possibility to compile to barebone assembly
  • 6.
  • 7.
  • 9.
  • 10. TypeScript – Stateless component export const Expense = (props: ExpenseProps) => { const { expense } = props; return ( <li> {expense.subject} | {expense.amount.toFixed(2)} </li> ); };
  • 11. Setup TypeScript npm install -g create-react-app create-react-app expenses-typescript --scripts-version=react-scripts-ts cd expenses-typescript && npm start ReasonReact npm install -g bs-platform bsb -init expenses-reason -theme react cd expenses-reason && npm install && npm start npm run webpack
  • 12. Reason – Stateless component let component = ReasonReact.statelessComponent("Expense"); let make = (~expense, _children) => { ...component, render: (_self) => <li> {ReasonReact.stringToElement( Printf.sprintf("%s | %.2f", expense.subject, expense.amount) )} </li> };
  • 13. TypeScript – Types export interface ExpenseType { id: string subject: string amount: number } interface ExpenseProps { expense: ExpenseType }
  • 14. Reason – Types type expense = { id: string, subject: string, amount: float };
  • 15. TypeScript – Stateful component export class ExpensesList extends React.Component<{}, ExpensesListState> { state: ExpensesListState = { amount: "0", expenses: [] }; submit = (e: React.FormEvent<HTMLFormElement>) => { e.preventDefault(); this.setState(state => { const amount = parseFloat(state.amount); if (!Number.isNaN(amount)) { return { /* ... */ }; } return null; }); } }
  • 16. Reason – Reducer component type action = | ChangeAmount(string) | Submit; let component = ReasonReact.reducerComponent("ExpensesList"); let make = (_children) => { ...component, initialState: () => {expenses: [], amount: "0"}, reducer: (action, state) => switch action { | ChangeAmount(amount) => ReasonReact.Update({...state, amount}) | Submit => switch (float_of_string(state.amount)) { | amount => ReasonReact.UpdateWithSideEffects(/* ... */, (_self) => { /* ... */ }) | exception (Failure(_msg)) => ReasonReact.NoUpdate }
  • 17.
  • 18. Interop - libraries [@bs.module] external uuidv4 : unit => string = "uuid/v4"; [@bs.module "uuid"] external uuidv4 : unit => string = "";
  • 19. Interop – #usetheplatform/raw JavaScript Js.log("this is reason"); [%%bs.raw {| console.log('here is some javascript for you'); |}];