Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
872 views

Reactive Patterns with RxJS for Angular A practical guide to managing your Angular application s data reactively and efficiently using RxJS 7 Lamis Chebbi - The full ebook with all chapters is available for download now

The document promotes a collection of ebooks focused on Angular and reactive programming, including titles like 'Reactive Patterns with RxJS for Angular' and 'Reactive Programming with Angular and ngrx.' It emphasizes the benefits of using RxJS for managing data reactively in Angular applications and provides links for instant downloads. The content is aimed at Angular developers with a beginner-level understanding of related technologies.

Uploaded by

myrnesyeful
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
872 views

Reactive Patterns with RxJS for Angular A practical guide to managing your Angular application s data reactively and efficiently using RxJS 7 Lamis Chebbi - The full ebook with all chapters is available for download now

The document promotes a collection of ebooks focused on Angular and reactive programming, including titles like 'Reactive Patterns with RxJS for Angular' and 'Reactive Programming with Angular and ngrx.' It emphasizes the benefits of using RxJS for managing data reactively in Angular applications and provides links for instant downloads. The content is aimed at Angular developers with a beginner-level understanding of related technologies.

Uploaded by

myrnesyeful
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

Explore the full ebook collection and download it now at textbookfull.

com

Reactive Patterns with RxJS for Angular A


practical guide to managing your Angular
application s data reactively and efficiently
using RxJS 7 Lamis Chebbi
https://textbookfull.com/product/reactive-patterns-with-
rxjs-for-angular-a-practical-guide-to-managing-your-angular-
application-s-data-reactively-and-efficiently-using-
rxjs-7-lamis-chebbi/

OR CLICK HERE

DOWLOAD EBOOK

Browse and Get More Ebook Downloads Instantly at https://textbookfull.com


Click here to visit textbookfull.com and download textbook now
Your digital treasures (PDF, ePub, MOBI) await
Download instantly and pick your perfect format...

Read anywhere, anytime, on any device!

Reactive Programming with Angular and ngrx: Learn to


Harness the Power of Reactive Programming with RxJS and
ngrx Extensions 1st Edition Oren Farhi (Auth.)
https://textbookfull.com/product/reactive-programming-with-angular-
and-ngrx-learn-to-harness-the-power-of-reactive-programming-with-rxjs-
and-ngrx-extensions-1st-edition-oren-farhi-auth/
textbookfull.com

Reactive Programming with RxJS 5 Untangle your


asynchronous Javascript code 1st Edition Sergi Mansilla

https://textbookfull.com/product/reactive-programming-with-
rxjs-5-untangle-your-asynchronous-javascript-code-1st-edition-sergi-
mansilla/
textbookfull.com

Essential Angular for ASP.NET Core MVC 3: A Practical


Guide to Successfully Using Both in Your Projects 2nd
Edition Adam Freeman
https://textbookfull.com/product/essential-angular-for-asp-net-core-
mvc-3-a-practical-guide-to-successfully-using-both-in-your-
projects-2nd-edition-adam-freeman/
textbookfull.com

Learn With Angular 4 Collected Essays Angular CLI Unit


Testing Debugging TypeScript and Angular Build Processes
2nd Edition Jeffry Houser
https://textbookfull.com/product/learn-with-angular-4-collected-
essays-angular-cli-unit-testing-debugging-typescript-and-angular-
build-processes-2nd-edition-jeffry-houser/
textbookfull.com
ng-book The Complete Guide to Angular Nate Murray

https://textbookfull.com/product/ng-book-the-complete-guide-to-
angular-nate-murray/

textbookfull.com

Angular Up and Running Learning Angular Step by Step Shyam


Seshadri

https://textbookfull.com/product/angular-up-and-running-learning-
angular-step-by-step-shyam-seshadri/

textbookfull.com

ng-book: The Complete Guide to Angular 5 Nathan Murray

https://textbookfull.com/product/ng-book-the-complete-guide-to-
angular-5-nathan-murray/

textbookfull.com

Ng Book The Complete Guide to Angular 9 Nathan Murray

https://textbookfull.com/product/ng-book-the-complete-guide-to-
angular-9-nathan-murray/

textbookfull.com

Ng Book The Complete Guide to Angular 11 Felipe Coury

https://textbookfull.com/product/ng-book-the-complete-guide-to-
angular-11-felipe-coury/

textbookfull.com
Reactive Patterns
with RxJS
for Angular

A practical guide to managing your Angular


application's data reactively and efficiently
using RxJS 7

Lamis Chebbi

BIRMINGHAM—MUMBAI
Reactive Patterns with RxJS for Angular
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the
information presented. However, the information contained in this book is sold without warranty,
either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors,
will be held liable for any damages caused or alleged to have been caused directly or indirectly by
this book.
Packt Publishing has endeavored to provide trademark information about all of the companies
and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.
Associate Group Product Manager: Pavan Ramchandani
Publishing Product Manager: Ashitosh Gupta
Senior Editor: Mark Dsouza
Content Development Editor: Divya Vijayan
Technical Editor: Shubham Sharma
Copy Editor: Safis Editing
Project Coordinator: Ajesh Devavaram
Proofreader: Safis Editing
Indexer: Rekha Nair
Production Designer: Alishon Mendonca
Marketing Coordinator: Elizabeth Varghese

First published: April 2022

Production reference: 2210422

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-80181-151-4

www.packt.com
To my father, who taught me diligence, perseverance, and work ethic. Thank
you for always being there to support me and lift me up.
To my mother, who taught me selflessness and doing things with love.
Thank you for your enduring encouragement during the writing of this
book.

To my brother and my sisters, for their continuous support.


-Lamis Chebbi
Contributors
About the author
Lamis Chebbi is a Google Developer Expert for Angular and an Auth0 ambassador.
She is an enthusiastic software engineer with a strong passion for the modern web. She's
the founder of Angular Tunisia, a member of the WWCode community, a speaker, a
content creator, and a trainer. She has been into Angular for the past few years and loves
to share her knowledge about Angular through participating in workshops and organizing
training sessions. ng-girls is one of the communities she supports. Empowering women
and students is one of her highest priorities. Besides Angular and the web, Lamis loves
music, traveling, chromotherapy, and volunteering. Last but not least, she's a forever
student.
I want to thank all the people that believed in me and supported me.
I am thankful for the people who helped me in the journey.
I am thankful for the people who inspired me in the journey.
About the reviewer
Dave Muellerchen is a freelancer. He loves sharing his self-taught knowledge of JavaScript
at meetups and conferences.
His passion for communities shows in his commitment to them. He is the organizer of
the Angular Hamburg Meetup and Tech Meetup Hamburg. He is also a team member
at the Angular conference in Germany (ng-de) and a Google Developer Expert for web
technologies. He streams developer content on Twitch.
Thanks to my wife, who has my back to do what I do. Thank you my sons, for the fun and the
distraction. And of course, thank you Lamis for your trust.
Anu Nagan G has worked in various corporate organizations starting from SaaS startup
[GenDeep], midsize [GAVS], Fortune 500 companies [DXC] playing various roles there
such as Technical Product Manager, Full Stack Product Lead [Angular, Java, Python,
AWS], Delivery Lead respectively in his 8 years of tenure. Currently, he is with Bounteous,
leading parallel projects such as Clinical mobile app development, Fintech marketing data
migration. Contributed to various AIOps products ZIF, Gcare in the past. He is an avid
reader, cinephile, who loves to play Guitar, makes short films with his friends.
I would like to dedicate this to my grandparents who are celebrating their 82nd anniversary,
to my wife and we are expecting. Happy birthday Hema.
Table of Contents

Preface

Part 1 – Introduction
1
The Power of the Reactive Paradigm
Technical requirements 4 The HTTP client module 7
Exploring the pillars of reactive The router module 8
programming  4 Reactive forms 13
Data streams 4 The event emitter  14
Observer patterns 5 The async pipe 15

Using RxJS in Angular and its Learning about the marble


advantages7 diagram – our secret weapon 15
Summary18

2
RxJS 7 – The Major Features
Technical requirements 20 The firstValueFrom() method 25
Exploring the bundle size The lastValueFrom() method 26
improvements  20 Empty errors 26

