Download as pdf or txt
Download as pdf or txt
You are on page 1of 38

Building Native Web Components:

Front-End Development with Polymer


and Vue.js Carlos Rojas
Visit to download the full and correct content document:
https://textbookfull.com/product/building-native-web-components-front-end-developm
ent-with-polymer-and-vue-js-carlos-rojas/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Developing Web Components with TypeScript: Native Web


Development Using Thin Libraries 1st Edition Jorg
Krause [Krause

https://textbookfull.com/product/developing-web-components-with-
typescript-native-web-development-using-thin-libraries-1st-
edition-jorg-krause-krause/

Vue on Rails: End-to-End Guide to Building Web Apps


Using Vue.js and Rails Bryan Lim

https://textbookfull.com/product/vue-on-rails-end-to-end-guide-
to-building-web-apps-using-vue-js-and-rails-bryan-lim/

Developing Web Components with TypeScript Native Web


Development Using Thin Libraries 1st Edition Jorg
Krause Krause Jörg

https://textbookfull.com/product/developing-web-components-with-
typescript-native-web-development-using-thin-libraries-1st-
edition-jorg-krause-krause-jorg/

Full-Stack Web Development with Jakarta EE and Vue.js:


Your One-Stop Guide to Building Modern Full-Stack
Applications with Jakarta EE and Vue.js Daniel Andres
Pelaez Lopez
https://textbookfull.com/product/full-stack-web-development-with-
jakarta-ee-and-vue-js-your-one-stop-guide-to-building-modern-
full-stack-applications-with-jakarta-ee-and-vue-js-daniel-andres-
Complete Vue js 2 Web Development Practical guide to
building end to end web development solutions with Vue
js 2 1st Edition Mike Street

https://textbookfull.com/product/complete-vue-js-2-web-
development-practical-guide-to-building-end-to-end-web-
development-solutions-with-vue-js-2-1st-edition-mike-street/

Front End Web Development The Big Nerd Ranch Guide 1st
Edition Chris Aquino

https://textbookfull.com/product/front-end-web-development-the-
big-nerd-ranch-guide-1st-edition-chris-aquino/

Full-Stack Web Development with Go: Build your web


applications quickly using the Go programming language
and Vue.js 1st Edition Nanik Tolaram

https://textbookfull.com/product/full-stack-web-development-with-
go-build-your-web-applications-quickly-using-the-go-programming-
language-and-vue-js-1st-edition-nanik-tolaram/

Learning React Native Building Native Mobile Apps with


JavaScript 2nd Edition Bonnie Eisenman

https://textbookfull.com/product/learning-react-native-building-
native-mobile-apps-with-javascript-2nd-edition-bonnie-eisenman/

Front End Tooling with Gulp Bower and Yeoman NOT true
pdf 1st Edition Stefan Baumgartner

https://textbookfull.com/product/front-end-tooling-with-gulp-
bower-and-yeoman-not-true-pdf-1st-edition-stefan-baumgartner/
Building
Native Web
Components
Front-End Development with Polymer
and Vue.js

Carlos Rojas
Building Native Web
Components
Front-End Development with
Polymer and Vue.js

Carlos Rojas
Building Native Web Components: Front-End Development with Polymer and Vue.js

Carlos Rojas
Medellin, Colombia

ISBN-13 (pbk): 978-1-4842-5904-7 ISBN-13 (electronic): 978-1-4842-5905-4


https://doi.org/10.1007/978-1-4842-5905-4

Copyright © 2021 by Carlos Rojas


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the
material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation,
broadcasting, reproduction on microfilms or in any other physical way, and transmission or information
storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now
known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with
every occurrence of a trademarked name, logo, or image, we use the names, logos, and images only in an
editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the
trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not
identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to
proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of publication,
neither the author nor the editors nor the publisher can accept any legal responsibility for any errors or
omissions that may be made. The publisher makes no warranty, express or implied, with respect to the
material contained herein.
Managing Director: Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Spandana Chatterjee
Development Editor: Rita Fernando
Coordinating Editor: Shrikant Vishwakarma
Cover designed by eStudioCalamar
Cover image designed by Pexels
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York Plaza, Suite
4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.
com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner)
is Springer Science+Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware
corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint,
paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and
licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales
web page at www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to
readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-5904-7. For more
detailed information, please visit www.apress.com/source-code.
Printed on acid-free paper
To my grandmothers, who always believed in me
Table of Contents
About the Author����������������������������������������������������������������������������������������������������� ix

