Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
ReasonML Quick Start Guide
ReasonML Quick Start Guide

ReasonML Quick Start Guide: Build fast and type-safe React applications that leverage the JavaScript and OCaml ecosystems

Arrow left icon
Profile Icon Rafatpanah Profile Icon Joseph D'mello
Arrow right icon
$15.99 $22.99
eBook Feb 2019 180 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Rafatpanah Profile Icon Joseph D'mello
Arrow right icon
$15.99 $22.99
eBook Feb 2019 180 pages 1st Edition
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$15.99 $22.99
Paperback
$32.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
Table of content icon View table of contents Preview book icon Preview Book

ReasonML Quick Start Guide

Setting Up a Development Environment

In addition to being a new syntax for OCaml, Reason is a toolchain that makes it easy to get started. In this chapter, we'll do the following:

  • Learn about the Reason toolchain
  • Configure our editor
  • Use bsb to start a pure Reason project
  • Learn about bsconfig.json
  • Write an example pure Reason application that manipulates the DOM
  • Use bsb to start a ReasonReact project
  • Get comfortable using webpack within a Reason project

To follow along, clone this book's GitHub repository and start from this chapter's directory. You're also welcome to start from a blank project:

git clone https://github.com/PacktPublishing/ReasonML-Quick-Start-Guide.git
cd ReasonML-Quick-Start-Guide
cd Chapter02/pure-reason-start
npm install

This chapter is meant to get you comfortable with the Reason toolchain. We'll have separate development environments...

The Reason toolchain

At the time of writing, the Reason toolchain is essentially BuckleScript—Reason's partner project—and the familiar JavaScript toolchain, namely npm and webpack (or another JavaScript module bundler).

There's no longer a need for babel, since BuckleScript compiles to the ES5 version of JavaScript. The compiled output can be configured to use either the CommonJS, AMD, or ES module formats. Reason's powerful static-type system replaces the need for Flow and ESlint. Additionally, Reason's editor plugins all come with refmt, which is essentially prettier for Reason.

Installing BuckleScript

BuckleScript is a compiler that takes the OCaml AST and emits clean, readable, and performant...

Setting up a pure Reason project

The bsb binary includes a project generator. We'll use it to create a pure Reason project using the basic-reason theme. Run bsb -themes to see all available project templates:

Available themes: 
basic
basic-reason
generator
minimal
node
react
react-lite
tea

Since BuckleScript works with both OCaml and Reason, some themes are only for OCaml projects. That being said, feel free to mix OCaml's .ml files with Reason's .re files within any BuckleScript project.

In this chapter, we'll focus on using the basic-reason and react templates. If you're curious, the react-lite theme is like the react one, except webpack is replaced with a simpler, faster, and more reliable module bundler that is intended only for development purposes.

Let's first create a pure Reason project:

bsb -init my-first-app -theme basic-reason
cd my-first-app

When...

Setting up a ReasonReact project

To create a new ReasonReact project, run the following command:

bsb -init my-reason-react-app -theme react
cd my-reason-react-app

After opening our text editor, we see that a couple of things have changed. The package.json file lists the relevant React and webpack dependencies. Let's install them:

npm install

We also have the following webpack-related npm scripts:

"webpack": "webpack -w",
"webpack:production": "NODE_ENV=production webpack"

In bsconfig.json, we have a new field that turns on JSX for ReasonReact:

"reason": {
"react-jsx": 2
},

We have a simple webpack.config.js file:

const path = require("path");
const outputDir = path.join(__dirname, "build/");

const isProd = process.env.NODE_ENV === "production";

module.exports = {
entry: "./src/Index...

Summary

In this chapter, we saw just how easy it is to get started with Reason. In Chapter 3, Creating ReasonReact Components, we'll start to build a ReasonReact application that we'll use throughout this book. This application will help to provide context as we learn more about Reason semantics, BuckleScript interoperability, and ReasonReact specifics.

Don't worry if you don't yet understand everything within these generated projects. By the end of Chapter 3, Creating ReasonReact Components, you'll be a lot more comfortable. However, if you have questions along the way, please don't hesitate to reach out on Reason's Discord channel for real-time assistance: https://discord.gg/reasonml.

I hope you'll find the Reason community as welcoming and helpful as I have.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Hands on learning by building a real world app shell that includes client-side routing and more.
  • Understand Reason’s ecosystem including BuckleScript and various npm workflows.
  • Learn how Reason differs from TypeScript and Flow, and how to use it to make refactoring less stressful.

Description

ReasonML, also known as Reason, is a new syntax and toolchain for OCaml that was created by Facebook and is meant to be approachable for web developers. Although OCaml has several resources, most of them are from the perspective of systems development. This book, alternatively, explores Reason from the perspective of web development. You'll learn how to use Reason to build safer, simpler React applications and why you would want to do so. Reason supports immutability by default, which works quite well in the context of React. In learning Reason, you will also learn about its ecosystem – BuckleScript, JavaScript interoperability, and various npm workflows. We learn by building a real-world app shell, including a client-side router with page transitions, that we can customize for any Reason project. You'll learn how to leverage OCaml's excellent type system to enforce guarantees about business logic, as well as preventing runtime type errors.You'll also see how the type system can help offload concerns that we once had to keep in our heads. We'll explore using CSS-in-Reason, how to use external JSON in Reason, and how to unit-test critical business logic. By the end of the book, you'll understand why Reason is exploding in popularity and will have a solid foundation on which to continue your journey with Reason.

Who is this book for?

The target audience of this book is web developers who are somewhat familiar with ReactJS and who want to learn why ReasonML is the future of ReactJS.

What you will learn

  • Learn why Reason is exploding in popularity and why it s the future of React
  • Become familiar with Reason s syntax and semantics
  • Learn about Reason s ecosystem: BuckleScript and JavaScript interoperability
  • Learn how to build React applications with Reason
  • Learn how to use Reason s type system as a tool to provide amazing guarantees
  • Gain a solid foundation on which to continue your journey

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Feb 28, 2019
Length: 180 pages
Edition : 1st
Language : English
ISBN-13 : 9781789344233
Languages :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

Publication date : Feb 28, 2019
Length: 180 pages
Edition : 1st
Language : English
ISBN-13 : 9781789344233
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 104.97
Learn Type-Driven Development
$38.99
ReasonML Quick Start Guide
$32.99
Getting Started with Qt 5
$32.99
Total $ 104.97 Stars icon

Table of Contents

9 Chapters
Introduction to ReasonML Chevron down icon Chevron up icon
Setting Up a Development Environment Chevron down icon Chevron up icon
Creating ReasonReact Components Chevron down icon Chevron up icon
BuckleScript, Belt, and Interoperability Chevron down icon Chevron up icon
Effective ML Chevron down icon Chevron up icon
CSS-in-JS (in Reason) Chevron down icon Chevron up icon
JSON in Reason Chevron down icon Chevron up icon
Unit Testing in Reason Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.