Digital Library

Learning Patterns. (Lydia Hallie, Addy Osmani, Josh W. Comeau)(Z-Library)

,
,

Share E-Book

Learning Patterns. (Lydia Hallie, Addy Osmani, Josh W. Comeau)(Z-Library)

Author

,
,

Rating 3.5 AI initial rating

Log in to rate

JavaScript
Language English

In this book, you will learn design patterns, performance and rendering patterns for building high-quality web applications using modern JavaScript and React. Patterns are time-tested templates for writing code. They can be really powerful, whether you're a seasoned developer or beginner, bringing a valuable level of resilience and flexibility to your codebase. Whether it's better user-experience, developer-experience or just smarter architecture, the patterns in “Learning Patterns” can be a valuable consideration for any modern web application.

Format PDF
Size 18.0 MB
(First 20 pages)

Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Page 1
(This page has no text content)
Page 2
(This page has no text content)
Page 3
We enable developers to build amazing things Authors Lydia and Addy started work on "Learning Patterns" to bring a modern perspective to JavaScript design, rendering and performance patterns.
 Lydia Hallie Lydia Hallie is a full-time software engineering consultant and educator that primarily works with JavaScript, React, Node, GraphQL, and serverless technologies. She also spends her time mentoring and doing in-person training sessions. Addy Osmani Addy Osmani is an engineering manager working on Google Chrome. He leads up teams focused on making the web fast. Some of the team’s projects include Lighthouse, PageSpeed Insights, Aurora - working with React/Next.js/ Angular/Vue, contributions to Chrome DevTools and others.
Page 4
The humans behind patterns.dev 
 
 
 License
 
 The Patterns.dev book is shared under a Creative Commons Attribution- NonCommercial 4.0 International (CC BY-NC 4.0) license. You may remix, transform, and build upon the material. You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use. Lydia Hallie Addy Osmani Josh W. Comeau Co-creator & Writer Co-creator & Writer Whimsical UX Twitter · GitHub · LinkedIn Twitter · GitHub · LinkedIn Twitter · GitHub · LinkedIn Anton Karlovskiy Leena Sohoni-Kasture Nadia Snopek Software Engineer Writer & Editing Illustrator Twitter · GitHub · LinkedIn Instagram · Behance
Page 5
(This page has no text content)
Page 6
Design patterns are a fundamental part of software development, as they provide typical solutions to commonly recurring problems in software design. Rather than providing specific pieces of software, design patterns are merely concepts that can be used to handle recurring themes in an optimized way. Over the past couple of years, the web development ecosystem has changed rapidly. Whereas some well-known design patterns may simply not be as valuable as they used to be, others have evolved to solve modern problems with the latest technologies. Facebook's JavaScript library React has gained massive traction in the past 5 years, and is currently the most frequently downloaded framework on NPM compared to competing JavaScript libraries such as Angular, Vue, Ember and Svelte. Due to the popularity of React, design patterns have been modified, optimized, and new ones have been created in order to provide value in the current modern web development ecosystem. The latest version of React introduced a new feature called Hooks, which
Page 7
plays a very important role in your application design and can replace many traditional design patterns. Modern web development involves lots of different kinds of patterns. This project covers the implementation, benefits and pitfalls of common design patterns using ES2015+, React-specific design patterns and their possible modification and implementation using React Hooks, and many more patterns and optimizations that can help improve your modern web app!
Page 8
Overview of React.js A UI library for building reusable user interface components Over the years, there has been an increased demand for straight-forward ways to compose user-interfaces using JavaScript. React, also referred to as React.js, is an open-source JavaScript library designed by Facebook, used for building user interfaces or UI components. React is of course not the only UI library out there. Preact, Vue, Angular, Svelte, Lit and many others are also great for composing interfaces from reusable elements. Given React's popularity, it's worth walking through how it works given we will be using it to walk through some of the design, rendering and performance patterns in this guide. When front-end developers talk about code, it's most often in the context of designing interfaces for the web. And the way we think of interface composition is in elements, like buttons, lists, navigation, and the likes. React provides an optimized and simplified way of expressing interfaces in these elements. It also helps build complex and tricky interfaces by organizing your interface into three key concepts— components, props, and state. Because React is composition-focused, it can, perfectly map to the elements of your design system. So, in essence, designing for React actually rewards you for thinking in a modular way. It allows you to design individual components before putting together a page or view, so you fully understand each component's scope and purpose—a process referred to as componentization.
Page 9
Terminology we will use: • React / React.js / ReactJS - React library, created by Facebook in 2013 • ReactDOM - The package for DOM and server rendering • JSX - Syntax extension to JavaScript • Redux - Centralized state container • Hooks - A new way to use state and other React features without writing a class • React Native - The library to develop cross-platform native apps with Javascript • Webpack - JavaScript module bundler, popular in React community. • CRA (Create React App) - A CLI tool to create a scaffolding React app for bootstrapping a project. • Next.js - A React framework with many best-in-class features including SSR, Code-splitting, optimized for performance, etc.
Page 10
Rendering with JSX We will be using JSX in a number of our examples. JSX is an extension to JavaScript which embeds template HTML in JS using XML-like syntax. It is meant to be transformed into valid JavaScript, though the semantics of that transformation are implementation-specific. JSX rose to popularity with the React library, but has since seen other implementations as well. 
 Components, Props, and State Components, props, and state are the three key concepts in React. Virtually everything you're going to see or do in React can be classified into at least one of these key concepts, and here's a quick look at these key concepts:
Page 11
Components 
 Components are the building blocks of any React app. They are like JavaScript functions that accept arbitrary input (Props) and return React elements describing what should be displayed on the screen. The first thing to understand is that everything on screen in a React app is part of a component. Essentially, a React app is just components within components within components. So developers don't build pages in React; they build components. Components let you split your UI into independent, reusable pieces. If you're used to designing pages, thinking in this modular way might seem like a big change. But if you use a design system or style guide? Then this might not be as big of a paradigm shift as it seems.
Page 12
The most direct way to define a component is to write a JavaScript function. This function is a valid React component because it accepts a single prop (which stands for properties) object argument with data and returns a React element. Such components are called "function components" because they are literally JavaScript functions.
Page 13
Aside from function components, another type of component are "class components." A class component is different from a function component in that it is defined by an ES6 class, as shown below: Extracting components To illustrate the facts that components can be split into smaller components, consider the following Tweet component:
Page 14
Which can be implemented as follows: This component can be a bit difficult to manipulate because of how clustered it is, and reusing individual parts of it would also prove difficult. But, we can still extract a few components from it.
Page 15
The first thing we will do is extract Avatar: This component can be a bit difficult to manipulate because of how clustered it is, and reusing individual parts of it would also prove difficult. But, we can still extract a few components from it.
Page 16
The first thing we will do is extract Avatar: Avatar doesn't need to know that it is being rendered inside a Comment. This is why we have given its prop a more generic name: user rather than author.
Page 17

 Now we will simplify the comment a little: The next thing we will do is to a User component that renders an_ Avatar _next to the user's name:
Page 18
Extracting components seems like a tedious job, but having reusable components makes things easier when coding for larger apps. A good criterion to consider when simplifying components is this: if a part of your UI is used several times (Button, Panel, Avatar), or is complex enough on its own (App, FeedStory, Comment), it is a good candidate to be extracted to a separate component. 
 Props Props are a short form for properties, and they simply refer to the internal data of a component in React. They are written inside component calls and are passed into components. They also use the same syntax as HTML attributes, e.g._ prop="value". Two things that are worth remembering about props; Firstly, we determine the value of a prop and use it as part of the blueprint before the component is built. Secondly, the value of a prop will never change, i.e. props are read-only once they are passed into components. The way you access a prop is by referencing it via the "this.props" property that every component has access to. State State is an object that holds some information that may change over the lifetime of the component. Meaning it is just the current snapshot of data stored in a component's Props. The data can change over time, so techniques to manage the way that data changes become necessary to ensure the component looks the way engineers want it to, at just the right time — this is called State management.
Page 19
It's almost impossible to read one paragraph about React without coming across the idea of state-management. Developers love expounding upon this topic, but at its core, state management isn't really as complex as it sounds. In React, state can also be tracked globally, and data can be shared between components as needed. Essentially, this means that in React apps, loading data in new places is not as expensive as it is with other technologies. React apps are smarter about which data they save and load, and when. This opens up opportunities to make interfaces that use data in new ways. Think of React components like micro-applications with their own data, logic, and presentation. Each component should have a single purpose. As an engineer, you get to decide that purpose and have complete control over how each component behaves and what data is used. You're no longer limited by the data on the rest of the page. In your design, you can take advantage of
Page 20
this in all kinds of ways. There are opportunities to present additional data that can improve the user experience or make areas within the design more contextual. How to add State in React When designing, Including state is a task that you should save for last. It is much better to design everything as stateless as possible, using props and events. This makes components easier to maintain, test, and understand. Adding states should be done through either state containers such as Redux and MobX, or a container/wrapper component. Redux is a popular state management system for other reactive frameworks. It implements a centralized state machine driven by actions.
The above is a preview of the first 20 pages. Register to read the complete e-book.

Recommended for You

Loading recommended books...
Failed to load, please try again later

Tip the Site

Scan the WeChat Pay or Alipay code to tip. No login required.

WeChat Pay
Alipay
← Back to List