About the Technical Reviewer��������������������������������������������������������������������������������� xi


Acknowledgments������������������������������������������������������������������������������������������������� xiii

Introduction�������������������������������������������������������������������������������������������������������������xv

Chapter 1: Making Your First Web Component��������������������������������������������������������� 1


What Are Web Components?��������������������������������������������������������������������������������������������������������� 1
History of Web Components���������������������������������������������������������������������������������������������������������� 2
Why Use Web Components?��������������������������������������������������������������������������������������������������������� 2
Legacy������������������������������������������������������������������������������������������������������������������������������������� 2
Framework Churn�������������������������������������������������������������������������������������������������������������������� 2
Basic Concepts of the Web Components Ecosystem�������������������������������������������������������������������� 3
Design Systems����������������������������������������������������������������������������������������������������������������������� 3
Component-Driven Development�������������������������������������������������������������������������������������������� 3
Browser Support for Web Components����������������������������������������������������������������������������������������� 4
Getting Started������������������������������������������������������������������������������������������������������������������������������ 5
cmder (Windows Only)������������������������������������������������������������������������������������������������������������ 5
Node.js������������������������������������������������������������������������������������������������������������������������������������� 7
npm����������������������������������������������������������������������������������������������������������������������������������������� 9
Google Chrome������������������������������������������������������������������������������������������������������������������������ 9
Chrome DevTools������������������������������������������������������������������������������������������������������������������� 10
Vue����������������������������������������������������������������������������������������������������������������������������������������� 12
Git������������������������������������������������������������������������������������������������������������������������������������������ 13
Firebase��������������������������������������������������������������������������������������������������������������������������������� 14
Visual Studio Code����������������������������������������������������������������������������������������������������������������� 16

v
Table of Contents

Developing Our First Web Component���������������������������������������������������������������������������������������� 16


Summary������������������������������������������������������������������������������������������������������������������������������������ 21

Chapter 2: Custom Elements���������������������������������������������������������������������������������� 23


What Are Custom Elements?������������������������������������������������������������������������������������������������������� 23
Custom Elements’ Life Cycle Hooks�������������������������������������������������������������������������������������������� 24
Building a Custom Element��������������������������������������������������������������������������������������������������������� 25
Summary������������������������������������������������������������������������������������������������������������������������������������ 30

Chapter 3: HTML Template�������������������������������������������������������������������������������������� 31


What Is an HTML Template?�������������������������������������������������������������������������������������������������������� 31
Slots�������������������������������������������������������������������������������������������������������������������������������������������� 33
Building a Web Component with <template>����������������������������������������������������������������������������� 34
Summary������������������������������������������������������������������������������������������������������������������������������������ 40

Chapter 4: Shadow DOM����������������������������������������������������������������������������������������� 41


What Is Shadow DOM?���������������������������������������������������������������������������������������������������������������� 41
Shadow Root������������������������������������������������������������������������������������������������������������������������� 43
Shadow Tree�������������������������������������������������������������������������������������������������������������������������� 43
Shadow Boundary����������������������������������������������������������������������������������������������������������������� 44
Shadow Host������������������������������������������������������������������������������������������������������������������������� 44
Building SocialShareComponent������������������������������������������������������������������������������������������������� 45
Summary������������������������������������������������������������������������������������������������������������������������������������ 51

Chapter 5: ES Modules�������������������������������������������������������������������������������������������� 53


What Are ES Modules?���������������������������������������������������������������������������������������������������������������� 53
Building the MathOperationsComponent������������������������������������������������������������������������������������ 55
Summary������������������������������������������������������������������������������������������������������������������������������������ 60

Chapter 6: Component Architecture����������������������������������������������������������������������� 61


Our NoteApp Application������������������������������������������������������������������������������������������������������������� 61
Communicating Between Web Components������������������������������������������������������������������������������� 63
NoteListComponent��������������������������������������������������������������������������������������������������������������������� 66
NoteListItemComponent������������������������������������������������������������������������������������������������������������� 69

