92775424
92775424
com
OR CLICK HERE
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
(Ebook) Fullstack Node.js: The Complete Guide to Building
Production Apps with Node.js by Davit Guttman; Nate Murray
(ed) ISBN 08671X
https://ebooknice.com/product/fullstack-node-js-the-complete-guide-to-
building-production-apps-with-node-js-11798290
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
Fullstack Web Components
The Complete Guide to Building UI Libraries
and Web Applications with Web Components
Nate Murray
* * * * *
* * * * *
Book Revision
Join Our Discord
Bug Reports
Be notified of updates via Twitter
We’d love to hear from you!
Introduction
Foreword
About the author
Web Components
About this book
Who is this book for
Introduction to Web Components
What are Web Components?
The many uses of Web Components
Implementing a design system with Web Components
Conventions used in this Book
Storybook
Application
Cypress
Storyshots
Monorepo
Setting up the development environment
Prerequisites
Summary
Part One
Part One
Specification
What you will learn
Developing in Part One
Part Two
Part Two
UI Library
What you will learn
Developing in Part Two
Micro-library
Chapter Four
Introduction
What is a micro-library?
Coding in a monorepo
What you will build
What you will learn
Acceptance criteria
Getting started
Class Decorator
Method Decorator
Define the Listen decorator
Refactor TextInputComponent
Summary
Compound Custom Elements
Chapter Five
Component Communication
What you will build
What you will learn
Acceptance criteria
Getting started
Mocking Table Data in Storybook
Coding Compound Components
Attribute Drilling
BroadcastChannel
Rendering Columns and Rows
Styling TableComponent
Handling CRUD Events with BroadcastChannel
Making the Table Editable
Testing the Table
Summary
Part Three
Part Three
Application
What you will learn
Developing in Part Three
Changelog
Revision 1 (04-04-2022)
Revision 2 (12-06-2022)
Book Revision
Revision 1 - Initial pre-release of the book - 04-04-2022
Bug Reports
If you’d like to report any bugs, typos, or suggestions just email us
at: [email protected].
Foreword
This is a book about Web Components. UI components are a
common pattern in many front end web development frameworks
like Angular, React or Vue, but coding user interfaces in the context
of a framework usually makes sharing those components difficult.
Angular components can’t be easily loaded in the context of React,
for instance. The framework is a closed system.
If you can move past the framework, and possibly enjoy the
simplification and standardization offered by web specifications,
coding with Web Components can be quite rewarding. Working
directly with specifications opens up a world once obscured by the
framework. The web platform is yours to explore and find interesting
ways to utilize parts of HTML, CSS, and JavaScript. By using web
specifications to code UI components you can achieve extraordinary
results. When used responsibly, adopting Web Components as your
UI component pattern can lead to stellar performance, compliance
with accessibility standards, and reusability.
Web Components
Before the set of technologies known as Web Components were
available engineers had to select an opinionated JavaScript
framework to abstract user interfaces into “components”. Web
Components are interoperable with virtually any JavaScript library or
framework because they are developed using only browser
specifications. The lifespan of a user interface component built with
Web Components can be much greater than a component built with
a library since browser specifications exist for a very long time. Web
Components can have dynamic templates, handle complex form
behaviors, even inherit characteristics of familiar HTML elements like
<button> or <table>. By coding a UI library with Web Components,
you can ensure the components have a farther reach than
components only compatible with a specific library or framework.
Depending on implementation, components coded with Web
Components specifications can out perform framework-based
components as well, due to the lack of dependencies and overhead
inherit in JavaScript frameworks.
Custom elements
CustomElementRegistry
Shadow DOM
HTML Template
When Shadow DOM was introduced, the only way to style a custom
element’s ShadowRoot from the context of Light DOM was to use CSS
variables. CSS variables were the only method that pierced the
Shadow boundary.
CSS Shadow Parts is a CSS pseudo selector ::part that allows styling
of any elements within a Shadow DOM tree that has a matching part
attribute. ::part is available in all evergreen browsers. WHATWG is
currently working on new specifications that enable greater flexibility
when styling Shadow DOM including a specification known as
Constructable Stylesheets.
Declarative Shadow DOM
Standalone widgets
So far I’ve talked about how Web Components behave and where
you might find custom elements. In the next sections, I further
define Web Components through the HTML specification, then talk
about how custom elements can be viewed through the lens of a
design system, followed by a guide for getting started developing
with the repository that accompanies this book.
UI Library
Tokens
Components
Layouts
Figma
Similarly, CSS variables for sizing, border radius, font, icons and box
shadow are provided on the global stylesheet found in
src/style/style.css. You may reference these CSS variables when
styling each UI component.
Storybook
The main development environment for a considerable portion of
this book is Storybook, “an open source tool for building UI
components and pages in isolation.”
Storybook is run locally on your computer. In several chapters, you’ll
define Stories for the UI component you’re coding. A Story is a
configurable template that hosts your component. Through the
Storybook user interface, you can define different controls that
change UI component behavior. By the end of this book you should
have a good understanding of how to develop and maintain UI
components in Storybook.
Application
In the third part of this book, you transition from developing user
interface components to developing with those components in the
context of a web application. When developing the application, you’ll
change up the local environment to a custom Webpack server and
only use Storybook when necessary.
The application you’re going to develop is called “In”, a web app
used to store a user’s contact list. After the user authenticates with a
login form, a user interface displays a table filled with contacts. The
user can view or edit the contact list. User interfaces found in the
application are developed in Storybook first, exported from a UI
library package, then imported into the application source code.
Cypress
Cypress is a test runner you’ll use to write end-to-end tests for each
UI component.
Storyshots
Storyshots is a Storybook addon you’ll use to generate automatic
visual snapshots for each UI component.
Monorepo
When developing against the content in this book, you’ll be working
in a monorepo built with lerna. Lerna allows you to manage multiple
projects in the same repository. Those projects are defined as:
Naming
Prerequisites
The following tools should be installed prior to starting development.
Terminal application
Which Terminal you use depends on your system. MacOS and Linux
systems come with the Terminal application. For Windows 10 and
above, all Terminal commands featured in this book should be run
with PowerShell and Windows Subsystem for Linux. Follow these
instructions to install Windows Subsystem for Linux. Running node
scripts in Windows Subsystem for Linux ensures the commands will
work.
git
Changes to the codebase are tracked via git. git is a version control
system that allows projects like this one to track changes across the
codebase effectively. If you have little or no experience with git,
don’t worry. Each chapter clearly demonstrates the git commands
you’ll need to run to navigate between changes. git is installed
differently depending on your system.
Mac
Windows
Linux
NodeJS
JavaScript IDE
Once you have all of the above tools installed on your system, you’re
ready to clone the git repository, install project dependencies, and
run the development server.
GitHub
The repository for this book is found on GitHub. If you don’t already
have a GitHub account, signup for a new account. If you’ve never
used GitHub before on your machine, you’ll need to setup your
username locally. More information about setting up GitHub locally is
found in the Set up Git Guide.
After you’ve properly setup git locally, fork the repository on Github,
then clone your fork of the repository via the Terminal, making sure
you run the command in a directory where code is usually stored on
your system. If you don’t already have any code projects on your
computer, make a new directory to store this book’s codebase, then
run the following command, inserting your Github username in lieu
of {username}.
1 git clone https://github.com/{username}/fullstack-web-com\
2 ponents.git
There are times you may need to update your local repository from
the upstream repository, mainly to uptake dependency upgrades or
new content. Further instructions for maintaining your local fork of
the repository are found in the README.md.
Yarn
This repository uses yarn to install npm dependencies and run node
scripts.
1 npm install --global yarn
Once yarn is installed you can install project dependencies with the
yarn command.
1 yarn
Storybook
After project dependencies are installed with yarn, run the storybook
script to start up the local Storybook development environment.
1 yarn storybook
Summary
Through the practical exercises in this book, you’ll learn how to code
user interfaces that are interoperable, reusable, accessible, portable
and require zero dependencies. The goal is to mirror best practices
at enterprise corporations that you can bring into your own
professional development.
Part One Specification
In the first part of this book, you’re going to take a deep dive into
the Web Components specification by developing the UI components
that comprise a login form. Through developing with the different
types of custom elements and several other parts of the Web
Components specification, you’ll learn:
In the final chapter of this book, we’ll summarize what was learned
and look to the future of Web Component development.
Specification
In Part One of this book we’ll explore several Web Components
specifications by developing the UI components that make up a login
form. This login user interface will be used in Part Three so users
can authenticate with the application.
Introduction
You can make completely customized HTML elements with
autonomous custom elements, so it can be daunting to know where
to start. In this exercise, autonomous custom elements are
highlighted for what they do best: provide a means to bind template
encapsulation provided by Shadow DOM with a unique HTML tag
and then reuse the custom element throughout DOM.
Acceptance criteria
A class called CardComponent is exported from
packages/component/src/card/Card.ts
CardComponent can accept dynamic images, paragraphs, links,
and headlines in the template
CardComponent is styled per the mockup in Figma
CardComponent is configurable via Storybook Controls
Integration tests are found in cypress/integration/Card.spec.js
Snapshot tests validate the design implementation of
CardComponent
Getting started
Navigate to the project directory. The default name of the directory
is fullstack-web-components from when you cloned the git
repository.
1 cd fullstack-web-components
Run Storybook:
1 yarn storybook
Scaffolding CardComponent
In this first section, you’ll code an autonomous custom element from
scratch. You’ll use Storybook as a development environment. If you
haven’t already, navigate to the project directory and run yarn
storybook. Have no fear if you’ve never coded a custom element
before because this book walks you through each exercise step by
step.
1 touch packages/component/src/card/Card.ts
If you haven’t already, now is a good time to open the new Card.js
file in your favorite IDE.
Following the call to super(), define the template for the Card.
Instantiate a Shadow DOM template for this component by creating
a const called shadowRoot and making it equal to
this.attachShadow({ mode: 'open' }).
Now that we’ve established this custom element should use Shadow
DOM, let’s give it a template using HTMLTemplateElement. In the
constructor, following the shadowRoot, add the following lines of
code:
1 const template = document.createElement('template');
2 template.innerHTML = `
3 <span>Hello World</span>
4 `;
5 shadowRoot.appendChild(template.content.cloneNode(tru\
6 e));
HTML templates are reusable DOM trees that are not parsed until
they are instantiated. In this case, the HTML template will be
instantiated when an instance of the Card component is rendered
and a clone of the template node is appended tp the Shadow Root
appendChild exists on the Shadow Root, which behaves similarly to
any other DOM node.
Finally, establish the tag name for the custom element by registering
the class you just defined with the CustomElementRegistry.
1 customElements.define('in-card', CardComponent);
This last step is significant because without it, the browser can’t
interpret CardComponent as the class associated with the HTML tag
<in-card>. We prefixed the tag name with in- because that is the
name of the application we’re coding: In. The tag name for custom
elements is limited to kebab case and can contain at least one dash.
Prefixing the component differentiates it from components from
other design systems that may exist on the same website, so
naming the components is something we want to get right fairly
early on.
1 touch packages/component/src/card/Card.stories.js
"Ettekö nyt ymmärrä?" sanoi hän äkkiä. "Ettekö nyt voi käsittää
sitä, millaisen epäluulon alaiseksi hän on saattanut itsensä, koska
herra Charles Sperrigoe ei tunne häntä?"
"En ole niinkään varma siitä", sanoin yhtä nopeasti. "Olen joka
tapauksessa aivan varma, että Parslewe tuntee tahi on ainakin
tuntenut Sperrigoen kerran maailmassa. Teen tämän varman
päätelmäni eräästä huomautuksesta, jonka hän teki kertoessani
hänelle Sperrigoesta."
"En tiedä oikein, mikä olen, kultaseni", vastasi hän käyden jälleen
lempeämmäksi, "mutta toivon saavani sen selville piakkoin. Ja sitä
odottaessamme eläkäämme mukavasti, koska tuolla tuodaan jo
meille ruokaa ja juomaa."
"Niin, kaikki", toisti Madrasia, "paitsi se, minkä nyt toistan tarkasti
Murthwaiten sanoilla. Sinun on palattava Wooleriin, puhuteltava
häntä
ja kerrottava hänelle kaikki, että hän voisi täyttää herra Charles
Sperrigoelle antamansa lupauksen. Ja parasta kai se onkin."
"Ja kaikki tuo merkitsee, että sinä tiedät paljon enemmän asiasta,
kuin olet meille ilmaissut!" huudahti Madrasia.
PELTISEPÄN ARKIHUONE
"Kyllä."
"Millainen edellytys?"
"Siinä tapauksessa, ettei hän palaa hotelliin ennen puoltayötä, piti
minun tuoda teille tämä kirje häneltä", vastasin laskien kirjeen
pulpetille. "Hän ei tullut, ja sen vuoksi tulin suoraan luoksenne."
Hän otti kirjeen, aukaisi sen ja alkoi lukea. Paikaltani voin nähdä,
että kirjoitus täytti kolme sivua hotellin postipaperiarkista. Miehen
kasvot eivät hänen lukiessaan ilmaisseet mitään — eivät
hämmästystä, neuvottomuutta eivätkä kummastusta — ja hän luki
kirjeen vain kerran läpi. Sitten hän taittoi sen kokoon, pisti
pulpettiinsa ja kääntyi puoleeni.
"Kyllä", vastasin.
"Kyllä. Otin selon siitä. Hän oli poistunut noin yhdentoista aikaan
— muutamia minuutteja ennen. Sain sen tietää ovenvartijalta."
"Kerron teille tarkasti, mitä hän sanoi", vastasin. "Hän sanoi: 'Ei
niin paljon vaaraa kuin vaikeuksia, vaikka en tahdo kieltää sitäkään,
että voin ehkä joutua vaaraankin.' Niin juuri hän sanoi."
"En ollenkaan!"
"No niin, koska hän on luvannut teidän tulla mukaamme, voin sen
vallan hyvin kertoakin teille", sanoi hän nauraen jälleen. "Olemme
menossa erään Bickerdale-nimisen läkki- ja kuparisepän taloon ja
työpajaan, jotka sijaitsevat erään sivukadun varrella tässä
läheisyydessä. Sinne juuri on herra Parslewe mennyt."
Minun olisi tietysti pitänyt arvata se. Tunsin itseni hyvin tyhmäksi,
kun en ollut osannut ajatella sitä ennen. Mutta säpsähdin kuitenkin
tahtomattani.
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.
ebooknice.com