Reviewing the TypeScript typing Highlighting API consistency


improvements22 improvements27
Understanding the toPromise() Summary29
deprecation23
viii Table of Contents

3
A Walkthrough of the Application
Technical requirements 32 View five – the modify recipe interface 36
Our app's user stories 32 View six – the recipe details interface 37

View one – the landing page  32 Our app's architecture 38


View two – the new recipe interface 34
The components overview 38
View three – the My Recipes interface 35
View four – the My Favourites interface 36
Summary39

Part 2 – A Trip into Reactive Patterns


4
Fetching Data as Streams
Technical requirements 44 Exploring the reactive pattern
Defining the requirement  45 for fetching data 52
Exploring the classic pattern for Retrieving data as streams 53
fetching data 45 Defining the stream in your component 53
Using the async pipe in your template 54
Defining the structure of your data 45
Creating an Angular service 46 Highlighting the advantages of
Retrieving the data through a method 47 the reactive pattern 55
Injecting and subscribing to the service Using the declarative approach 55
in your component 47
Using the change detection strategy of
Displaying the data in the template 48 OnPush 56
Managing unsubscriptions 49 Wrapping up 58

Summary59

5
Error Handling
Technical requirements 62 Exploring error handling
Understanding the anatomy of patterns and strategies 63
an Observable 62 Handling error operators 64
Table of Contents ix

The catchError operator  64 Error handling in action  75


The delayWhen operator 72 Summary77

6
Combining Streams
Technical requirements 80 Exploring the declarative
Defining the requirement 80 pattern for filtering data 85
Exploring the imperative The combineLatest operator 86
pattern for filtering data 81 The declarative pattern pillars 87
Emitting a value when an action occurs 90
A look at the filter component 81
A look at the recipes list component 82 Summary94

7
Transforming Streams
Technical requirements 96 Learning about other useful
Defining the requirement 96 higher-order mapping
operators107
Exploring the imperative
pattern for autosave 97 The mergeMap operator  107
The switchMap operator  108
Exploring the reactive pattern
The exhaustMap operator  109
for autosave 100
Higher-order observables 101 Summary110
Higher-order mapping operators 101
The concatMap operator 102

Part 3 – Multicasting Takes You to


New Places
8
Multicasting Essentials
Technical requirements 114 Producer  114
Explaining Multicasting A cold observable  114
versus Unicasting 114 A hot observable  116
x Table of Contents

Exploring Subjects 118 Highlighting Multicasting


A plain Subject 119 operators123
ReplaySubject120 Summary123
BehaviorSubject  121

9
Caching Streams
Technical requirements 126 Exploring the RxJS 7
Defining the requirement 126 recommended pattern to
cache streams 133
Learning about using
the reactive pattern to Highlighting the use cases of
cache streams 127 caching streams 134
Summary135

10
Sharing Data between Components
Technical requirements 138 Step two – updating the last-selected
recipe140
Defining the requirement 138
Step three – consuming the
Exploring the reactive pattern last-selected recipe 142
to share data 139
Step one – creating a shared service 139 Highlighting other ways for
sharing data 144
Summary145

11
Bulk Operations
Technical requirements 147 The pattern in action 151
Defining the requirement 148 Learning about the reactive
Learning about the reactive pattern for tracking progress 156
pattern for bulk operations 149 Summary157
The forkJoin operator 150
Table of Contents xi

12
Processing Real-Time Updates
Technical requirements 160 Connection management 164
Defining the requirement 160 Putting the pattern into action 166

Learning the reactive pattern Learning the reactive pattern


for consuming real-time for handling reconnection 170
messages 161 Retrying the reconnection 172
The WebSocketSubject behavior 161
Summary173

Part 4 – Final Touch


13
Testing RxJS Observables
Technical requirements 178 Understanding the syntax 182
Learning about the subscribe Implementing marble tests 184
and assert pattern 178 Highlighting testing streams
Learning about the marble using HttpClientTestingModule 190
testing pattern 182 Summary192

Index
Other Books You May Enjoy
Preface
Switching to a reactive mindset is one of the biggest challenges when you start learning
Reactive programming using RxJS. I believe that the reactive mindset is gradually
achieved by learning reactive patterns and comparing the reactive way with the imperative
one to distinguish the difference and the benefits.
That's why I wrote this book, which gathers a set of reactive patterns applied in an
Angular application. Learning reactive patterns helps with managing your application's
data efficiently, writing clean and maintainable code, reacting to user changes faster, and
consequently, enhancing the user experience.
So, all that you have to do is get started!

Who this book is for


The book is for Angular developers who want to use RxJS to build reactive web
applications. This book assumes beginner-level knowledge of and experience with
Angular, RxJS, TypeScript, and functional programming concepts.

What this book covers


Chapter 1, The Power of the Reactive Paradigm, explains the fundamentals of Reactive
programming.
Chapter 2, RxJS 7 – The Major Features, focuses on the main improvements of RxJS 7.
Chapter 3, A Walkthrough of the Application, highlights the architecture and requirements
of the application that we will be building gradually.
Chapter 4, Fetching Data as Streams, explains the first reactive pattern for fetching data.
Chapter 5, Error Handling, details the error handling strategies and the reactive patterns
for handling errors.
Chapter 6, Combining Streams, explains the reactive pattern for combining streams.
Chapter 7, Transforming Streams, explains the reactive pattern for transforming streams.
xiv Preface

Chapter 8, Multicasting Essentials, focuses on the multicasting approach essentials.


Chapter 9, Caching Streams, explains the reactive pattern for caching streams.
Chapter 10, Sharing Data between Components, explains the reactive patterns for sharing
data between components.
Chapter 11, Bulk Operations, explores the reactive pattern for performing bulk actions.
Chapter 12, Processing Real-Time Updates, explores the reactive pattern for consuming
real-time updates.
Chapter 13, Testing RxJS Observables, explains the different strategies for testing reactive
patterns.

To get the most out of this book


All code examples have been tested using Angular 12 on a Windows operating system.
However, it should work with future releases too.

Please make sure you follow the prerequisites at https://angular.io/guide/


setup-local. The prerequisites include the environment setup and the technologies
needed in order to install and use Angular.
We also used the Bootstrap library to manage the application responsiveness. We used
primeng as a library of rich components and RxJS 7 as the reactive library, of course.
If you are using the digital version of this book, we advise you to type the code yourself or
access the code from the book's GitHub repository (a link is available in the next section).
Doing so will help you avoid any potential errors related to the copying and pasting of
code.
Preface xv

Download the example code files


You can download the example code files for this book from GitHub at https://
github.com/PacktPublishing/Reactive-Patterns-with-RxJS-for-
Angular. If there's an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at
https://github.com/PacktPublishing/. Check them out!

Download the color images


We also provide a PDF file that has color images of the screenshots and diagrams used
in this book. You can download it here: https://static.packt-cdn.com/
downloads/9781801811514_ColorImages.pdf.

Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names,
filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles.
Here is an example: "In the try block, you place your risky statements, and inside catch,
you handle the possible exceptions."
A block of code is set as follows:

behaviourSubject$.subscribe({
next: (message) => console.log(message),
error: (error) => console.log(error),
complete: () => console.log('Stream Completed'),
});

When we wish to draw your attention to a particular part of a code block, the relevant
lines or items are set in bold:

behaviourSubject$.subscribe({
next: (message) => console.log(message),
error: (error) => console.log(error),
complete: () => console.log('Stream Completed'),
});
xvi Preface

Any command-line input or output is written as follows:

$ mkdir css
$ cd css

Bold: Indicates a new term, an important word, or words that you see onscreen. For
instance, words in menus or dialog boxes appear in bold. Here is an example: "Select
System info from the Administration panel."

Tips or Important Notes


Appear like this.

Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at
customercare@packtpub.com and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you have found a mistake in this book, we would be grateful if you would
report this to us. Please visit www.packtpub.com/support/errata and fill in the
form.
Piracy: If you come across any illegal copies of our works in any form on the internet,
we would be grateful if you would provide us with the location address or website name.
Please contact us at copyright@packt.com with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in
and you are interested in either writing or contributing to a book, please visit authors.
packtpub.com.
Preface xvii