vi
Table of Contents

SimpleFormModalComponent����������������������������������������������������������������������������������������������������� 74
Adding an API������������������������������������������������������������������������������������������������������������������������������ 84
Summary������������������������������������������������������������������������������������������������������������������������������������ 88

Chapter 7: Distributing Web Components��������������������������������������������������������������� 89


Publishing to npm����������������������������������������������������������������������������������������������������������������������� 89
Old Web Browsers Support��������������������������������������������������������������������������������������������������������� 94
Polyfills��������������������������������������������������������������������������������������������������������������������������������������� 98
Webpack and Babel�������������������������������������������������������������������������������������������������������������������� 99
Summary���������������������������������������������������������������������������������������������������������������������������������� 102

Chapter 8: Polymer����������������������������������������������������������������������������������������������� 103


Getting Started�������������������������������������������������������������������������������������������������������������������������� 103
LitElement��������������������������������������������������������������������������������������������������������������������������������� 106
Properties���������������������������������������������������������������������������������������������������������������������������� 106
Templates���������������������������������������������������������������������������������������������������������������������������� 107
Styles����������������������������������������������������������������������������������������������������������������������������������� 110
Events���������������������������������������������������������������������������������������������������������������������������������� 111
Life Cycle����������������������������������������������������������������������������������������������������������������������������� 112
Building with Polymer��������������������������������������������������������������������������������������������������������������� 114
Summary���������������������������������������������������������������������������������������������������������������������������������� 138

Chapter 9: Working with Vue.js���������������������������������������������������������������������������� 139


What Are the Major Features of Vue.js?������������������������������������������������������������������������������������ 139
What Are Components in Vue.js?���������������������������������������������������������������������������������������������� 140
What Are the Life Cycle Hooks in Vue Components?���������������������������������������������������������������� 142
beforeCreate������������������������������������������������������������������������������������������������������������������������ 143
created�������������������������������������������������������������������������������������������������������������������������������� 144
beforeMount������������������������������������������������������������������������������������������������������������������������ 144
mounted������������������������������������������������������������������������������������������������������������������������������ 144
beforeUpdate����������������������������������������������������������������������������������������������������������������������� 145
updated������������������������������������������������������������������������������������������������������������������������������� 145

vii
Table of Contents

beforeDestroy���������������������������������������������������������������������������������������������������������������������� 146
destroyed����������������������������������������������������������������������������������������������������������������������������� 146
Communicating Between Vue Components������������������������������������������������������������������������������ 146
What Are Props?������������������������������������������������������������������������������������������������������������������ 147
What Is a Ref Attribute?������������������������������������������������������������������������������������������������������� 148
Emitting an Event���������������������������������������������������������������������������������������������������������������� 148
Using Two-Way Data Binding����������������������������������������������������������������������������������������������� 149
Material Web Components��������������������������������������������������������������������������������������������������� 150
Building VueNoteApp����������������������������������������������������������������������������������������������������������������� 150
Creating a New Vue Project������������������������������������������������������������������������������������������������� 151
Adding Material Web Components�������������������������������������������������������������������������������������� 152
Adding a Header������������������������������������������������������������������������������������������������������������������ 160
Adding Vue Router��������������������������������������������������������������������������������������������������������������� 162
Deleting a Note�������������������������������������������������������������������������������������������������������������������� 168
Adding New Notes��������������������������������������������������������������������������������������������������������������� 172
Adding Firebase������������������������������������������������������������������������������������������������������������������� 180
Summary���������������������������������������������������������������������������������������������������������������������������������� 193

Chapter 10: Publishing����������������������������������������������������������������������������������������� 195


Adding Firebase Authentication������������������������������������������������������������������������������������������������ 195
Adding Guards��������������������������������������������������������������������������������������������������������������������� 206
Adding a User to Data���������������������������������������������������������������������������������������������������������� 211
Sending to Firebase Hosting���������������������������������������������������������������������������������������� 219
Summary���������������������������������������������������������������������������������������������������������������������� 221
Final Thoughts�������������������������������������������������������������������������������������������������������������� 221

Index��������������������������������������������������������������������������������������������������������������������� 223

