showing All 496 lessons...
Use the FlexboxLayout component to create a layout container that is based on the CSS flexbox-layout in modern browsers. We will examine several of the properties, behaviors, and benefits that the FlexboxLayout provides with native mobile UI layouts in a NativeScript app.
In this lesson we'll see how Ramda's
pathOr functions can be used to safely access a deeply nested property from an object while avoiding the dreaded checks for
undefined at each new property in the desired path.
Using the map method of an array is a great way to create new data from an existing array in an immutable way and without writing any loops. The problem is that you need to call it on an existing array instance. In the lesson we'll see how to build our own reusable
map utility function using manual currying and then we'll replace it with Ramda's
Using the NativeScript-DrawingPad plugin in a NativeScript app you can create a drawing pad. This is great for capturing signatures or any touch drawing on the device.
We will use the NativeScript-Email plugin from Eddy Verbruggen to compose email messages from our app that the user can send out.
We will use the nativescript-phone plugin which provides a simple API to access the device's default phone and SMS applications. This allows us to dial phone numbers from our app using the device's phone capabilities as well as pre filling SMS messages for your app's users.
We will use the NativeScript Speech Recognition plugin by Eddy Verbruggen to convert speech to text. The plugin provides a clean abstraction over the Android SpeechRecognizer and the iOS SFSpeechRecognizer.
In this lesson, we'll use
Promise.all to get an array that contains the resolved values from multiple promises. Then we'll see how we can use Ramda to convert that array of values into a single object using
fromPairs. Then we'll refactor to use
In this lesson, we'll look at how we can use Ramda's
constructN functions to take methods of an object and turn them into reusable utility functions that are curried and accept their object as the last argument. We'll convert a dot-chained string of jQuery methods and create a composed function that can be applied to multiple elements.
Sorting an array of objects by multiple fields can be tricky. Even worse, the code can be tough to follow and making changes in the future is complicated by conditional logic in the sorting function. In this lesson we'll see how to simplify this using Ramda's
sortWith along with
descending. We'll sort an array of objects by multiple fields and the code will be readable and dead simple to change.
Promise chains can be a powerful way to handle a series of transformations to the results of an async call. In some cases, additional promises are required along the way. In cases where there are no new promises, function composition can reduce the number of dot chained
thens you need. In this lesson, we'll look at how to take a promise chain, and reduce it down with function composition.
Naming things is hard and arguments in generic utility functions are no exception. Making functions "tacit" or "point free" removes the need for the extra parameter names and can make your code cleaner and more succinct. In this lesson, we'll create a normal, "pointed" function and then use ramda's
useWith function to refactor our way to point-free bliss.
Functional composition is a great way to write declarative code that reads well. But sometimes, you need to get insight into what's happening at different steps in your composition. This is where
tap comes in. With tap, we can run code that generates side-effects, like logging to the console, and our data will continue to be passed along, untouched.
In this lesson, we'll grab arrays of values from other arrays, resulting in a nested array. From there, we'll look at multiple ways to flatten the array structure using composition with
unnest and then refactoring to use
flatMap. Finally, we'll add Ramda's
uniq function to remove duplicate values.
Take the first step in learning how to create native desktop applications with Electron. We'll set up a package.json, create an npm start script to launch our app in development, and create a browser window and load a local HTML file into it.
An important concept to understand about Electron is it's multi-process architecture. The main process creates web pages by creating
BrowserWindow instances, manages application lifecycle events, and more. Each
BrowserWindow instance runs the web page in its own renderer process.
Handling your logic with composable functions makes your code declarative, leading to code that's easy to read and easy to test. Breaking that up to wrap some risky function in a
try/catch block introduces imperative code and makes it harder to maintain that declarative approach. With Ramda's
tryCatch function, you can handle errors right in the middle of a composition and leave your code clean and functional. We'll also see how you can use
propOr to avoid common "cannot find X of undefined" errors.
We often want to check if an array includes a specific item. It's been common to do this with the
Array.prototype.indexOf method, but now we have a simpler way: We can use the
Array.prototype.includes method, which is available starting with ES2016.
Promises are rapidly overtaking callbacks in popularity. In this lesson, I show you how to rewrite a callback using ES6 Promises. After getting a handle on the basics, we'll convert an error-first style callback to use the Resolve and Reject handlers built into Promises. If you aren't familiar with Promises, this lesson can be a great starting point by learning how to duplicate the behavior of a callback with ES6 Promises.
In this lesson we'll take some existing code and refactor it using some functions from the Ramda library, most notably,
converge. When we're done, we'll have taken a function with a couple of local variables and parameter references and converted it into more streamlined "point-free" or "tacit" functions.
When doing comparisons inside of functions, you end of relying heavily on the argument passed into the function. Ramda's
converge allows you to do comparisons in a Point-Free style allowing you more flexibility with composing and constructing functions. This lesson walks through refactoring a function to Point-Free style using Ramda's Converge.
You can really unlock the power of ramda (and functional programming in general) when you combine functions. Counting words in a string may seem like a relatively difficult task, but ramda makes it easy by providing a
countBy function. This lesson walks through using the
countBy to count words in a string.
fromPairs functions, along with the crucial
One of the more powerful functions for creating streams in MostJS is the
In this lesson, we use
As a bonus, we see what it looks like to use
Function.prototype.bind for a quick and dirty way to partially apply arguments to a function.
We don't always control the data we need in our applications, and that means we often find ourselves massaging and transforming our data. In this lesson, we'll learn how to transform objects in a declarative way using ramda's evolve function.
Public Class Fields allow you to add instance properties to the class definition with the assignment operator (
=). In this lesson, we'll look at their use case for simplifying event callbacks and state initialization with a React component.
In this lesson we'll take an array of objects and map it to a new array where each object is a subset of the original. We'll look at multiple ways to accomplish this, refactoring our code into a simple and easy to read function using Ramda's
get "trap" that will allow us to get items starting from the end of the array with ease.
Most of the functions offered by the ramda library are curried by default. Functions you've created or that you've pulled in from another library may not be curried. Ramda's
curryN functions allow you to take a non-curried function and use it as a curried functions. In the case where you have a manually curried function and you want to just call it like a normal function, you can use
uncurryN to get back a function that accepts all of the arguments at once.
Most provides many means for creating streams, the simplest of which is the
of function. In this lesson, we demonstrate the use of
of to lift a single value into a stream. We also show off the
just alias of
of, as well as, a common method for currying a function.
Learn how to use Object.assign to combine multiple objects together. This pattern is helpful when writing libraries that have a set of default options where you want to allow a user to override specific options. You'll also learn how to use a third party library to recursively merge nested objects together.