Share Your Thoughts


Once you've read Reactive Patterns with RxJS for Angular, we'd love to hear your thoughts!
Please click here to go straight to the Amazon review page for this
book and share your feedback.
Your review is important to us and the tech community and will help us make sure we're
delivering excellent quality content.
Part 1 –
Introduction

In this section, you will understand the importance of using the reactive paradigm in
an Angular application, as well as the new features of RxJS 7. In the third chapter, we
will introduce the application that we are going to progressively build as we go through
the book.
This part comprises the following chapters:

• Chapter 1, The Power of the Reactive Paradigm


• Chapter 2, RxJS 7 – The Major Features
• Chapter 3, A Walkthrough of the Application
1
The Power of the
Reactive Paradigm
This book is based entirely on useful reactive patterns in Angular applications. Reactive
patterns are reusable solutions to a commonly occurring problem using reactive
programming. Behind all of these patterns, there is a new way of thinking, new
architecture, new coding styles, and new tools.
I know you are impatient to write your first reactive pattern in Angular, but before doing
that, and to help you take full advantage of all the RxJS patterns and leverage the reactive
paradigm, we will start by explaining, in detail, all the fundamentals. Additionally, we
will prepare the groundwork for the following chapters. First, let's start with a basic
understanding of the reactive paradigm, its advantages, and the problems it solves. And
best of all, let's get into the reactive mindset and start thinking reactively.
We will begin by highlighting the pillars and the advantages of the reactive paradigm.
Then, we will describe the relationship between Angular and RxJS. Finally, we will explain
the Marble diagram and why it is useful.
Giving an insight into the fundamentals of the reactive paradigm is incredibly important.
This will ensure you get the basics right, help you understand the usefulness of the reactive
approach, and consequently, help you determine which situation it is best to use it in.
4 The Power of the Reactive Paradigm

In this chapter, we're going to cover the following topics:

• Exploring the pillars of reactive programming


• Using RxJS in Angular and its advantages
• Learning about the marble diagram – our secret weapon

Technical requirements
This chapter does not require an environment setup or installation steps. All the code
snippets here are just examples to illustrate the concepts. This book assumes that you have
a basic understanding of Angular and RxJS.

Exploring the pillars of reactive programming


Let's begin with a little bit of background!
Reactive programming is among the major programming paradigms used by developers
worldwide. Every programming paradigm solves some problems and has its own
advantages. By definition, reactive programming is programming with asynchronous
data streams and is based on observer patterns. So, let's talk about these pillars of reactive
programming!