viii
About the Author
Carlos Rojas is an engineer with more than ten years of
experience building digital products. He is focused on front-
end technologies (HTML, CSS, JS, Angular, React, Polymer,
and Vue.js) and cutting-edge web technologies, such as Web
Components, WebXR, and Progressive Web Apps. He also
has experience working with Fortune 500 companies and
fast-changing business environments, such as startups.
He enjoys sharing knowledge through talks at meetups,
videos on YouTube, other books published by Apress, his
personal blog (https://medium.com/@carlosrojas_o), and
helping startups and other companies run workflows to make excellent digital products.
As such, his books aim to convey his love for the construction of scalable, high-quality
products.

ix
About the Technical Reviewer
Yogendra Sharma is a developer with experience in
architecture, design, and development of scalable
and distributed applications, with a core interest in
microservices and Spring. Currently, he works as an IoT and
cloud architect at Intelizign Engineering Services Pvt, Pune.
Yogendra also has hands-on experience in such
technologies as AWS, IoT, Python, J2SE, J2EE, NodeJS, Vue.js,
Angular, MongoDB, and Docker. He is constantly exploring
technical novelties and is open-minded and eager to learn
about new technologies and frameworks. He has reviewed
several books and video courses published by Apress and Packt.

xi
Acknowledgments
To my friends, because they always found time to review my code and drafts; to my
colleagues, because they helped me a lot with their feedback; to Yogendra, because his
attention to detail made this book better; and to my editors, because their feedback and
reviews have made this book a high-quality guide.

xiii
Introduction
Web Components are everywhere in the current front-end environment. The three most
popular frameworks, Angular, React, and Vue.js, use Web Components as an architectural
element. In this book, you will learn how to empower a web app, building small pieces that
can be integrated into any modern JavaScript project and modified for future use, if your
company decides to migrate its current web app to a new and more promising framework.
In Chapter 1, you will create your first native web component. I am going to guide
you through all the steps that you require to create a placeholder component, using web
platform specifications.
Chapter 2 covers the CustomElement specification. You will learn to use it to create
custom tags on the Web and how its life cycle works.
Chapter 3 covers HTML templates. I will discuss the <template> and <slot>
elements and how to build a component with these.
In Chapter 4, you will learn the Shadow DOM specification, how to add it in native
Web Components, and what its benefits are.
Chapter 5 discusses ES modules specifications, how to create modules, and how to
use modules in our web applications.
In Chapter 6, you will learn how to design components and make them work
together in a web application. We will connect our web application to an API and define
a dataflow for our components.
In Chapter 7, you will learn how to make our Web Components available in npm. You
also will learn about browser support for Web Components APIS, how to add polyfills to
support more web browsers, and how to add Webpack and Babel to process and prepare
our Web Components for publication.
Chapter 8 covers how to build Web Components with Polymer, why Polymer is used
instead of VanillaJS, how to use LitElement in our Web Components, and how to use
lit-html.
In Chapter 9, we will develop an app. You will learn some key concepts and
understand how to integrate Web Components and Vue.js.
In Chapter 10, you will see how Firebase hosting and Firebase authentication are
used to release our final web app to the world.

xv
CHAPTER 1

Making Your First


Web Component
Welcome to building your first web component. This chapter discusses the various
tools, technologies, designs, and development concepts that you will require to create
your first web component. You will learn what a web component is, as well as what web
browser support, design systems, and component-driven development (CDD) are.

What Are Web Components?


At a high level, Web Components are isolated pieces (kinds of blocks) with which a user
interface (UI) can communicate with other elements, through properties and events
(inputs and outputs from these blocks). Take the <video> element, for example. We can
use this element with any technologies in a browser, and we can pass such properties as
width and height and listen for events such as onclick.
In stricter terms, we can say that Web Components are a set of web platform APIs
(application programming interfaces) that allow us to build HTML tags that will work
across modern web browsers and can be used with any JavaScript technology (React,
Angular, Vue.js, etc.).
Web Components have four main specifications:

• Custom elements

• Shadow DOM

• ES modules
• HTML templates

I will cover these specifications in greater depth in the next chapters.

1
© Carlos Rojas 2021
C. Rojas, Building Native Web Components, https://doi.org/10.1007/978-1-4842-5905-4_1
Chapter 1 Making Your First Web Component

History of Web Components


Currently, Web Components are everywhere in the front-end environment. The three
most popular frameworks (Angular, React, and Vue.js) use Web Components as part
of their architecture. It was not always so. Web Components were developed little
by little over time. The first significant progress was achieved in 2010 with AngularJS
(https://angularjs.org), which was a framework that introduced the concept
of directives as a way to create your own tags, with their own features to build UIs.
Later, in 2011, Alex Russell delivered a speech at a Fronteers Conference, titled “Web
Components and Model Driven Views,” that set out some key concepts and ideas that
are now commonly used.1 In 2013, Google took another big step forward with Polymer,
a library based on Web Components (using web APIs) that has become a tool for
building libraries, tools, and standards for a better Web.

Why Use Web Components?


Today, all front-end developers face two significant problems that can be a drain on
companies’ energy, time, and finances. These are as follows.

L egacy
Legacy, a well-known problem in software development, refers to an old code base
that must be updated at some point, in order to operate with new JavaScript projects
and tools.

F ramework Churn
JavaScript’s tools and its frameworks ecosystem are changing rapidly. It can be stressful
and exhausting to choose the correct framework for a new project, because we can’t
guess for how long the framework will be relevant. This problem of relevance and how it
affects investment in training and development for a set of tools that can quickly become
obsolete is called framework churn.

1
 lex Russell, “Web Components and Model Driven Views,” Fronteers https://fronteers.nl/
A
congres/2011/sessions/web-components-and-model-driven-views-alex-russell, Accessed
September 28, 2020.

2
Chapter 1 Making Your First Web Component

Remember that Web Components are a set of web platform specifications. Therefore,
they are something likely to be used in web browsers for a long time and offer many
benefits, including the following:

• Web Components are reusable and work between frameworks.

• Web Components can run in all major web browsers.

• Web Components are easily maintainable and are prepared for the
future, mainly because they are based in web platform specifications.

Basic Concepts of the Web Components Ecosystem


Throughout this book, I will be using several terms that are related to techniques,
methodologies, or patterns that we can apply when using Web Components in our web
apps. These are as follows.

D
 esign Systems
Design systems are catalogs or collections of reusable components, guidelines, and tools
that allow teams in organizations to build digital products to work more efficiently and
apply consistent branding for all their products. Some examples with this approach are
as follows:

• Google: Material Design (https://material.io)

• Adobe: Spectrum (https://spectrum.adobe.com)


• Ionic: Ionic Framework (https://ionicframework.com/docs)

C
 omponent-Driven Development
Component-driven development means designing your software applications by
building independent components. Each component has an interface or API to
communicate with the rest of the system. Some advantages of using this approach are
• Faster development: Separating development into components allows
you to build modular parts with small scopes and small objectives.
This means that you can develop faster and make a piece for testing
available more quickly for reuse in some other system.

3
Chapter 1 Making Your First Web Component

• More straightforward maintenance: When you must add or update


the functionality of your application, you only have to update the
component, instead of having to refactor more significant parts of
your application.

• Reusability: Modular components allow for reusable functionality


and can be extended to build multiple applications, eliminating the
need to rewrite them over and over again.

• Test-driven development (TDD): Implementing unit tests to validate


the focused functionality of each modular component becomes
much easier.

• A better understanding of the system: When a system is composed of


modular components, it becomes easier to grasp, understand, and
operate.

Browser Support for Web Components


At the time of writing (early 2020), Web Components are supported by all major web
browsers (see Figure 1-1).

Figure 1-1. Major browsers supporting the main specifications of Web


Components

4
Chapter 1 Making Your First Web Component

G
 etting Started
To start to build apps with Web Components, you must understand and install several
technologies and tools.

cmder (Windows Only)


cmder is a terminal emulator for Windows. By default, Windows operating systems come
with a terminal (command prompt) that is not useful for development. That is why
we need cmder, which is an emulator we can use to run commands smoothly in our
terminal.
To access this emulator, go to cmder.net and download the latest version.
Extract the file in your C:/ location.
Go to System Properties ➤ Environment Variables and edit Path Variable, as in
Figure 1-2.

Figure 1-2. Environment Variables preferences in System Properties

Add the cmder location to the Path variable, as in Figure 1-3.

5
Chapter 1 Making Your First Web Component

Figure 1-18. Placeholder component

The basic usage of this component in our HTML is as in Listing 1-3.

Listing 1-3. Using vanilla-placeholder-component

<vanilla-placeholder-content></vanilla-placeholder-content>

We can add some attributes, as in Listing 1-4.

Listing 1-4. Using vanilla-placeholder-component with Attributes

<vanilla-placeholder-content height="100px" width="50px">


</vanilla-­placeholder-­content>

Our component accepts height and width properties to customize the size, but if we
don’t provide that info, we are going to assign 100px by default for both.
First we must create a file index.html and fill it with a basic structure, as shown in
Listing 1-5.

Listing 1-5. index.html—Basic Structure

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

17
Another random document with
no related content on Scribd:
CENTENARY EDITION

The Positive Outcome of Philosophy


By Josef Dietzgen

One of the best books we have ever published is THE POSITIVE


OUTCOME OF PHILOSOPHY. We have sold many thousands of
Josef Dietzgen’s books, and readers everywhere have testified to
their educational value and to the enjoyment and enlightenment they
obtained from the study of Dietzgen.
December 9th, 1928, was the hundredth anniversary of the birth of
Josef Dietzgen. To commemorate the event we published, with the
kind assistance of his son, Eugen Dietzgen, a new translation of
THE POSITIVE OUTCOME OF PHILOSOPHY. This new translation
from the original German is by W. W. Craik, an Englishman, resident
of Hamburg.
Good as our former edition was, we do not hesitate to assert that
this translation is immensely superior. It is in clear and expressive
English, which simplifies the study. Craik has certainly done his work
well.
To those who have formerly read the philosophy of Josef Dietzgen,
it is not necessary to comment upon its merits, but to those who
have not yet participated in this pleasure we wish to give here a brief
outline of its content.
It deals with the nature and substance of thinking. It strips the
human mind of the mysticism that is usually attached to it, and
shows the functioning of the brain as a perfectly natural process.
Just as Karl Marx and Frederick Engels traced history and
economics along evolutionary lines, to the logical conclusion that a
new social order is inevitable, so Josef Dietzgen traced the evolution
of human thought, as expressed through philosophy, to its positive
outcome. He shows that the natural sciences have taken over every
branch of the old-time philosophy, leaving only the thinking process
itself to be explained. This latter he accomplishes in a masterly
fashion in his chapter on “The Nature of Human Brain-Work.”
The Centenary Edition of THE POSITIVE OUTCOME OF
PHILOSOPHY is handsomely bound in maroon cloth with gold
stamping and contains a portrait of its famous author. Price $2.00,
postage paid.

CHARLES H. KERR & COMPANY


341 East Ohio Street, Chicago
ANTI-DÜHRING
Herr Eugene Dühring’s
Revolution in Science

By Frederick Engels
Also contains “The Mark” and the author’s introduction to “Socialism, Utopian and Scientific”

Part I treats with Philosophy, giving the most comprehensive


statement of Marx and Engels with regard to this question than
anywhere else in their published writings. Part II is, in effect, an
outline and introduction to the three volumes of Capital, along with
interesting data on the force theory and warfare and militarism. Part
III explains the basis of modern socialism in its entire range of
program, strategy and tactics.
Anti-Dühring is the only work compressing into one volume the
Marxian world-outlook in its relation to the various fields of
knowledge and science and the society of the future. Engels says of
this work: “I had to treat of all and every possible subject, from the
concepts of time and space to bimetallism; from the eternity of
matter and motion to the perishable nature of moral ideas; from
Darwin’s natural selection to the education of youth in a future
society. Anyhow, the systematic comprehensiveness of my opponent
gave me the opportunity of developing, in opposition to him, and in a
more connected form than had previously been done, the views held
by Marx and myself on this great variety of subjects. And that was
the principal reason which made me undertake this otherwise
ungrateful task.”
Price, postpaid, $2.00

Write for complete list


CHARLES H. KERR & COMPANY
341–349 E. Ohio St. Chicago, Illinois

Transcriber’s Notes:
Punctuation and spelling inaccuracies were silently
corrected.
Archaic and variable spelling has been preserved.
Variations in hyphenation and compound words have been
preserved.
*** END OF THE PROJECT GUTENBERG EBOOK MARXISM AND
DARWINISM ***

Updated editions will replace the previous one—the old editions


will be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright
in these works, so the Foundation (and you!) can copy and
distribute it in the United States without permission and without
paying copyright royalties. Special rules, set forth in the General
Terms of Use part of this license, apply to copying and
distributing Project Gutenberg™ electronic works to protect the
PROJECT GUTENBERG™ concept and trademark. Project
Gutenberg is a registered trademark, and may not be used if
you charge for an eBook, except by following the terms of the
trademark license, including paying royalties for use of the
Project Gutenberg trademark. If you do not charge anything for
copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such
as creation of derivative works, reports, performances and
research. Project Gutenberg eBooks may be modified and
printed and given away—you may do practically ANYTHING in
the United States with eBooks not protected by U.S. copyright
law. Redistribution is subject to the trademark license, especially
commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the


free distribution of electronic works, by using or distributing this
work (or any other work associated in any way with the phrase
“Project Gutenberg”), you agree to comply with all the terms of
the Full Project Gutenberg™ License available with this file or
online at www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand,
agree to and accept all the terms of this license and intellectual
property (trademark/copyright) agreement. If you do not agree to
abide by all the terms of this agreement, you must cease using
and return or destroy all copies of Project Gutenberg™
electronic works in your possession. If you paid a fee for
obtaining a copy of or access to a Project Gutenberg™
electronic work and you do not agree to be bound by the terms
of this agreement, you may obtain a refund from the person or
entity to whom you paid the fee as set forth in paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only


be used on or associated in any way with an electronic work by
people who agree to be bound by the terms of this agreement.
There are a few things that you can do with most Project
Gutenberg™ electronic works even without complying with the
full terms of this agreement. See paragraph 1.C below. There
are a lot of things you can do with Project Gutenberg™
electronic works if you follow the terms of this agreement and
help preserve free future access to Project Gutenberg™
electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright
law in the United States and you are located in the United
States, we do not claim a right to prevent you from copying,
distributing, performing, displaying or creating derivative works
based on the work as long as all references to Project
Gutenberg are removed. Of course, we hope that you will
support the Project Gutenberg™ mission of promoting free
access to electronic works by freely sharing Project
Gutenberg™ works in compliance with the terms of this
agreement for keeping the Project Gutenberg™ name
associated with the work. You can easily comply with the terms
of this agreement by keeping this work in the same format with
its attached full Project Gutenberg™ License when you share it
without charge with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.

1.E. Unless you have removed all references to Project


Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project
Gutenberg™ work (any work on which the phrase “Project
Gutenberg” appears, or with which the phrase “Project
Gutenberg” is associated) is accessed, displayed, performed,
viewed, copied or distributed:

This eBook is for the use of anyone anywhere in the United


States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it
away or re-use it under the terms of the Project Gutenberg
License included with this eBook or online at
www.gutenberg.org. If you are not located in the United
States, you will have to check the laws of the country where
you are located before using this eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is


derived from texts not protected by U.S. copyright law (does not
contain a notice indicating that it is posted with permission of the
copyright holder), the work can be copied and distributed to
anyone in the United States without paying any fees or charges.
If you are redistributing or providing access to a work with the
phrase “Project Gutenberg” associated with or appearing on the
work, you must comply either with the requirements of
paragraphs 1.E.1 through 1.E.7 or obtain permission for the use
of the work and the Project Gutenberg™ trademark as set forth
in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is


posted with the permission of the copyright holder, your use and
distribution must comply with both paragraphs 1.E.1 through
1.E.7 and any additional terms imposed by the copyright holder.
Additional terms will be linked to the Project Gutenberg™
License for all works posted with the permission of the copyright
holder found at the beginning of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files
containing a part of this work or any other work associated with
Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute
this electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the
Project Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must, at
no additional cost, fee or expense to the user, provide a copy, a
means of exporting a copy, or a means of obtaining a copy upon
request, of the work in its original “Plain Vanilla ASCII” or other
form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™
works unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or


providing access to or distributing Project Gutenberg™
electronic works provided that:

• You pay a royalty fee of 20% of the gross profits you derive from
the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt that
s/he does not agree to the terms of the full Project Gutenberg™
License. You must require such a user to return or destroy all
copies of the works possessed in a physical medium and
discontinue all use of and all access to other copies of Project
Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project


Gutenberg™ electronic work or group of works on different
terms than are set forth in this agreement, you must obtain
permission in writing from the Project Gutenberg Literary
Archive Foundation, the manager of the Project Gutenberg™
trademark. Contact the Foundation as set forth in Section 3
below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on,
transcribe and proofread works not protected by U.S. copyright
law in creating the Project Gutenberg™ collection. Despite
these efforts, Project Gutenberg™ electronic works, and the
medium on which they may be stored, may contain “Defects,”
such as, but not limited to, incomplete, inaccurate or corrupt
data, transcription errors, a copyright or other intellectual
property infringement, a defective or damaged disk or other
medium, a computer virus, or computer codes that damage or
cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES -


Except for the “Right of Replacement or Refund” described in
paragraph 1.F.3, the Project Gutenberg Literary Archive
Foundation, the owner of the Project Gutenberg™ trademark,
and any other party distributing a Project Gutenberg™ electronic
work under this agreement, disclaim all liability to you for
damages, costs and expenses, including legal fees. YOU
AGREE THAT YOU HAVE NO REMEDIES FOR NEGLIGENCE,
STRICT LIABILITY, BREACH OF WARRANTY OR BREACH
OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE
TRADEMARK OWNER, AND ANY DISTRIBUTOR UNDER
THIS AGREEMENT WILL NOT BE LIABLE TO YOU FOR
ACTUAL, DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE
OR INCIDENTAL DAMAGES EVEN IF YOU GIVE NOTICE OF
THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If


you discover a defect in this electronic work within 90 days of
receiving it, you can receive a refund of the money (if any) you
paid for it by sending a written explanation to the person you
received the work from. If you received the work on a physical
medium, you must return the medium with your written
explanation. The person or entity that provided you with the
defective work may elect to provide a replacement copy in lieu
of a refund. If you received the work electronically, the person or
entity providing it to you may choose to give you a second
opportunity to receive the work electronically in lieu of a refund.
If the second copy is also defective, you may demand a refund
in writing without further opportunities to fix the problem.

1.F.4. Except for the limited right of replacement or refund set


forth in paragraph 1.F.3, this work is provided to you ‘AS-IS’,
WITH NO OTHER WARRANTIES OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO
WARRANTIES OF MERCHANTABILITY OR FITNESS FOR
ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of
damages. If any disclaimer or limitation set forth in this
agreement violates the law of the state applicable to this
agreement, the agreement shall be interpreted to make the
maximum disclaimer or limitation permitted by the applicable
state law. The invalidity or unenforceability of any provision of
this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the


Foundation, the trademark owner, any agent or employee of the
Foundation, anyone providing copies of Project Gutenberg™
electronic works in accordance with this agreement, and any
volunteers associated with the production, promotion and
distribution of Project Gutenberg™ electronic works, harmless
from all liability, costs and expenses, including legal fees, that
arise directly or indirectly from any of the following which you do
or cause to occur: (a) distribution of this or any Project
Gutenberg™ work, (b) alteration, modification, or additions or
deletions to any Project Gutenberg™ work, and (c) any Defect
you cause.

Section 2. Information about the Mission of


Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new
computers. It exists because of the efforts of hundreds of
volunteers and donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project
Gutenberg™’s goals and ensuring that the Project Gutenberg™
collection will remain freely available for generations to come. In
2001, the Project Gutenberg Literary Archive Foundation was
created to provide a secure and permanent future for Project
Gutenberg™ and future generations. To learn more about the
Project Gutenberg Literary Archive Foundation and how your
efforts and donations can help, see Sections 3 and 4 and the
Foundation information page at www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-
profit 501(c)(3) educational corporation organized under the
laws of the state of Mississippi and granted tax exempt status by
the Internal Revenue Service. The Foundation’s EIN or federal
tax identification number is 64-6221541. Contributions to the
Project Gutenberg Literary Archive Foundation are tax
deductible to the full extent permitted by U.S. federal laws and
your state’s laws.

The Foundation’s business office is located at 809 North 1500


West, Salt Lake City, UT 84116, (801) 596-1887. Email contact
links and up to date contact information can be found at the
Foundation’s website and official page at
www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or
determine the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About Project


Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.

You might also like