Data streams
Data streams are the spine of reactive programming. Everything that might change or
happen over time (you don't know when exactly) is represented as a stream, such as data,
events, notifications, and messages. Reactive programming is about reacting to changes as
soon as they are emitted!
An excellent example of data streams is UI events. Let's suppose that we have an HTML
button, and we want to execute an action whenever a user clicks on it. Here, we can think
of the click event as a stream:

//HTML code
<button id='save'>Save</button>

//TS code
const saveElement = document.getElementById('save');
saveElement.addEventListener('click', processClick);
Exploring the pillars of reactive programming 5

function processClick(event) {
console.log('Hi');
}

As implemented in the preceding code snippet, in order to react to this click event, we
register an EventListener event. Then, every time a click occurs, the processClick
method is called to execute a side effect. In our case, we are just logging Hi in the console.
As you might have gathered, to be able to react when something happens and execute
a side effect, you should listen to the streams to become notified. We can say listen or
observe to get closer to the reactive terminology. And this leads us to the observer design
pattern, which is at the heart of reactive programming.

Observer patterns
The observer pattern is based on two main roles: a publisher and a subscriber.
A publisher maintains a list of subscribers and notifies them or propagates a change every
time there is an update. On the other hand, a subscriber performs an update or executes a
side effect every time they receive a notification from the publisher:

Figure 1.1 – The observer pattern


So, to get notified about any updates, you need to subscribe to the publisher. A real-world
analogy would be a newsletter; you don't get any emails if you don't subscribe
to a newsletter.
6 The Power of the Reactive Paradigm

This leads us to the building blocks of RxJS. They include the following:

• Observables: These are a representation of the data streams that notify the
observers of any change.
• Observers: These are the consumers of the data streams emitted by observables.

RxJS combines the observer pattern with the iterator pattern and functional programming
to process and handle asynchronous events.
This was a reminder of the fundamentals of reactive programming. Remember, it is
crucial to understand when to put a reactive implementation in place and when to
avoid it.
In general, whenever you have to handle asynchronous tasks in your Angular application,
always think of RxJS. The main advantages of RxJS over other asynchronous APIs are
listed as follows:

• RxJS makes dealing with event-based programs, asynchronous data calls, and
callbacks an easy task.
• Observables guarantee consistency. They emit multiple values over time so that you
can consume continuous data streams.
• Observables are lazy; they are not executed until you subscribe to them. This helps
with writing declarative code that is clean, efficient, and easy to understand and
maintain.
• Observables can be canceled, completed, and retrieved at any moment. This makes
a lot of sense in many real-world scenarios.
• RxJS provides many operators with a functional style to manipulate collections and
optimize side effects.
• Observables push errors to the subscribers and provide a clean way to handle errors.
• RxJS allows you to write clean and efficient code to handle asynchronous data in
your application.

Now that we have given some insight into the reactive programming pillars and detailed
the major advantages of RxJS, let's shed some light on the relationship between Angular
and RxJS.
Using RxJS in Angular and its advantages 7

Using RxJS in Angular and its advantages


RxJS is a first-class citizen in Angular. It is part of the Angular ecosystem and is used in
many features to handle asynchronous operations. Primarily, this includes the following:

• HTTP client module


• Router module
• Reactive forms
• Event emitter
• Async pipe

We will discuss each of the following concepts in the subsequent subsections.

Note
We recommend taking a quick look at https://angular.io/docs.
Here, you can find further details about the features mentioned earlier.

The HTTP client module


You might be familiar with the HTTP client API provided by Angular in order to
communicate with your server over the HTTP protocol. The HttpClient service is
based on observables to manage all transactions. This means that the result of calling the
API methods (such as GET, PATCH, POST, or PUT) is an observable.
In the following code snippet, we have an example of an Angular service that injects
the HttpClient service and fetches data from the server using the HttpClient.
get() method:

Import { Injectable } from '@angular/core';


import { HttpClient } from '@angular/common/http';
import { Observable} from 'rxjs';
import { environment } from '@env/environment';
const BASE_PATH = environment.basePath;

@Injectable()
export class RecipesService {
constructor(private http: HttpClient) { }
getRecipes(): Observable<Recipe[]> {
return this.http.get<Recipe[]>(`${BASE_PATH}/recipes/search/
8 The Power of the Reactive Paradigm

all`);
}

The following is the content of the environment.ts file where we define the
basePath property of our backend:

export const environment = {


basePath: '/app/rest',
production: false
};

The getRecipes() method or, to be more accurate, the call to this.http.


get<Recipe>(`${BASE_PATH}/recipes/search`) returns an observable that
you should subscribe to in order to issue the GET request to the server. Please note that
this is an example of an HTTP transaction, and it is the same for all of the other HTTP
methods available in the API (such as POST, PUT, and PATCH)
For those familiar with promise-based HTTP APIs, you might be wondering, in this case,
what the advantages of using observables are.
Well, there are a lot of advantages but the most important ones are listed as follows:

• Observables are cancellable, so you can cancel the HTTP request whenever you
want by calling the unsubscribe method.
• Also, you can retry HTTP requests when an error occurs or an exception is thrown.
• The server's response cannot be mutated by observables, although this can be the
case when chaining then() to promises.

The router module


The router module, which is available in the @angular/router package, uses
observables in router events and activated routes.

Router events
The router exposes events as observables. The router events allow you to intercept the
navigation life cycle. The following list shows the sequence of router events:
• NavigationStart
• RouteConfigLoadStart
• RouteConfigLoadEnd
Using RxJS in Angular and its advantages 9

• RoutesRecognized
• GuardsCheckStart
• ChildActivationStart
• ActivationStart
• GuardsCheckEnd
• ResolveStart
• ResolveEnd
• ActivationEnd
• ChildActivationEnd
• NavigationEnd
• NavigationCancel
• NavigationError
• Scroll

Note
We recommend that you take a quick look at https://angular.io/
api/router/Event. Here, you can find further details about the events
and their order.

To intercept all the events that the router goes through, first, you should inject the
Router service, which provides navigation and URL manipulation capabilities. Then,
subscribe to the events observable available in the Router object, and filter the events
of the RouterEvent type using the rxjs filter operator.
This is an example of an Angular service that injects the Router object in the
constructor, subscribes to the router events, and just traces the event ID and path in the
console. However, note that you can also introduce pretty much any specific behavior:

import { Injectable } from '@angular/core';


import { Router, RouterEvent } from '@angular/router';
import { filter } from 'rxjs/operators';
@Injectable()
export class CustomRouteService {
constructor(public router: Router) {
this.router.events.pipe(
10 The Power of the Reactive Paradigm

filter(event => event instanceof RouterEvent)


).subscribe((event: RouterEvent) => {
console.log(`The current event is : ${event.id} |
event.url`);
});
}
}

You can filter any specific event by putting the target type. The following code example
only filters the NavigationStart event and traces the event ID and path inside the
console. However, you can also introduce pretty much any specific behavior:

import { Injectable } from '@angular/core';


import { NavigationStart, Router } from '@angular/router';
import { filter } from 'rxjs/operators';

@Injectable()
export class CustomRouteService {
constructor(public router: Router) {
this.router.events.pipe(
filter(event => event instanceof NavigationStart)
).subscribe((event: NavigationStart) => {
console.log(`The current event is : ${event.id} |
event.url`);
});

}
}

The majority of Angular applications have a routing mechanism. The router events change
frequently over time, and it makes sense to listen to changes to execute the side effects.
That's why observables are a flexible way in which to handle those streams.
Random documents with unrelated
content Scribd suggests to you:
a club, four feet long, until you drive it away, merely watching the
operations of the point of the tail, that, at each blow you give,
thrashes to the right and left most furiously.

‘The drivers of cattle from the Appelousas, and those of mules


from Mexico, on reaching a lagoon or creek, send several of their
party into the water, armed merely each with a club, for the purpose
of driving away the alligators from the cattle; and you may then see
men, mules, and those monsters, all swimming together, the men
striking the alligators, that would otherwise attack the cattle, of
which they are very fond, and those latter hurrying towards the
opposite shores, to escape those powerful enemies. They will swim
swiftly after a dog, or a deer, or a horse, before attempting the
destruction of man, of which I have always remarked they were
afraid, if the man feared not them.

‘Although I have told you how easily an alligator may be killed


with a single rifle-ball, if well aimed, that is to say, if it strike either
in the eye or very immediately above it, yet they are quite as difficult
to be destroyed if not shot properly; and, to give you an idea of this,
I shall mention two striking facts.

‘My good friend Richard Harlan, M.D. of Philadelphia, having


intimated a wish to have the heart of one of these animals to study
its comparative anatomy, I one afternoon went out about half a mile
from the plantation and, seeing an alligator that I thought I could
put whole into a hogshead of spirits, I shot it immediately on the
skull bone. It tumbled over from the log on which it had been
basking, into the water, and, with the assistance of two negroes,
I had it out in a few minutes, apparently dead. A strong rope was
fastened round its neck, and, in this condition, I had it dragged
home across logs, thrown over fences, and handled without the least
fear. Some young ladies there, anxious to see the inside of his
mouth, requested that the mouth should be propped open with a
stick put vertically; this was attempted, but at this instant the first
stunning effect of the wound was over, and the animal thrashed and
snapped its jaws furiously, although it did not advance a foot. The
rope being still round the neck, I had it thrown over a strong branch
of a tree in the yard, and hauled the poor creature up swinging, free
from all about it, and left it twisting itself, and scratching with its
fore feet to disengage the rope. It remained in this condition until
the next morning, when finding it still alive, though very weak, the
hogshead of spirits was put under it, and the alligator fairly lowered
into it with a surge. It twisted about a little; but the cooper secured
the cask, and it was shipped to Philadelphia, where it arrived in
course.

‘Again, being in company with Augustin Bourgeat, Esq., we met


an extraordinary large alligator in the woods whilst hunting; and, for
the sake of destruction I may say, we alighted from our horses, and
approached with full intention to kill it. The alligator was put
between us, each of us provided with a long stick to irritate it; and,
by making it turn its head partly on one side, afford us the means of
shooting it immediately behind the fore leg and through the heart.
We both discharged five heavy loads of duck-shot into its body, and
almost all into the same hole, without any other effect than that of
exciting regular strokes of the tail, and snapping of the jaws at each
discharge, and the flow of a great quantity of blood out of the
wound, and mouth, and nostrils of the animal; but it was still full of
life and vigor, and to have touched it with the hand would have been
madness; but as we were anxious to measure it, and to knock off
some of its larger teeth to make powder charges, it was shot with a
single ball just above the eye, when it bounded a few inches off the
ground, and was dead when it reached it again. Its length was
seventeen feet; it was apparently centuries old; many of its teeth
measured three inches. The shot taken were without a foot only of
the circle that we knew the tail could form, and our shots went en
masse.

‘As the lakes become dry, and even the deeper connecting
bayous empty themselves into the rivers, the alligators congregate
into the deepest hole in vast numbers; and, to this day, in such
places, are shot for the sake of their oil, now used for greasing the
machinery of steam-engines and cotton mills, though formerly, when
indigo was made in Louisiana, the oil was used to assuage the
overflowing of the boiling juice, by throwing a ladleful into the kettle
whenever this was about to take place. The alligators are caught
frequently in nets by fishermen; they then come without struggling
to the shore, and are killed by blows on the head given with axes.

‘When autumn has heightened the coloring of the foliage of our


woods, and the air feels more rarefied during the nights and earlier
part of the day, the alligators leave the lakes to seek for winter
quarters, by burrowing under the roots of trees, or covering
themselves simply with earth along their edges. They become then
very languid and inactive, and, at this period, to sit or ride on one
would not be more difficult than for a child to mount his wooden
rocking-horse. The negroes, who now kill them, put all danger aside,
by separating, at one blow with an axe, the tail from the body. They
are afterwards cut up in large pieces, and boiled whole in a good
quantity of water, from the surface of which the fat is collected with
large ladles. One single man kills oftentimes a dozen or more of
large alligators in the evening, prepares his fire in the woods, where
he has erected a camp for the purpose, and by morning has the oil
rendered.

‘I have frequently been very much amused when fishing in a


bayou, where alligators were numerous, by throwing a blown
bladder on the water towards the nearest to me. The alligator makes
for it, flaps it towards its mouth, or attempts seizing it at once, but
all in vain. The light bladder slides off; in a few minutes many
alligators are trying to seize this, and their evolutions are quite
interesting. They then put one in mind of a crowd of boys running
after a football. A black bottle is sometimes thrown also, tightly
corked; but the alligator seizes this easily, and you hear the glass
give way under its teeth as if ground in a coarse mill. They are easily
caught by negroes, who most expertly throw a rope over their heads
when swimming close to shore, and haul them out instantly.’
The Tortoise is found in considerable numbers and variety. In the
lakes west of the Mississippi, and near New Orleans, a soft shelled
mud-tortoise is found, which epicures declare to be not much
inferior to the sea-turtle of the West Indies. The gouffre is an animal
apparently of the tortoise class, and is abundant in the pine barrens
of the south-western states. Its shell is large and thick, and it
burrows to a great depth in the ground; its strength and power are
wonderful, and in many respects it is similar to the logger-head
turtle. The siren is nearly two feet in length, and a very singular
animal; it somewhat resembles the lamprey. It is amphibious,
penetrates the mud easily, and seems to be of an order between fish
and lizards. The whole of the republic is prolific in toads, frogs, and
reptiles of that class; but they are found in the greatest number and
variety in the regions of the warmest temperature.
V. INSECTS.
The insects of the United States are numerous, and many of
them beautiful; many of the species are entirely new, and science
has been much indebted to Mr. Say for additions of no
inconsiderable importance to entomology. The moths and butterflies
are exceedingly splendid, and one of them, the atlas moth, is the
largest hitherto known. Among the spiders, is a huge species called
the tarantula, supposed to inflict a dangerous bite. The annoyance
inflicted by moschetos in hot weather is well known; by these and
other stinging insects, damp and low situations are rendered very
disagreeable during the summer. The fire flies, which glitter
especially in the southern forests, are very interesting. The copper
colored centiped, a creature of cylindrical form, and as long as a
man’s finger, is dreaded as noxious; a family is said to have been
poisoned by taking tea in which one of them had been accidentally
boiled.

One insect, the ægeria exitiosa, has committed great ravages


among the peach trees. The larva begins the work of destruction
about the beginning of October, by entering the tree, probably
through the tender bark under the surface of the soil; thence it
proceeds downwards, within the tree, into the root, and then turns
its course upwards towards the surface, where it arrives about the
commencement of the succeeding July. They voraciously devour
both the alburnum and the liber, the new wood and the inner bark.
The insects deposit from one to three hundred eggs within the bark
of the tree, according to its capacity to support their progeny.
The United States are not free from the scourge of the locust.
The males have under each wing a ribbed membrane as thin as a
gossamer’s web, which, when inflated, constitutes their musical
organ. The female has a sting or drill, the size of a pin, and near half
an inch in length, of a hard and brittle substance, which lies on the
under surface of the body; with this the insect drills a hole into the
small limbs of trees, quite to the pith; there it deposits through this
hollow sting or drill some dozen or two of small white eggs. The time
required to drill the hole and deposit the egg is from two to five
minutes. When undisturbed, they make some half dozen or more
insertions of their drill in the same limb, perhaps an inch apart, and
these punctures usually produce speedy death to the end of the
limb. They sometimes swarm about the forests in countless
multitudes, making ‘melancholy music,’ and causing no less
melancholy desolation.

GENERAL REMARKS ON ZOOLOGY.

The zoology of the United States opens a wide and interesting field of
observation: it is more peculiar and striking than either the mineralogy or
botany. The following general view of the mammiferous animals inhabiting
North America is given by Dr. Harman. The number of species now
ascertained is one hundred and forty-six, in which we do not include man;
of these twenty-eight are cetacea, and one hundred and eighteen are
quadrupeds. Among the quadrupeds, Dr. Harman reckons eleven species, of
which no living trace is found in any part of the world; which cannot of
course be considered as forming a part of our present zoology. The number
of living species of quadrupeds is therefore one hundred and seven. The
comparative numbers of the several orders are stated as follows, omitting
man:

Carnivora 60
Glires 37
Edentata 6
Pachydermata 2
Ruminantia 13
Cetacea 28

We may here introduce from Dr. Harman a statement of the number of


North American quadrupeds, which he conceives to be common both to the
new and old world.

Species.
1 Mole.
2 Shrew.
1 Bear.
1 Glutton.
1 Otter.
2 Wolf.
2 Fox.
2 Seal.
2 Weasel.
1 Beaver.
1 Field-mouse.
1 Campagnol (rat.)
1 Squirrel.
2 Deer.
1 Sheep.

The whole number of common species is twenty one; leaving eighty-six


species as peculiar to North America, though not all of them to the United
States.

Charles Lucien Bonaparte has arranged the birds of the United States in
twenty-eight families, eighty-one genera, and three hundred and sixty-two
species, viz.: two hundred and nine land, and one hundred and fifty-three
water-birds. Of the eighty-one genera, sixty-three are common to Europe
and America, while eighteen have no representatives in Europe.
CHAPTER XVII.—
BOTANY.
The vegetation of the United States is as various as the climate
and soil. In Florida and the southern states, the superb magnolia,
the majestic tulip tree and the deciduous cypress charm the traveller
by their grandeur and beauty. The lofty oak, the stately fir and the
gracefully-waving elm of the north, present a different and still a
highly interesting study to the naturalist. As a general observation,
the trees of the United States are larger, taller, and more generally
useful for timber than those of Europe. As to height, it is observed
by Michaux, that, while in France only thirty-seven species of trees
arrive at thirty feet, in the transatlantic republic, one hundred and
thirty exceed that elevation. A general idea of the American forest
having thus been given, we will now notice, as largely as our limits
will permit, the most remarkable trees.

Oak.—The White Oak is found throughout the United States,


though it is by no means equally diffused. It abounds chiefly in the
middle states, particularly in that part of Pennsylvania and Virginia
which lies between the Alleghanies and the Ohio, a distance of about
one hundred and fifty miles, where nine tenths of the forests are
frequently composed of these trees, whose healthful appearance
evinces the favorable nature of the soil. East of the mountains, this
tree is found in every exposure, and in every soil which is not
extremely dry or subject to long inundations; but the largest stocks
grow in humid places. In the western districts, where it composes
entire forests, the face of the country is undulated, and the yellow
soil, consisting partly of clay with calcareous stones, yields abundant
crops of wheat.

The white oak attains the elevation of seventy or eighty feet,


with a diameter of six or seven feet; but its proportions vary with the
soil and climate. Soon after their unfolding, the leaves are reddish
above and white and downy beneath; when fully grown, they are
smooth and of a light green on the upper surface. In autumn, they
change to a bright violet color, and form an agreeable contrast with
the surrounding foliage which has not yet suffered by the frost. This
is the only oak on which a few of the dried leaves remain till the
circulation is renewed in the spring. By this peculiarity and by the
whiteness of the bark, from which it derives its name, it is easily
distinguishable in the winter. This tree puts forth flowers in May,
which are succeeded by acorns of an oval form, large, very sweet,
contained in rough, shallow, grayish cups, and borne singly or in
pairs, by peduncles eight or ten lines in length, attached, as in all
species of annual fructification, to the shoots of the season. The fruit
of the white oak is rarely abundant, and frequently, for several years
in succession, a few handfuls of acorns could hardly be collected in a
large forest where the tree is multiplied. Some stocks produce
acorns of a deep blue color.

Of all the American oaks, this is the best and the most generally
used, being strong, durable, and of large dimensions. It is less
employed than formerly in building, only because it is scarcer and
more costly. Among the uses of this wood, the most important is in
ship-building. In all the dock yards of the northern and middle
states, except Maine, it is almost exclusively employed for the keel,
and always for the lower part of the frame and the sides: it is
preferred for the knees, when sticks of a proper form can be found.
In the smaller ports south of New York, the upper part of the frame
is also made of white oak; but such vessels are less esteemed than
those constructed of more durable wood. The medicinal properties
of oak bark depend on its astringency, and that again on its tannin.
The inner bark of the small branches is the strongest, the middle
bark next, and the outer bark is almost useless.

The Gray Oak, Water Oak, Bear Oak, Upland, Willow Oak, and
Bartram Oak are interesting varieties. The Laurel Oak is a stranger
north of Philadelphia, and is rare in the more southern states. It is
most abundant in the open savannas of Illinois. Rising to the height
of forty or fifty feet, clad in a smooth bark, and for three fourths of
its height laden with branches, it presents an uncouth appearance
when bared by the winter blasts, but in the summer with its thick
tufted foliage is really beautiful. The Black Oak is found throughout
the country, with the exception of the northern part of New England.
It is one of the loftiest of the American forest trees, rising to the
height of eighty or ninety feet, with a diameter of four or five feet.
The wood is reddish and coarse-grained, with empty pores, but is
esteemed for strength and durability. It furnishes excellent fuel, and
the bark is largely used for tanning. Other varieties of the oak are
numerous.

Walnut.—The Black Walnut is met with in large numbers in the


forests in the vicinity of Philadelphia, and with the exception of the
lower parts of the southern states, where the soil is too sandy, or
too wet as in the swamps, it is met with to the banks of the
Mississippi throughout an extent of two thousand miles. East of the
Alleghanies in Virginia, and in the upper parts of the Carolinas and
Georgia, it is chiefly confined to the valleys where the soil is deep
and fertile, and which are watered by creeks and rivers. On the
banks of the Ohio and on the islands of this beautiful river, the black
walnut attains the elevation of sixty or seventy feet, with a diameter
of three to seven feet. Its powerful vegetation clearly points out this,
as one of the largest trees of America. When it stands insulated, its
branches, extending themselves horizontally to a great distance,
spread into a spacious head, which gives it a very majestic
appearance. The bark is thick, blackish, and on old trees deeply
furrowed. The leaves when bruised emit a strong aromatic odor.

When the wood of this tree is freshly cut, the sap is white and
the heart of a violet color, which, after a short exposure to the air,
assumes an intenser shade, and becomes nearly black: hence
probably is derived the name Black Walnut. There are several
qualities for which its wood is principally esteemed: it remains sound
for a long time, even when exposed to the influences of heat and
moisture; but this observation is only applicable to the heart, the sap
speedily decays: it is very strong and very tenacious: when
thoroughly seasoned, it is not liable to warp and split; and its grain
is sufficiently fine and compact to admit of a beautiful polish. It
possesses, in addition to these advantages, that of being secure
from worms. On account of these excellencies, it is preferred and
successfully employed in many kinds of work. East of the
Alleghanies, its timber is not extensively used in building houses,
but, in some parts of Kentucky and Ohio, it is split into shingles
which serve to cover them: sometimes also this timber enters into
the composition of the frame. But it is chiefly in cabinet-making, that
this wood is employed wherever it abounds.

There are several other species of the walnut. The Shell-bark


Hickory sometimes grows to the height of eighty or ninety feet, with
a diameter of less than two feet; the trunk is destitute of branches,
regularly shaped, and almost of a uniform size for three fourths of its
length. The Butternut is found in all the New England states, and in
the middle states.

Maple.—The Sugar Maple, called also rock maple, has leaves five-
parted, and yellowish green flowers, and is one of the loftiest trees
in our forests. Its trunk is usually straight and entire, to the height of
from forty to eighty feet, where it suddenly unfolds into a dense top,
crowded with rich foliage. The bark of the older trees is gray, and
marked with numerous deep clefts. The wood is firm and heavy,
though not durable. It is much used by cabinet-makers, and when
cut at the right season forms excellent fuel. Michaux says, that it
grows in its greatest perfection, between the forty-third and forty-
sixth degrees of north latitude.

The White Maple, sometimes called silver maple, is distinguished


by having its leaves five-parted, and white beneath; its flowers
reddish yellow, without flower-stalks. The trunk frequently divides
near the ground, so as to appear like several trunks close together.
These divisions diverge a little as they rise, and often at the height
of from eight to twenty feet the top commences. This is generally
larger in proportion to the trunk, than the top of any other tree. It
blossoms earlier than the sugar maple. The fruit is larger than that
of any other species: it advances with great rapidity towards
perfection, ripens and falls about June in Georgia, and May in
Pennsylvania. The fruit of the sugar maple does not ripen until
October. The white maple is principally found on the banks of rivers,
and on the banks of such only as have a clean gravelly bottom and
clear water. It is most luxuriant on flats which are subject to annual
inundations, and is usually the first settler on alluvial deposits. ‘The
banks of the Sandy river, in Maine,’ says Michaux, ‘and those of the
Connecticut in Windsor, Vermont, are the most northerly points at
which I have seen the white maple. It is found more or less on all
the rivers of the United States, flowing from the mountains to the
Atlantic, but becomes scarce in South Carolina and Georgia. In no
part of the United States is it more multiplied than in the western
country, and no where is its vegetation more luxuriant than on the
banks of the Ohio, and of the great rivers that empty into it. There,
sometimes alone, and sometimes mingled with the willow, which is
found all along these waters, it contributes singularly by its
magnificent foliage to the embellishment of the scene. The brilliant
white of the leaves beneath, forms a striking contrast with the bright
green above, and the alternate reflection of these two surfaces in
the water, heightens the beauty of this wonderful moving mirror, and
aids in forming an enchanting picture, which during my long
excursions in a canoe, in these regions of solitude and silence,
I contemplated with unwearied admiration.’
The Red-flowering Maple is a beautiful tree, and in the swamps
of New Jersey and Pennsylvania, it is found to the height of sixty or
seventy feet, with a diameter of three or four. It blossoms earlier in
the spring than any other tree, and flowers from the middle to the
last of April. The blossoms, of a beautiful purple or deep red, unfold
more than a fortnight before the leaves. This tree furnishes wood
adapted to a variety of purposes; it is much used in making domestic
wares and agricultural implements. Furniture of great richness and
lustre is also made of it. It is not good fuel. The Mountain, Striped
and Ash-leaved Maples are all beautiful trees.

Birch.—The Black Birch abounds in New England and the middle


states; farther south it is confined to the summits of the Alleghanies.
It often exceeds seventy feet in height. At the close of winter, the
leaves, during a fortnight after their birth, are covered with a thick,
silvery down, which soon after disappears. When bruised, the leaves
and bark diffuse a very agreeable odor, and as they retain this
property when dried and carefully preserved, they afford a pleasant
infusion, with the addition of a little sugar and cream. The wood is
applied to a variety of useful purposes; it is of a rosy hue, which
deepens on exposure to the light. The Yellow, Canoe, White, and
Red Birch are found in various localities throughout the country.

Pines.—The pines constitute a large and interesting class of


American forest trees. The most valuable species is that which is
known in England and the West Indies as the Georgia Pitch Pine;
and which, in the United States, is variously called yellow pine, pitch
pine, broom pine, southern pine, red pine, and long-leaved pine, a
name which is adopted by Michaux. Towards the north, the long-
leaved pine makes its appearance near Norfolk, in Virginia, where
the pine-barrens begin. It seems to be especially assigned to dry
sandy soils; and it is found, almost without interruption, in the lower
part of Carolinas, Georgia, and the Floridas, over a tract more than
six hundred miles long, from north-east to south-west, and more
than a hundred miles broad, from the sea towards the mountains.
Immediately beyond Raleigh, it holds almost exclusive possession of
the soil, and is seen in company with other pines only on the edges
of swamps, enclosed in the barrens; even there not more than one
stock in a hundred is of another species, and with this exception, the
long-leaved pine forms the unbroken mass of woods which covers
this extensive country.

The mean stature of the long-leaved pine is sixty or seventy feet,


with a uniform diameter of fifteen or sixteen inches for two thirds of
this height. Some stocks, favored by local circumstances, attain
much larger dimensions, particularly in East Florida. The timber is
very valuable, being stronger, more compact, and more durable,
than that of all the other species of pine: it is besides fine grained,
and susceptible of high polish. Its uses are diversified, and its
consumption great. But the value of the long-leaved pine does not
reside exclusively in its wood; it supplies nearly all the resinous
matter used in the United States in ship-building, with a large
residue for exportation; and in this view, its place can be supplied by
no other species, those which afford the same product being
dispersed through the woods, or collected in inaccessible places. In
the northern states, the lands, which at the commencement of their
settlements were covered with pitch pine, were exhausted in twenty-
five or thirty years, and for more than half a century have ceased to
furnish tar. The pine-barrens are of vast extent, and are covered
with trees of the forest growth; but they cannot all be rendered
profitable, from the difficulty of communicating with the sea.

Among the varieties which we can only enumerate, without an


attempt at description, are the New Jersey, Table Mountain, Gray,
Pond, and White Pine.

Spruces.—The American Silver Fir is found in the colder regions


of the states; towards the south, it is found only on the tops of the
Alleghanies. It flourishes best in a moist, sandy loam. Its height
rarely exceeds forty feet, with a diameter of twelve or fifteen inches.
The trunk tapers from a foot in diameter at the surface of the
ground to seven or eight inches at the height of six feet. When
standing alone and developing itself naturally, its branches, which
are numerous and thickly garnished with leaves, diminish in length
in proportion to their height, and form a pyramid of perfect
regularity. The bark is smooth and delicate. The leaves are six or
eight lines long, and are inserted singly on the sides and on the top
of the branches; they are narrow, rigid and flat, of a bright green
above, and a silvery white beneath; whence probably is derived the
name of the tree. The flowers appear in May, and are followed by
cones of a fragrant odor, nearly cylindrical, four or five inches long,
an inch in diameter, and always directed upwards. The seeds are
ripe in autumn, and if permitted to hang late will fall apart and
scatter themselves. The wood of the silver fir is light and slightly
resinous, and the heart is yellowish.

The Hemlock Spruce inhabits a similar tract of country, though


moist ground appears not to be the most favorable to its growth. It
arrives at the height of seventy or eighty feet, with a circumference
of six or nine feet, and is uniform for two thirds of its length. The
White and Black Spruce are varieties of this genus.

Cypresses.—The Cypress is a very interesting tree, from its


extraordinary dimensions, and the varied application of its wood. Its
northern boundary is Indian river, in Delaware, in latitude about
thirty-nine degrees. In proceeding southward, it becomes more
abundant in the swamps, and in Louisiana those parts of the
marshes where the cypress grows almost alone are called cypress
swamps, and they sometimes occupy thousands of acres. In the
swamps of the southern states and the Floridas, on whose deep,
miry soil a new layer of vegetable mould is every year deposited by
floods, the cypress attains its utmost developement. The largest
stocks are one hundred and twenty feet in height, and from twenty-
five to forty feet in circumference, above the conical base, which at
the surface of the earth is three or four times as large as the
continued diameter of the trunk: in felling them, the negroes are
obliged to raise themselves upon scaffolds five or six feet from the
ground. The base is usually hollow for three fourths of its bulk.
Amidst the pine forests and savannas of the Floridas is seen here
and there a bog filled with cypresses, whose squalid appearance,
when they exceed eighteen or twenty feet in height, proves how
much they are affected by the barrenness of a soil which differs from
the surrounding only by a layer of vegetable mould, a little thicker
upon the quartzous sand. The summit of the cypress is not
pyramidical like that of the spruce, but is widely spread and even
depressed upon old trees. The foliage is open, light, and of a fresh
agreeable tint; each leaf is four or five inches long, and consists of
two parallel rows of leaflets upon a common stem. The leaflets are
small, fine, and somewhat arching, with the convex side outwards.
In autumn they change from a light green to a dull red, and are
shed soon after. This tree blooms in Carolina about the first of
February.

Among the resinous trees of the United States, the White Cedar
is one of the most interesting for the varied utility of its wood. North
of the river Connecticut, it is rare and little employed in the arts. In
the southern states, it is not met with beyond the river Santee, but it
is found, though not abundantly, on the Savannah: it is multiplied
only within these limits and to the distance of fifty miles from the
ocean. The white cedar is seventy or eighty feet high, and
sometimes more than three feet in diameter. When the trees are
close and compressed, the trunk is straight, perpendicular and
destitute of branches to the height of fifty or sixty feet. When cut, a
yellow transparent resin of an agreeable odor exudes, of which a
few ounces could hardly be collected in a summer from a tree of
three feet in circumference. The foliage is evergreen: each leaf is a
little branch numerously subdivided, and composed of small, acute,
imbricated scales.

The White Ash is one of the most interesting among the


American species for the qualities of its wood, and the most
remarkable for the rapidity of its growth and for the beauty of its
foliage. A cold climate seems most congenial to its nature. It is
everywhere called White Ash, probably from the color of its bark, by
which it is easily distinguished. The situations most favorable to this
tree are the banks of rivers and the edges and surrounding
acclivities of swamps. The white ash sometimes attains the height of
eighty feet, with a diameter of three feet, and is one of the largest
trees of the United States. The trunk is perfectly straight and often
undivided to the height of more than forty feet. On large stocks the
bark is deeply furrowed, and divided into small squares from one to
three inches in diameter. The leaves are twelve or fourteen inches
long, opposite and composed of three or four pair of leaflets
surmounted by an odd one. The leaflets are three or four inches
long, about two inches broad, of a delicate texture and an undulated
surface. Early in the spring they are covered with a light down,
which gradually disappears, and at the approach of summer they are
perfectly smooth, of a light green color above and whitish beneath.
It puts forth white or greenish flowers in the month of May, which
are succeeded by seeds that are eighteen lines long, cylindrical near
the base, and gradually flattened into a wing, the extremity of which
is slightly notched. They are united in bunches four or five inches
long, and are ripe in the beginning of autumn. The shoots of the two
preceding years are of a bluish gray color and perfectly smooth: the
distance between their buds sufficiently proves the vigor of their
growth.

Elm.—The White Elm inhabits an extensive tract of the states,


being found from Nova Scotia to the extremity of Georgia. It is also
found on the banks of the western rivers; growing in low, moist and
substantial soils. In the middle states, this tree stretches to a great
height, but does not approach the magnificence of vegetation which
it displays in the countries peculiarly adapted to its growth. In
clearing the primitive forests, a few stocks are sometimes left
standing; insulated in this manner, it appears in all its majesty,
towering to the height of eighty or one hundred feet, with a trunk
four or five feet in diameter, regularly shaped, naked, and insensibly
diminishing to the height of sixty or seventy feet, where it divides
itself into two or three primary branches. This species differs from
the red and European elm in its flowers and seeds; it blooms in the
month of April, previous to the unfolding of the leaves; the flowers
are very small, of a purple color, supported by short, slender
footstalks, and united in bunches at the extremity of the branches.
The Wahoo and the Red Elm are interesting species.

The American Chesnut sometimes attains the height of seventy


or eighty feet, with a circumference of fifteen or sixteen feet.
Though this tree nearly resembles that of Europe in its general
appearance, its foliage, its fruit and the properties of its wood, it is
treated by botanists as a distinct species. Its leaves are six or seven
inches long, one and a half broad, coarsely toothed, of an elongated
oval form, of a fine, brilliant color and of a firm texture, with
prominent parallel nerves beneath. It flowers in June. The fruit is
spherical, covered with fine prickles, and stored with two dark brown
seeds or nuts, about as large as the end of the finger. They are
smaller and sweeter than the wild chesnuts of Europe. They are ripe
about the middle of October. The wood is strong, elastic and capable
of enduring the succession of dryness and moisture.

Buttonwood or Sycamore.—Among trees with deciduous leaves,


none in the temperate zones, either in the old or new continent,
equal the dimensions of the planes. The species which we are about
to describe is not less remarkable for its amplitude, and for its
magnificent appearance, than the plane of Asia, whose majestic
form and extraordinary size were so much celebrated by the
ancients. In the Atlantic states, this tree is commonly known by the
name of Buttonwood, and sometimes in Virginia, by that of Water
Beach. On the banks of the Ohio, and in the states of Kentucky and
Tennessee, it is most frequently called Sycamore, and by some
persons Plane Tree. This tree, in no part of the United States, is
more abundant and vigorous than along the rivers of Pennsylvania
and Virginia; though in the more fertile valleys of the west, its
vegetation is still more luxuriant, especially on the banks of the Ohio
and of the rivers that flow into it.
On the margin of the great rivers of the west, the buttonwood is
constantly found to be the loftiest and largest tree of the United
States. Often with a trunk of several feet in diameter, it begins to
ramify at the height of sixty or seventy feet, near the summit of
other trees; and often the base divides itself into several trunks,
equally vigorous and superior in diameter to any of the surrounding
trees. On a little island in the Ohio, fifteen miles above the mouth of
the Muskingum, Michaux mentions a buttonwood which, at five feet
above the ground, was forty feet and four inches in circumference,
and consequently more than thirteen feet in diameter. The American
species is generally thought, in Europe, to possess a richer foliage,
and to afford a deeper shade than the Asiatic plane: its leaves are of
a beautiful green, alternate, from five to fifteen inches broad, and
formed with more open angles than those of the plane of the
eastern continent.

Beech.—The species of Red Beech is almost exclusively confined


to the north-eastern parts of the United States. In the state of
Maine, New Hampshire and Vermont, it is so abundant as often to
constitute extensive forests, the finest of which grow on fertile, level
or gently sloping lands which are proper for the culture of corn. The
red beech equals the white species in diameter, but not in height;
and as it ramifies nearer the earth and is more numerously divided,
it has a more massy summit and the appearance of more tufted
foliage. Its leaves are equally brilliant, a little larger and thicker, and
have longer teeth. Its fruit is of the same form, but is only half as
large, and is garnished with firmer and less numerous points.

The White Beech is one of the tallest and most majestic trees of
the American forests. It grows the most abundantly in the middle
and western states. On the banks of the Ohio, the white beech
attains the height of more than one hundred feet, with a
circumference of eight to eleven feet. In the forests, where these
trees vegetate in a deep and fertile soil, their roots sometimes
extend to a great distance even with the surface, and being
entangled so as to cover the ground, they embarrass the steps of
the traveller and render the land peculiarly difficult to clear. This tree
is more slender and less branchy than the red beech; but its foliage
is superb, and its general appearance magnificent.

Poplar or Tulip Tree.—This tree, which surpasses most others of


North America in height and in the beauty of its foliage and of its
flowers, is one of the most interesting from the numerous and useful
applications of its wood.

In the Atlantic states, especially at a considerable distance from


the sea, tulip trees are often seen seventy, eighty and one hundred
feet in height, with a diameter of eighteen inches to three feet. But
the western states appear to be the natural soil of this magnificent
tree, and here it displays its most powerful vegetation. M. Michaux
mentions a tulip tree, near Louisville, on the Ohio, which at five feet
from the ground was twenty-two feet six inches in circumference,
and whose elevation he judged to be from one hundred and twenty
to one hundred and forty feet. The flowers bloom in June or July.
They are large, brilliant, and on detached trees very numerous,
variegated with different colors: they have an agreeable odor, and
produce a fine effect. The fruit is composed of a great number of
thin, narrow scales, attached to a common axis, and forming a cone
two or three inches in length. Each cone consists of sixty or seventy
seeds, of which never more than a third part are productive. For ten
years before the tree begins to yield fruit, almost all the seeds are
unproductive, and on large trees, those from the highest branches
are the best.

Catalpa.—In the Atlantic states, the Catalpa begins to be found in


the forests, on the banks of the river Savannah, and west of the
Alleghanies, on those of the Cumberland, between the thirty-fifth
and thirty-sixth degrees of latitude. Farther south it is more
common, and abounds near the borders of all the rivers which
empty into the Mississippi, or which water West Florida. In the
regions where it grows most abundantly, it frequently exceeds fifty
feet in height, with a diameter from eighteen to twenty-four inches.
It is easily recognised by its bark, which is of a silver-gray color, and
but slightly furrowed, by its ample leaves, and by its wide-spreading
summit, disproportioned in size to the diameter of its trunk. It differs
from other trees also by the fewness of its branches. The flowers
which are collected in large bunches at the extremity of the
branches, are white, with violet and yellow spots, and are beautiful
and showy.

Magnolia Grandiflora.—‘Bartram and others,’ says Mr. Flint, ‘by


overrating the beauty of this tree, have caused, that when strangers
first behold it, their estimation of it falls too low. It has been
described, as a very large tree. We have seen it in Florida, where
Bartram saw it. We have seen it in its more congenial position for full
developement, the rich alluvions of Louisiana; and we have never
seen it compare with the sycamore, the cotton wood, or even the
ash, in point of size. It is sometimes a tall tree; often graceful in
form; but ordinarily a tree of fourth or fifth rate in point of
comparative size in the forest, where it grows. Its bark is smooth,
whitish, very thick, and something resembles that of the beech. The
wood is soft, and for aught we know, useless. The leaves strongly
resemble those of the orange tree, except in being larger, thicker,
and having a hoary yellowish down upon the under side. The upper
side has a perfect verdure, and a feel of smoothness, as if it was
oiled. The flowers are large, of a pure white, nearest resembling the
northern pond lily, though not so beautiful; and are, ordinarily, about
twice the size. The fragrance is indeed, powerful, but to us rather
sickly and offensive. We have felt, and we have heard others
complain of feeling a sensation of faintness, in going into a room,
where the chimney place was filled with these flowers. The tree
continues to put forth flowers for two months in succession, and
seldom displays many at a time.

‘We think, few have been in habits of examining flowering trees


more attentively than ourselves, and we contemplated this tree for
years in the season of flowers. Instead of displaying, as has been
represented, a cone of flowers, we have seldom seen a tree in
flower, which did not require some attention and closeness of
inspection, to discover where the flowers were situated among the
leaves. We have not been led to believe, that others possessed the
sense of smell more acutely, than ourselves. In advancing from
points, where these trees were not, to the pine forest, on the water
courses of which they are abundant, we have been warned of our
approach to them by the sense of smell, at a distance of something
more than half a mile; and we question, if any one ever perceived
the fragrance much farther, except by the imagination. The magnolia
is a striking tree, and an observer, who saw it for the first time,
would remark it, as such. But we have been unable to conceive
whence the extravagant misconceptions, respecting the size,
number, fragrance and beauty of its flowers, had their origin.

‘There are six or seven varieties among the laurels of the


magnolia tribe, some of which have smaller flowers than those of
the grandiflora, but much more delicate, and agreeably fragrant.
A beautiful evergreen of this class is covered in autumn with berries
of an intense blackness, and we remarked them in great numbers
about St. Francisville. The holly is a well-known and beautiful tree of
this class. But that one, which has struck us, as being the
handsomest of the family, is the laurel almond. It is not a large tree.
Its leaves strongly resemble those of the peach; and it preserves a
most pleasing green through the winter. Its flowers yield a delicious
perfume. It grows in families of ten or fifteen trees in a cluster.
Planters of taste in the valley of Red river, where it is common,
select the place of their dwelling amidst a cluster of these trees.’

The Bow Wood is a very striking tree, found about the upper
courses of the Washita, the middle regions of Arkansas, and
occasionally on the northern limits of Louisiana. Its leaves are large
and beautiful, and its fruit, which somewhat resembles a large
orange, is of a most inviting appearance, but is ‘the apple of Sodom
to the taste.’ It is considered by many the most splendid of all forest
trees.
The China Tree is much cultivated in the south-western region of
the states, as an ornamental shade tree. Its leaves are long and
spiked, set in correspondence on each side of the stem. The verdure
is deep and brilliant. When in full flower, the top is one tuft of
blossoms. The tree is of most rapid growth, and its beautiful color
imparts delightful freshness to the landscape. After the fall of its
leaves, a profusion of reddish berries remain, and give at a little
distance the appearance of continuing in flower. This berry is a
narcotic, and stupefies the birds that eat of it.

The Papaw is seldom found north of the river Schuylkill, and is


extremely rare in the low, maritime parts of the southern states. It is
not uncommon in the bottoms which stretch along the rivers of the
middle states; but it is most abundant in the rich valleys intersected
by the western waters, where at intervals, it forms thickets
exclusively occupying several acres. In Kentucky and in the western
part of Tennessee, it is sometimes seen also in forests where the soil
is luxuriantly fertile; of which its presence is an infallible proof.

It seldom exceeds thirty feet in height, and a diameter of six or


eight inches, though it generally stops short at half this elevation.
The trunk is covered with a silver-gray bark, which is smooth and
finely polished. The leaves are alternate, five or six inches in length,
and of an elongated form, widening from the base to the summit.
They are of a fine texture, and the superior surface is smooth and
brilliant. The flowers are pendent, and of a purple hue. When the
fruit is ripe, which takes place towards the beginning of August, it is
about three inches long, one and a half thick, of a yellowish color,
and of an oval form, irregular and swelling into inequalities. Its pulp
is soft, and of an insipid taste, and it contains several large,
triangular stones.

Persimon.—The banks of the river Connecticut, below the forty-


second degree of latitude, may be uniformly considered as the
northern limit of this tree; but it is rendered rare in these parts by
the severity of the winter, while in New Jersey it is common, and still
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like