100% found this document useful (2 votes)
915 views

Full download (Ebook) Getting Started with Meteor.js JavaScript Framework, 2nd Edition: Learn to develop powerful web applications in minutes with Meteor by Isaac Strack ISBN 9781785285547, 1785285548 pdf docx

The document promotes the ebook 'Getting Started with Meteor.js JavaScript Framework, 2nd Edition' by Isaac Strack, which teaches readers how to develop web applications quickly using the Meteor framework. It includes links to download the ebook and additional related titles. The book covers various topics including setup, reactive programming, templates, and data handling in Meteor.

Uploaded by

memarxhone
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
915 views

Full download (Ebook) Getting Started with Meteor.js JavaScript Framework, 2nd Edition: Learn to develop powerful web applications in minutes with Meteor by Isaac Strack ISBN 9781785285547, 1785285548 pdf docx

The document promotes the ebook 'Getting Started with Meteor.js JavaScript Framework, 2nd Edition' by Isaac Strack, which teaches readers how to develop web applications quickly using the Meteor framework. It includes links to download the ebook and additional related titles. The book covers various topics including setup, reactive programming, templates, and data handling in Meteor.

Uploaded by

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

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Getting Started with Meteor.js JavaScript


Framework, 2nd Edition: Learn to develop powerful
web applications in minutes with Meteor by Isaac
Strack ISBN 9781785285547, 1785285548
_____ Click the link below to download _____
https://ebooknice.com/product/getting-started-with-
meteor-js-javascript-framework-2nd-edition-learn-to-
develop-powerful-web-applications-in-minutes-with-
meteor-5475694

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) Meteor Cookbook by Strack, Isaac ISBN 9781783280292,


1783280298

https://ebooknice.com/product/meteor-cookbook-55893630

ebooknice.com

(Ebook) Getting Started with MariaDB, 2nd Edition: Explore the


powerful features of MariaDB with practical examples by Daniel
Bartholomew ISBN 9781785284120, 1785284126

https://ebooknice.com/product/getting-started-with-mariadb-2nd-
edition-explore-the-powerful-features-of-mariadb-with-practical-
examples-5475706
ebooknice.com

(Ebook) Getting Started with Varnish Cache: Accelerate Your Web


Applications by Thijs Feryn ISBN 9781491972229, 149197222X

https://ebooknice.com/product/getting-started-with-varnish-cache-
accelerate-your-web-applications-6778218

ebooknice.com

(Ebook) Getting started with Deep Learning for Natural Language


Processing: Learn how to build NLP applications with Deep Learning by
Sunil Patel ISBN 9789389898118, 9389898110

https://ebooknice.com/product/getting-started-with-deep-learning-for-
natural-language-processing-learn-how-to-build-nlp-applications-with-
deep-learning-36407330
ebooknice.com
(Ebook) Building Modern Web Applications with ASP.NET Core Blazor:
Learn how to use Blazor to create powerful, responsive, and engaging
web applications by Brian Ding ISBN 9789355518798, 935551879X

https://ebooknice.com/product/building-modern-web-applications-with-
asp-net-core-blazor-learn-how-to-use-blazor-to-create-powerful-
responsive-and-engaging-web-applications-52198310
ebooknice.com

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) Mastering Ext JS, 2nd Edition: Learn how to develop advanced
and efficient Internet applications with Ext JS by Loiane Groner ISBN
9781784390457, 1784390453

https://ebooknice.com/product/mastering-ext-js-2nd-edition-learn-how-
to-develop-advanced-and-efficient-internet-applications-with-ext-
js-5470758
ebooknice.com

(Ebook) Getting Started with the Web by Shelley Powers ISBN


9781491922323, 149192232X

https://ebooknice.com/product/getting-started-with-the-web-33350162

ebooknice.com

(Ebook) Getting Started with BeagleBone: Linux-Powered Electronic


Projects With Python and JavaScript by Matt Richardson ISBN
9781449345372, 1449345379

https://ebooknice.com/product/getting-started-with-beaglebone-linux-
powered-electronic-projects-with-python-and-javascript-5060292

ebooknice.com
Getting Started with Meteor js JavaScript Framework
2nd Edition Learn to develop powerful web applications
in minutes with Meteor Isaac Strack Digital Instant
Download
Author(s): Isaac Strack
ISBN(s): 9781785285547, 1785285548
File Details: PDF, 6.93 MB
Year: 2015
Language: english
www.it-ebooks.info
Getting Started with Meteor.js
JavaScript Framework
Second Edition

Learn to develop powerful web applications in


minutes with Meteor

Isaac Strack

BIRMINGHAM - MUMBAI

www.it-ebooks.info
Getting Started with Meteor.js JavaScript Framework
Second Edition

Copyright © 2015 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, and its dealers and distributors will be held liable for any damages
caused or alleged to be 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.

First published: December 2012


Second edition: June 2015

Production reference: 2290615

Published by Packt Publishing Ltd.


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

ISBN 978-1-78528-554-7

www.packtpub.com

www.it-ebooks.info
Credits

Author Copy Editor


Isaac Strack Jasmine Nadar

Reviewers Project Coordinator


Netanel Gilad Izzat Contractor
Flávio Juvenal da Silva Junior
Arthur Pham Proofreader
Safis Editing

Commissioning Editor
Veena Pagare Indexer
Tejal Daruwale Soni

Acquisition Editors
Subho Gupta Graphics
Jason Monteiro
James Jones

Production Coordinator
Content Development Editor
Manu Joseph
Anish Sukumaran

Cover Work
Technical Editor
Manu Joseph
Menza Mathew

www.it-ebooks.info
About the Author

Isaac Strack is a design technologist and STEM education advocate, currently


working as a solutions consultant for Adobe Systems. With more than 15 years of
experience in management information systems and web and creative technologies,
Isaac has a strong background in modern web application development. He is the
author of the Packt Publishing book Meteor Cookbook and the Packt Publishing video
series Learning Meteor Application Development; he also assisted recently as a technical
reviewer for another Packt Publishing book named Building Single-page Web Apps
with Meteor. He holds a patent for online fraud detection and is a co-captain of the
Salt Lake City Meteor Meetup group. He is an experienced lecturer/speaker. Isaac
regularly mentors others at boot camps, training events, and conferences, such as
UtahJS, DevMountain Meteor Day, NMC Summer Conference, Adobe workshops/
events, and the Consumer Electronics Show (CES).

A huge thank you to my family, especially my mom, who have


loved me despite instead of because. A shout out to my amazing
daughters, without whom I wouldn't be long for this world.
Sunshine, Monkey, Boogers, Pig, this one is for you.

www.it-ebooks.info
About the Reviewers

Netanel Gilad is an enthusiastic developer with expertise in web development.


He loves to learn everything, from new web development frameworks to setting
up a Continuous Integration environment to creating the ultimate application
architecture. He has led a team and worked on a mission-critical C2 web application
with high-performance requirements and an emphasis on UX. Netanel is currently
working on multiple web-related projects and is a coauthor of the popular Meteor
package angular-meteor, which brings the worlds of Angular and Meteor together.

Flávio Juvenal da Silva Junior is a Brazilian software developer. He works


at Vinta Software Studio (http://www.vinta.com.br), a software shop that uses
state-of-the-art tools such as Django or Meteor to build web and mobile products
from the backend to UX.

He believes that programming is a mix of art and engineering; therefore, the


programmer has the right to choose the best tools (such as Meteor) to transform
clients' expectations into elegant solutions.

Arthur Pham has been working for Thomson Reuters as a lead quantitative
engineer since 2006. He has spent many years designing and implementing
derivative pricing models and still loves to learn new programming languages
such as F#, C++, Python, Flex/ActionScript, C#, Ruby, and JavaScript.

He currently lives in New York, USA, and can be contacted on twitter at @arthurpham.

www.it-ebooks.info
www.PacktPub.com

Support files, eBooks, discount offers, and more


For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF
and ePub files available? You can upgrade to the eBook version at www.PacktPub.
com and as a print book customer, you are entitled to a discount on the eBook copy.
Get in touch with us at service@packtpub.com for more details.

At www.PacktPub.com, you can also read a collection of free technical articles,


sign up for a range of free newsletters and receive exclusive discounts and offers
on Packt books and eBooks.
TM

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital
book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?
• Fully searchable across every book published by Packt
• Copy and paste, print, and bookmark content
• On demand and accessible via a web browser

Free access for Packt account holders


If you have an account with Packt at www.PacktPub.com, you can use this to access
PacktLib today and view 9 entirely free books. Simply use your login credentials for
immediate access.

www.it-ebooks.info
Table of Contents
Preface v
Chapter 1: Setup and Installation 1
Installing using curl 2
Loading an example application 3
Selecting your file's location 4
Loading the example application 4
Starting the example application 4
Previewing the application 5
Help! I made too many changes! 6
Making code changes 6
Changing from Leaderboard to Yay Science! 7
Summary 10
Chapter 2: Reactive Programming…It's Alive! 11
Creating the Lending Library 11
Creating the base application 12
Creating a Collection 14
Having fun with the browser console 15
Adding some data 17
Displaying collections in HTML 18
Cleaning up 22
Creating a reaction 25
Multiple clients 27
Summary 28

[i]

www.it-ebooks.info
Table of Contents

Chapter 3: Why Meteor Rocks! 29


Modern web applications 29
The origin of the web app (client/server) 30
The rise of the machines (MVC) 30
The browser grows up 32
A giant Meteor appears! 33
Data On The Wire 33
Latency Compensation 34
Full Stack Reactivity 37
Let's create some templates 40
Summary 46
Chapter 4: Templates 47
A new HTML template 47
Gluing it all together 51
Displaying items 51
Additional view states 54
Adding events 57
Model updates 61
Style updates 64
Summary 66
Chapter 5: Data – Meteor Style! 67
Document-oriented storage 67
Why not use a relational database? 68
MongoDB 69
Using direct commands 70
Broadcasting changes 73
Configuring publishers 74
Turning off autopublish 74
Listing Categories 75
Listing items 79
Checking your streamlined data 80
Summary 81

[ ii ]

www.it-ebooks.info
Table of Contents

Chapter 6: Application Structure – Client, Server,


and Public (oh my!) 83
The client and server folders 83
The public folder 88
The security and accounts 90
Removing insecure 90
Adding an admin account 91
Granting admin permissions 94
Customizing results 97
Modifying Meteor.publish() 97
Adding owner privileges 99
Enabling multiple users 100
Summary 101
Chapter 7: Packaging and Deploying 103
Third-party packages 103
Finding the available packages 104
Bundling your application 107
Deploying your application to Meteor's servers 107
Updating Meteor's servers 108
Using your own hostname 109
Deploying your application to a custom server 109
The server setup 109
Installing and configuring MUP 110
Deploying your app using MUP 112
Summary 114
Index 115

[ iii ]

www.it-ebooks.info
www.it-ebooks.info
Preface
We live in amazing times. Advances in medicine, communication, physics, and
all other scientific fields provide us with opportunities to create things that were
literally impossible to create only a short while ago.

Yet, we aren't easily amazed. Moore's law has not only affected how fast our
computers are, it has significantly increased our expectations as well. We've
come to expect wondrous advances, and therefore, what was once amazing has
become…well…expected. It's a rare thing, indeed, to find something that takes
us by surprise—something that renews that childhood sense of wonder we all
secretly want back because it was stolen from us.

Well, get ready to regain some of that wonder. A dedicated group of computer
scientists, who were determined to make something wondrous, have created a
new JavaScript framework called Meteor. You may be thinking, "A new JavaScript
framework? That's nothing special." And, if that's all Meteor is, you'd be correct.
However, fortunately for you, that's not the end of the story.

Meteor is a reactive, simple, and powerful application platform, capable of producing


sophisticated, robust web and mobile applications with just a few lines of code.

In the context of modern web applications, it is state-of-the-art. Using established,


proven development design patterns, Meteor takes all the mundane parts of building
an app and does them all for you. Therefore, you get to focus on building a solid
application without getting bogged down with the usual time-wasting activities,
such as writing yet another database interface or learning a new templating engine.

[v]

www.it-ebooks.info
Preface

And the best part is, it's simple to learn, amazingly simple! You will see an
application come to life right before your eyes, and when you look back at the
number of lines of code it took to create and compare it to the traditional methods
of development, you may actually find yourself saying "wow" or "how did they
do that?"

This book will walk you through the major features of Meteor and show you
how to create an application from scratch. By the end of the book, you will have
created a working, useful application, and you will have a solid understanding of
what makes Meteor different. This may sound like hyperbole, but if you're open
to the idea that something innovative and unexpected can qualify as amazing,
then prepare to be amazed!

What this book covers


Chapter 1, Setup and Installation, gets you up and running with Meteor in just a few
minutes, and you'll see how quickly and easily you can build a fully functional and
useful application.

Chapter 2, Reactive Programming…It's Alive!, teaches you all about reactive


programming, and how you can leverage reactivity in Meteor to create amazing
responsive applications.

Chapter 3, Why Meteor Rocks!, helps you to gain an understanding of the design
patterns that Meteor uses and see examples of these powerful patterns in action.

Chapter 4, Templates, teaches you about Meteor Templates in depth and uses
templates to lay the groundwork for your Lending Library application.

Chapter 5, Data – Meteor Style!, helps you to discover how Meteor handles data,
making an enterprise-level application incredibly simple and robust. Implement
Meteor's data handling quickly and effectively in your application.

Chapter 6, Application Structure – Client, Server, and Public (oh my!), shows you what
changes you can make to the default configuration to make your application more
secure, extensible, and user-friendly.

Chapter 7, Packaging and Deploying, helps you to become an expert on Meteor's


packaging system, including how to include many popular third-party frameworks.
You will learn how to deploy a Meteor application to your developer, testing, and
production environments.

[ vi ]

www.it-ebooks.info
Preface

What you need for this book


To run the examples in the book, the following software will be required:

• Operating systems:
°° Mac OS X 10.7 (Lion) and above versions
°° Linux x86 or x86_64 architectures
°° Windows 7 and above versions

• Meteor:
°° Meteor version 1.1 or above

The following table will guide you to sites that contain more information:

# Software Name URL


1 Mac OS X http://www.apple.com
2 Linux http://www.debian.org
http://www.redhat.com
3 Windows https://www.microsoft.com
4 Meteor https://www.meteor.com/install

Who this book is for


This book is for an application developer, designer, or an analyst with a decent
understanding of HTML and JavaScript who wants to learn about Meteor and
the new movement inside the JavaScript community towards full-stack web and
mobile applications.

If you are looking for a step-by-step approach to understand how and when to
use one of the most popular and innovative application development frameworks,
this book is for you.

Conventions
In this book, you will find a number of styles of text that distinguish between
different kinds of information. Here are some examples of these styles, and an
explanation of their meaning.

Code words in text are shown as follows: "The WebElement class also supports
find methods to find child elements."

[ vii ]

www.it-ebooks.info
Preface

A block of code is set as follows:


<form name="loginForm">
<label for="username">UserName: </label> <input type="text"
class="username" /></br>
<label for="password">Password: </label> <input
type="password" class="password" /></br>
<input name="login" type="submit" value="Login" />
</form>

When we wish to draw your attention to a particular part of a code block, the
relevant lines or items are set in bold:
//Locate all the Checkbox which are checked by calling jQuery
find() method.
//find() method returns elements in array
List<WebElement> elements = (List<WebElement>)
js.executeScript("return jQuery.find(':checked')");

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


mvn clean test

New terms and important words are shown in bold. Words that you see on
the screen, in menus or dialog boxes for example, appear in the text like this:
"Right-click to open the pop-up menu and select the Inspect element option."

Warnings or important notes appear in a box like this.

Tips and tricks appear like this.

Reader feedback
Feedback from our readers is always welcome. Let us know what you think about
this book—what you liked or may have disliked. Reader feedback is important for
us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to feedback@packtpub.com,


and mention the book title through the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing
or contributing to a book, see our author guide on www.packtpub.com/authors.
[ viii ]

www.it-ebooks.info
Preface

Customer support
Now that you are the proud owner of a Packt book, we have a number of things
to help you to get the most from your purchase.

Downloading the example code


You can download the example code files for all Packt books you have purchased
from your account at http://www.packtpub.com. If you purchased this book
elsewhere, you can visit http://www.packtpub.com/support and register to have
the files e-mailed directly to you.

Errata
Although we have taken every care to ensure the accuracy of our content, mistakes
do happen. If you find a mistake in one of our books—maybe a mistake in the text or
the code—we would be grateful if you would report this to us. By doing so, you can
save other readers from frustration and help us improve subsequent versions of this
book. If you find any errata, please report them by visiting http://www.packtpub.
com/support, selecting your book, clicking on the errata submission form link, and
entering the details of your errata. Once your errata are verified, your submission
will be accepted and the errata will be uploaded to our website, or added to any list
of existing errata, under the Errata section of that title.

Piracy
Piracy of copyright material on the Internet is an ongoing problem across all media.
At Packt, we take the protection of our copyright and licenses very seriously. If you
come across any illegal copies of our works, in any form, on the Internet, please
provide us with the location address or website name immediately so that we can
pursue a remedy.

Please contact us at copyright@packtpub.com with a link to the suspected


pirated material.

We appreciate your help in protecting our authors, and our ability to bring you
valuable content.

Questions
You can contact us at questions@packtpub.com if you are having a problem with
any aspect of the book, and we will do our best to address it.

[ ix ]

www.it-ebooks.info
www.it-ebooks.info
Setup and Installation
Under the hood, Meteor is really just a bunch of files and scripts, which are designed
to make the building of a web application easier. That's a terrible way to describe
something so elegant, but it helps us to better understand what we're using.

After all, Mila Kunis is really just a bunch of tissue wrapped around bone, with
some vital organs inside. I know you hate me now for that description, but you
get the point. She's beautiful. So is Meteor. But it doesn't do us any good to just
leave it at that. If we want to reproduce that type of beauty on our own, we have
to understand what's really going on.

So, files and scripts… We're going to walk you through how to get the Meteor package
properly installed on your Linux or Mac OS X system, and then see the package of files
and scripts in action.

Windows is now officially supported (Yay!) so you can follow along


using the new Windows installation if you would like. Information
can be found at https://www.meteor.com/install.

In this chapter, you will learn the following topics:

• Downloading and installing Meteor via curl


• Loading an example application
• Making changes and watching Meteor in action

[1]

www.it-ebooks.info
Setup and Installation

Installing using curl


There are several ways to install a package of files and scripts. You can manually
download and transfer files, you can use a pretty installation wizard/package with
lots of Next buttons, or you can do what real developers do and use the command
line. It puts hair on your chest. Which, now that I think about it, may not be a very
desirable thing. Okay, no hair; we lied. But still, you want to use the command line,
trust us. Trust the people that just lied to you.

curl (or cURL if you want to get fancy) is a command-line tool used to transfer
files and run scripts using standard URL locations. You probably already knew that,
or you probably don't care. Either way, we've described it and we're now moving on
to using it.

Open a terminal window or the command line, and enter the following command:
curl https://install.meteor.com/ | sh

This will install Meteor on your system. curl is the command to go and fetch the
script. https://install.meteor.com is the URL/location of the script, and sh is,
of course, the location of the script interpreter "Shell", which will run the script.

Once you've run this script, assuming you have an Internet connection and the
proper permissions, you will see the Meteor package downloaded and installed:

[2]

www.it-ebooks.info
Chapter 1

The key thing that we're looking for in the preceding installation text is the launcher
script location:
Writing a launcher script to /usr/local/bin/meteor

This location could vary depending on whether you're running this script in Linux
or Mac OS X, but it puts Meteor into a location where you can then access the Meteor
script from anywhere else. This will become important in a minute. For now, let's see
what kind of friendly message we get when the Meteor installation is finished:
To get started fast:

$ meteor create ~/my_cool_app


$ cd ~/my_cool_app
$ meteor

Or see the docs at:

docs.meteor.com

Great! You've successfully installed Meteor, and you're on your way to create your
first Meteor web application!

You should bookmark http://docs.meteor.com,


an invaluable reference moving forward.

Loading an example application


The wonderful people at Meteor have included several example applications,
which you can quickly create and play with; these help you to get a better idea
of what Meteor is capable of.

We want to use the simplest possible example, just to get an idea of how Meteor
works, so we will be creating the leaderboard example. We'll be using the command
line again. This is awesome news if you still have it open! If not, open a terminal
window and follow these steps.

[3]

www.it-ebooks.info
Setup and Installation

Selecting your file's location


So that we can remember where they are later, we'll put all the files for this book in
the ~/Documents/Meteor folder. We will create this folder as follows:
$ mkdir ~/Documents/Meteor

Now, we need to get to that directory. Use the following command:


$ cd ~/Documents/Meteor

Loading the example application


We can now use the Meteor create command with the --example parameter to
create a local copy of the leaderboard example application:
$ meteor create –-example leaderboard

As with the Meteor installation itself, the create command script has a friendly
success message:
leaderboard: created.
To run your new app:
cd leaderboard
meteor

There are even instructions on what to do next. How handy! Let's go ahead and do
what our good command-line friend is telling us.

Starting the example application


To start up a Meteor application, we need to be in the application directory itself.
This is because Meteor looks for the startup files, HTML, and JavaScript that are
needed to run the application. These are all found in the application folder, so let's
go there:
$ cd leaderboard

This puts us in the ~/Documents/Meteor/leaderboard folder, and we're ready to


run the application:
$ meteor

[4]

www.it-ebooks.info
Chapter 1

Yes, that's it. Meteor takes care of everything for us; it reads all the files and scripts,
and sets up the HTTP listener:
[[[[[ ~/Documents/Meteor/leaderboard ]]]]]

Running on: http://localhost:3000/

We can now take the URL we've been given (http://localhost:3000/) and check
out the example application in a web browser.

Previewing the application


Open your favorite web browser (we'll be using Chrome, but any modern, updated
browser will work) and navigate to http://localhost:3000/.

You should see a screen with a list containing the names of scientists, similar to the
following screenshot:

[5]

www.it-ebooks.info
Setup and Installation

You can go ahead and poke around the application a bit, if you want to. Click on
Nikola Tesla's name and add 5 points to his score about 20 bajillion times, because
he deserves it. Give some love to Marie Curie because she was so radioactive that
she actually made up the word. Go nuts, friend!

Help! I made too many changes!


Do you fear change and want to reset the scores? No problem, we can start with a
clean database instance; to do this, perform the following steps:

1. Open the command line, and press Ctrl + C.


2. This stops the running application. Now, enter the following command:
$ meteor reset

3. Restart your app, and you're good to go. Just type the following command:
$ meteor

Note that the initial scores are random, so it won't look exactly like it did before.
The meteor reset command resets all the data collections and whatnot; so in a
non-random app, the command will indeed reset the app cleanly.

Making code changes


Okay, we've got our application up and running in the browser, and we now want to
see what happens when we make some code changes.

One of the best features of Meteor is reactive programming. The following extract is
taken from http://docs.meteor.com/#/full/reactivity:

Meteor embraces the concept of reactive programming. This means that you can
write your code in a simple imperative style, and the result will be automatically
recalculated whenever data changes that your code depends on.

This principle applies to code changes too, which means that any changes
that you make to the HTML, JavaScript, or database are automatically picked
up and propagated.

You don't have to restart the application or even refresh your browser. All changes
are incorporated in real time, and the application reactively accepts the changes.

Let's see an example.

[6]

www.it-ebooks.info
Chapter 1

Changing from Leaderboard to Yay Science!


As you become more familiar with Meteor, you will come to learn that you can
make changes and add files pretty much whenever you want. You don't have to
link anything up, and you certainly don't have to redeploy before you can see the
results. You get to just play around, build wonderful things, and let Meteor take
care of all the crunchy stuff.

To see what we mean, let's change the title of this application from Leaderboard to
Yay Science! because, well, yay science!

First, make sure that the application is up and running. You can do this by having
an open browser window that is pointing to http://localhost:3000/. If the
app is running, you'll see your leaderboard application. If your application isn't
running, make sure to follow the steps previously given in the Starting the example
application section.

Now, we need to open and edit the leaderboard.html file. With your favorite text/
code editor, open the leaderboard.html file under the location, ~/Documents/
Meteor/leaderboard/client/, and change title in the head section using the
following lines of code:
<head>
<title>Yay Science!</title>
</head>

Go ahead and save the file, and then look at your web browser. The page will
automatically update, and you'll see the title change. Earlier, it displayed the
word Leaderboard:

However, now, after the execution of the preceding code, the title will display our
spiffy new Yay Science! page:

[7]

www.it-ebooks.info
Setup and Installation

This is Meteor in action! It monitors any changes to files, and when it sees that a file
has changed, it tells your browser that a change has been made and that it should
refresh itself to get the latest version.

Moving forward, we're going to build an application from scratch, so we don't want
to make too many changes to this example application. However, we still want to
stay with our new theme rather than that generic old leaderboard stuff. So, to do so,
perform the following steps:

1. Back in your text editor, on about the tenth line or so, we have the title
label for our leaderboard. Make the following change to the <h1> tag:
<h1 class="title">Yay Science!</h1>

Save this change, and you'll see the change reflected in your browser.
The title in our page will now look like this:

2. Likewise, we don't give "points" to scientists. They're not trained monkeys,


dancing around for our amusement. They're scientists! We give them mad
props instead. In the <div> tag just below our title, make the following text
change:
<div class="subtitle">Select a scientist to give them props</div>

We also need to change the button text from the word points to the word
props. Towards the bottom half of the file, you'll find a <button> tag.
Change the text in that tag to the following:
<button class="inc">Give props</button>

[8]

www.it-ebooks.info
Chapter 1

Save your changes, and you will see the application update
almost immediately:

3. Just below the <button> tag, there is a message displayed if no scientist's


name is selected. It currently uses the word "players". We want to change
that to something a little more specific. To do this, make the following
change to the <div> message tag:
<div class="message">Click a name to select</div>

Save this change, and this time, refresh your browser. Not because we need
the change to take effect, but because we want to make sure no scientist is
highlighted so that we can verify our message text:

[9]

www.it-ebooks.info
Setup and Installation

Summary
Great success! In this chapter, you've successfully installed the Meteor framework,
loaded an example application, and made changes to that application by becoming
familiar with file changes and the reactive nature of Meteor.

You are now ready to start building your very own Meteor application, and learn
more about the elegant features and advantages that come from developing with
Meteor in the coming chapters.

[ 10 ]

www.it-ebooks.info
Chapter 2

Reactive Programming…
It's Alive!
As we learned in Chapter 1, Setup and Installation, Meteor operates on a reactive
programming model. This means that your templates aren't only concerned with
displaying data, but they are also listening for changes to that data so that they can
"react" to those changes. These areas of data where the templates look for changes
are called reactive contexts.

We will now start developing a Lending Library application, lay the framework for
future chapters, and use Meteor's built-in reactive model to track and propagate
changes to our application to all clients that are listening.

In this chapter, you will learn about:

• Creating your first real application


• Using reactive programming to track and automatically update changes
• Exploring and testing changes made to your data from multiple
browser windows

Creating the Lending Library


There are two kinds of people in this world—those who remember who they lent
something to and those who buy a lot of stuff twice. If you're one of the people who
is on a first-name basis with your UPS delivery driver, this application is for you!

Using Meteor, we're going to build a Lending Library. We'll keep track of all our
stuff and who we lent it to, so that the next time we can't remember where we put
our linear compression wrench, we can simply look up who we lent it to last and
get it back from them.

[ 11 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

And when that same friend says, "Are you sure you lent it to me?", you can say,
"Yeah, STEVE, I'm sure I lent it to you! I see you're enjoying your digital cable,
thanks to my generous lending of said linear compression wrench. Why don't you
go find it so that I too can enjoy the benefits of digital cable in my own home!"

Okay, okay, maybe STEVE forgot too. Maybe he's a dirty liar, and he sold your
wrench to pay for his deep-fried Oreo® habit. Either way, you'll have your very
own custom Meteor app that gives you proof that you're not going crazy. And, if
he did sell it for deep-fried carnival food, at least you can make him share his stash
with you while you watch the game at his house.

Creating the base application


The first thing we want to do is create the base application, similarly to what we did
in the first chapter, and we can then expand the base application to fit our needs:

1. Start by navigating to your applications folder. This can be anywhere, but


as mentioned in our earlier chapter, we'll be working out of ~/Documents/
Meteor as our root folder:
$ cd ~/Documents/Meteor

2. Now, we create our base folder structure for our Lending Library
application:
$ meteor create LendLib

3. As usual, we'll give instructions on how to get the application up and


running. Let's go ahead and try that, just to make sure that everything was
created properly:
$ cd LendLib
$ meteor

This navigates to the Lending Library folder under ~/Documents/Meteor/


LendLib and runs the application.

[ 12 ]

www.it-ebooks.info
Chapter 2

4. Open a browser and navigate to http://localhost:3000/. You should see


the following screen:

5. Welcome to Meteor! is nice and all, but we are going to change this to
Lending Library. Open the LendLib.html file under ~/Documents/Meteor/
LendLib/ in your favorite editor. Towards the top (the sixth line or so), you'll
see the HTML code snippet that's responsible for our greeting. Go ahead and
change Welcome to Meteor! to Lending Library:
<body>
<h1>Lending Library</h1>

6. Save the change. The page will refresh and will look like the following
screenshot:

You may have noticed a reference to a template called hello, just below the
title:
{{> hello}}

This is called the template inclusion because we are including a template.


By adding this to the body of our code, we instruct Meteor to include the
template named hello and append its contents inside our <body> tag.

[ 13 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

7. Let's make a change in this template as well. Edit LendLib.html and modify
the title of the hello template:
<template name="hello">
<h2>my list</h2>
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>

8. Save the change and your page will update as follows:

Creating a Collection
Okay, so you've just made a few small changes to static files, but what we really
want to see is some dynamic, reactive programming, and some live HTML code!

We need to attach a data source—something that will keep track of our items.
Normally, this would be quite a process indeed, but Meteor makes it easy by
supporting MongoDB, and its own client-side version called Minimongo, out
of the box.

[ 14 ]

www.it-ebooks.info
Chapter 2

To learn more about NoSQL databases (and specifically MongoDB, the


default database used inside Meteor), you can visit the following sites:

• http://en.wikipedia.org/wiki/NoSQL
• http://www.mongodb.org/
• http://www.packtpub.com/books/all?keys=mongodb

Let's create our collection. Inside the LendLib.js file under ~/Documents/Meteor/
LendLib/, we want to add the following highlighted line of code as the first line, and
then save the change:
lists = new Mongo.Collection("lists");

if (Meteor.isClient) {
...

This creates a new collection in MongoDB. Since it comes before anything else in the
LendLib.js file, the collection is available for both the client and server to see. It is
persistent, as we'll see in a moment, and once values are entered into it, they can be
retrieved by any client accessing the page.

To see this persisted object, we'll need to use the console of our web page.

Having fun with the browser console


The browser console is a debugging tool available in most modern browsers by
default, or as an add-on through plugins.

For a more in-depth tutorial on using the console in Chrome,


check out http://developer.chrome.com/extensions/
tut_debugging.html.

[ 15 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

Since we're using Chrome, the console is available by default. Let's start by
performing the following steps:

1. In a browser window pointing to http://localhost:3000/, enter the


shortcut key combination command + option + I, or you can right-click
anywhere on the page and select Inspect Element:

This will open our debugging tools. We now want to get into the console.

2. Click on the Console icon found at the extreme right of the debugging
menu bar:

[ 16 ]

www.it-ebooks.info
Chapter 2

You will now have a blinking cursor, and you're ready to check out our
newly minted collection!

3. Enter the following command in the console and hit enter:


> lists

You should get a returned object that says Mongo.Collection:

Adding some data


The previous output means that our changes were accepted, and we have a new
persistent collection! It's empty, but let's do something about that:

1. Enter the following commands in the browser console to create a couple of


sample Categories:
> lists.insert({Category:"DVDs", items: [{Name:"Mission Impossible
",Owner:"me",LentTo:"Alice"}]});

> lists.insert({Category:"Tools", items: [{Name:"Linear


Compression Wrench",Owner:"me",LentTo: "STEVE"}]});

After each command, you'll get a GUID (something like


ehkGMaxmjWqqXAMdq), which is Meteor's way of telling you that the item was
saved properly.

2. Being the natural skeptics that we are, we're going to check. To do so, enter
the following command:
> lists.findOne({Category: "DVDs"});

You should then get an Object with an expandable icon next to it.

[ 17 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

3. Click on this icon to expand it, and you should see something similar to the
following screenshot:

We could similarly check for our tools collection by entering the lists.
findOne({Category:"Tools"}) command, but we don't need to. This time we'll
trust that Meteor entered it correctly. We do, however, want to check to see whether
the objects are persistent. To do so, perform the following steps:

1. Refresh the web page. Your console will clear, but the Categories that we
entered have been saved in the persistent Meteor Collection, so we can check
again to see if they're hanging around.
2. Enter the following command in the console:
> lists.find({}).count();

This command finds all records in the lists collection and gives us a total
count. If everything went according to plan, you should have got back a
count of 2.

We're on our way! We've created two categories, and we have one item in each
category. We've also verified that the lists collection is being saved after each
session. Now, let's see about displaying this in our page.

Displaying collections in HTML


We're now going to see our collection come to life inside the HTML page that
we created when we initialized our project. This page will use templates that are
reactive, allowing us to have changes made to our Collection appear instantly,
without a page refresh. These types of reactive templates, where the DOM for
the page can be updated without a refresh are called Live HTML Templates.

[ 18 ]

www.it-ebooks.info
Chapter 2

To read more about Live HTML Templates, consult the Meteor


documentation at http://docs.meteor.com/#/full/
livehtmltemplates.

Let's perform the following set of steps:

1. With the LendLib.html file under ~/Documents/Meteor/LendLib/ still


open, locate the <body> tag and add a new template inclusion:
<body>
<h1>Lending Library</h1> {{> hello}}
<div id="categories-container" class="container">
{{> categories}}
</div>
</body>

This creates a new div element with the contents being filled by a template
partial named categories.

2. Now, at the very bottom of the page, add the skeleton for the categories:
<template name="categories">
</template>

This won't change the appearance of the page, but we now have a template
partial where we can list our categories.

3. Let's put in our section title within the preceding lines of code:
<template name="categories">
<div class="title">categories</div>
</template>

4. And now, let's get our categories in there:


<template name="categories">
<div class="title">categories</div>
<div id="categories">

</div>
</template>

This creates the div categories which we can then go through and list all of
our categories. If we only had one record to deal with, the code would look
like this:
<div class="category">
{{Category}}
</div>

[ 19 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

5. But, we need to wrap this into a loop (in this case, an #each statement) so
that we get all the categories:
<template name="categories">
<div class="title">categories</div>
<div id="categories">
{{#each lists}}
<div class="category">
{{Category}}
</div>
{{/each}}
</div>

Notice that we are telling the template "for each record in the lists collection"
with our {{#each lists}} command, and then, "display the Category" with
{{Category}}.

6. If you save these changes and look at the web page, you will see something
like the following screenshot:

This doesn't look much different. Yes, we have our header (categories), but where
are the categories for which we just created our template?

[ 20 ]

www.it-ebooks.info
Chapter 2

There's one more step we need to complete for the categories to show up. Currently,
the template that we just created isn't pointing towards anything. In other words, we
have a lists collection, and we have a template, but we don't have the underlying
JavaScript function that hooks them together. Let's take care of this by performing
the following steps:

1. Open the LendLib.js file under ~/Documents/Meteor/LendLib/, and we


can see some Template functions:
Template.hello.helpers({ ...

...

Template.hello.events({ ...

These code chunks hook up JavaScript functions and objects to the HTML
hello template. Meteor's built-in Template object makes this possible, and
we're going to follow the same pattern, that is, to hook up our categories
template.

2. We want to declare that the categories template has a lists collection.


We do this by entering the following code, just below the Template.hello.
events() block:
Template.hello.events({
...
});
Template.categories.helpers({
lists : function(){
}
});
}

The Template declaration must be inside of the if (Meteor.


isClient){...} code block so that the client will pick up the
change and the server will ignore it.

3. We've now declared the lists collection for all the templates to use, and we
can have the function return the results from a Meteor.Collection query.
We can do that using the find() command:
lists : function(){
return lists.find({}, { sort: { Category : 1 }});
}

[ 21 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

This code will find every record in the lists collection and will sort the results
by the Category (name). Save these changes, and you will now see a populated
list of categories:

Cleaning up
We're fast approaching a working application, and we want it to look super-shiny
and clean. Let's do a bit of clean up in our code and add some CSS to make things
more readable. To do this, perform the following steps:

1. We don't need the greeting anymore. So, let's get rid of it. To do this,
remove the following lines from LendLib.html and save the page:
<body>
<h1>Lending Library</h1>
{{> hello}}
<div id="categories-container" class="container">
{{> categories}}
</div>
</body>

<template name="hello">
<h2>My Library</h2>
<button>Click Me</button>
<p>You've pressed the button {{counter}} times.</p>
</template>

2. We'll keep the Template.hello declarations in LendLib.js for now, as a


reference. We'll comment them out for now and remove them later when
they're no longer needed:
/* Template.hello.helpers({
...

[ 22 ]

www.it-ebooks.info
Chapter 2

});
Template.hello.events({
...
}); */

3. Now, let's add the Twitter Bootstrap framework, which gives us a lot of style
without much effort. Using a terminal window, create a client folder in /
LendLib/:

$ mkdir ~/Documents/Meteor/LendLib/client

Download the latest Bootstrap framework at http://getbootstrap.


com/getting-started/ and extract the archive into the client
folder under ~/Documents/Meteor/LendLib/.

Since Meteor will read and use every file put into the application folder, we want to
eliminate the redundant files. We don't have to worry too much about efficiency, but
some things are just shameful and leaving that much extraneous code lying around
is right up there with enjoying deep-fried carnival food.

So, let's perform the following set of steps:

1. Navigate to the Bootstrap folder (the name will vary) using the following
command:
$ cd ~/Documents/Meteor/LendLib/client/[bootstrap]/

2. Once you've entered the folder, delete the unneeded files:


$ rm css/bootstrap-theme.c*
$ rm css/bootstrap.c*
$ rm js/npm.js
$ rm js/bootstrap.js

If you know what you're doing with Bootstrap, you can just copy
the fonts, min.js, and min.css files instead of performing the
preceding instructions.

[ 23 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

After all these changes, your UI should be really clean and simple:

Let's quickly make the UI more distinct and readable. To do this, we must perform
the following set of steps:

1. In LendLib.html, let's change our header from a <div> tag to an <h2> tag,
and change the text from categories to my stuff:
<template name="categories">
<h2 class="title">my stuff</h2>

2. Let's turn categories into a pretty button group:


<div id="categories" class="btn-group">
{{#each lists}}
<div class="category btn btn-primary">
{{Category}}
</div>
{{/each}}

This gives us a distinct, clean-looking page:

[ 24 ]

www.it-ebooks.info
Chapter 2

Creating a reaction
Following the creation of our basic template and collection, and with Meteor putting
our lists collection into the reactive context, we can now proceed to watch the
reactive programming model in action.

Navigate to our Lending Library page at http://localhost:3000/ and open the


browser console window.

In the console, enter the following command:


> lists.insert({Category:"Fraggles"});

You will instantly see the page update. Note that, this time, the full page didn't
refresh! This is because, under the hood, Meteor is tracking changes to our reactive
context (in this case, the lists collection) and the template is being updated
immediately after a change is made.

Let's make a few more changes. To do this, enter the same Fraggles command
again:
> lists.insert({Category:"Fraggles"});

Just as before, a new Fraggles button will instantly appear:

But we have too many Fraggles categories now. There are a lot of Fraggles, but
unless you're some weirdo collector, you don't need two categories. So, let's remove
them. However, we can't just erase whatever we want on the client side. This is
a basic safety feature, and if we just let it happen, things could get quite chaotic.
For instance, if we tried to just remove the records using the following command:
> lists.remove({Category:"Fraggles"});

[ 25 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

...then that's quite a no-no. Meteor detects stuff like this and will give us a 403 error
as follows:

There are three ways in which we can manually delete or modify records.

• The first is on the client side, by finding the ID of the record. In your browser
console, run the following command:
> lists.findOne({Category:"Fraggles"});

This will return a single record, including an _id property, similar to the
following screenshot:

If we take this _id and execute lists.remove(), the extra Fraggles


category will be removed:
> lists.remove({_id:"Jz68JR4gBbiBcbLPt"});

• The second way is to use meteor shell. In a new terminal window (keep
your app running!), navigate to ~/Documents/Meteor/LendLib/ and enter
the following command:
$ meteor shell

This will open a console that is directly connected to the server so that we can
run commands as if they were server code; for example:
> lists.remove({Category:"Fraggles"});

This will remove all categories that are named Fraggles. The meteor shell
command comes in handy when we need to run tests or debug, so keep this
command in your pocket to use when you need it.

• The final way to delete records is how we did it in the previous chapter, with
meteor reset. In fact, let's do that right now. Stop your application from
running (Ctrl + C) and execute the following command in the terminal:
$ meteor reset

[ 26 ]

www.it-ebooks.info
Chapter 2

Start Meteor again with the meteor command, and your application screen should be
nice and clean:

It would probably be good to have a couple of categories, so let's create them really
quickly. In the browser console, enter the following commands:
> lists.insert({Category:"Collectibles"});
> lists.insert({Category:"DVDs"});
> lists.insert({Category:"Tools"});

As you can see, the changes are made instantly, with no page refresh.

Multiple clients
Good things should be shared. Meteor gets this, and as we're about to see for
ourselves, the reactive programming model allows us to share updates in real time
across multiple clients.

With your Chrome web page still open to http://localhost:3000/, open a new
browser tab and navigate to the same page.

If you really want to get fancy, you can conduct this same
experiment with multiple browsers (Firefox, Opera, or Safari).
Each session will be live and reactive!

You now have two clients open, which is simulating the application being open by
different people, at different locations, with different computers. Meteor's reactive
model allows you to treat all clients in the same manner, and a change made by one
will be propagated to all the others.

With your eyes on the new second browser, type the following command into the
console of browser #1:
> lists.insert({Category:"Vinyl Records"})

[ 27 ]

www.it-ebooks.info
Reactive Programming…It's Alive!

You will notice that the change propagates to both browsers, without a page refresh:

Feel free to make any extra collections, to remove or rename them, and so on.
Experiment a little and notice how these changes can be instantly made to every
listening client. Meteor operates under a very powerful paradigm, and in the next
chapter, you'll be able to see exactly why this is such an important and disruptive
change to web application development.

Summary
In this chapter, you successfully created the framework for your new Meteor
application. You saw firsthand how quickly a new project can be created, and you
created database and template functionality with just a few lines of code. You saw
live HTML and reactive programming in action, and you are now ready to go even
deeper into the Meteor engine. You've conquered the tip of the iceberg, my friend.
Take a break, have a cold one, and get ready for even more Meteor awesomeness!

[ 28 ]

www.it-ebooks.info
Discovering Diverse Content Through
Random Scribd Documents
"And don't I want you to be happy? You know I'd do
anything in the world for you! Don't you, now? I'd promise
faithful never to touch a drop of anything again, if that
would make it all right."

"You wouldn't keep your promise?"

"I swear I would."

"James, you are not to speak so! And it's no use. You
promised me—faithfully—that you would stick to work, the
next that came in your way; and you threw it up the first
thing."

"I'll stick to it yet,—as soon as I get something to do."

Suddenly Plunkett turned into the street, and crossed


over a little way in front of them. Marigold at once called,—

"Father!"

"You shut up!" said Todd, not too civilly.

"Father!" repeated Marigold, and he stopped.

"Eh; it's you, is it?" said Plunkett. He did not think much
of seeing the two together, merely supposing that they had
just met, and Todd remarked,—

"Fine day!"

"Father, James has walked with me all the way from the
Common,—from half over the Common. I did not want him.
I've let him do it before, and I was wrong; and I told him
not to-day, and he would come."

"Well, why not?" said Todd sulkily.


Plunkett looked from the one to the other.

"I told him I would tell you, and now I have," said
Marigold. Then she went indoors, leaving the two together.

Plunkett presently followed, to find her alone in the little


kitchen.

"What's all this?" he demanded.

"Father, I thought I ought to speak about it. Mother said


once you wouldn't be pleased . . . And I wouldn't listen . . .
But Mrs. Heavitree's been talking . . . And—I thought—I
ought—" Marigold's voice failed.

"An idle fellow like that! You've too much sense to care
for him!"

Plunkett stared, as Marigold burst into tears.

"Eh? You don't mean for to say you like Todd?"

"He's been nice to me,—and I do like him," sobbed


Marigold. "But Mrs. Heavitree says—says he's not—"

"Not the sort to make a girl happy? No, I should think


not. He's smooth-spoken, and when you've said that,
you've said all. I wouldn't see you marry Todd,—not for
anything you could name! I told him he'd best make himself
scarce, and he said it was all a mistake,—he'd no notion of
marrying nobody."

"Oh!" Marigold's cheeks flamed.

"That isn't how he's talked to you, oh?"

"I should think not! Father, I did think he was one that
would speak true."
"Well, the best thing you can do is to see no more of
him," said Plunkett decisively. "There's no sort o'
dependence to be put on Todd. He's not fit for you, and
you're a deal too good for him. And what's more, you'll
never marry him with my will. So the sooner you can forget
him, the better. I've said enough to stop his looking in here,
again, in a hurry. And I'm sure you'd need be grateful to
Mrs. Heavitree, for the trouble she's taken."

Marigold's thoughts reverted to the beginning of her


Vicarage conversation. "There's something else too,—" she
said, "something you'll be glad of. Mrs. Heavitree said I'd
best not speak to mother, but I might to you." Then she told
Plunkett about the doctor who was to arrive at the Vicarage,
and about Mrs. Heavitree's kind intentions.

CHAPTER IX.
NOT SO BAD.
RESENTMENT at Todd's declaration that "it was all a
mistake," and that "he hadn't meant to marry nobody,"
gave Marigold a good deal of help in casting aside overmuch
thought of him. Had he been grieved and disappointed only,
she would have been grieved too; and he might have
retained his power over her; but now Marigold's womanly
self-respect was up in arms.

Some girls seem to have no womanly self-respect at all,


but Marigold happily was not deficient in this direction. If
Todd counted it "all a mistake" that he had wanted to marry
her, she would let nobody suppose that she wanted him. If
Todd did not care for her, then she would not care for him.

Of course in a measure she did care; though to her


surprise, by no means so much as she would have
expected. Todd had managed to win her liking, but not to
stir her feelings deeply. That might have come later, had the
affair been allowed to go on. At present it was mainly a
question of gratified vanity, and of escape from home
troubles. Wounded vanity was the best possible antidote to
the former; and as for the latter, home troubles had
lessened.

Marigold found her time and thoughts much occupied


with her stepmother; so much, that for hours together she
often forgot Todd's very existence—a sure proof that her
affections were not profoundly engaged.

Mrs. Plunkett suffered much, and was weighed down by


anxious depression, as well as weakness. But from the day
when she allowed herself to speak out to Marigold, there
was an extraordinary cessation of the extreme irritability.
She reverted suddenly to her old self; the kind and amiable
self, which they had known for three months only. She no
longer struggled to keep up, or to do work for which she
was utterly unfit.

Marigold might arrange matters as she chose, and Mrs.


Plunkett offered no opposition. It was easy now to be gentle
and kind to one so passive; and love, no longer receiving a
slap in the face at every other step, sprang into being, with
a promise of rapid growth.

"I'm sure I can't think how ever it was you seemed so


different, Marigold, till these last few days," Mrs. Plunkett
said musingly one afternoon.

She had not come down till the middle of the day, and
was suffering a good deal; but her face, though yellow and
drawn, had lost much of its acidity. "Why, nothing I could do
pleased you, and yet you're as good to me now—"

"Mother! Why, nothing I could do pleased you," broke


from the surprised Marigold.

Mrs. Plunkett cast a puzzled glance backward.

"I'm sure I don't know," she said. "I know I used to feel
so dreadful bad, I didn't know how to drag through the
days; and I could have flown out at anybody. The day we
went to the beasts' show—oh, dear! Part of the time I could
get along; and then the pain came on, till it turned me sick,
and I didn't half know what I was about, and the thought of
going home all alone—oh dear me!"

"Mother, if you only had told! We thought you were just


cross and vexed about something," said Marigold, tears in
her eyes.
"I wasn't. I thought it as nice as could be of you to ask
me to go—and if only I could have kep' on!—But it did seem
hard, when I felt so awfully ill, to have all of you thinking of
nothing but them snakes. And the pain was so bad."

"Oh, mother, if you only had told me!"

"Well, I see now that I had ought to—but I didn't feel as


if I could. I thought you'd dislike me more than ever. I know
you better now, Marigold!"

"Somebody outside. There's the bell, mother!"

And when Marigold opened the front door, she found


Mrs. Heavitree, with a grave middle-aged gentleman, whom
she at once guessed to be the expected Dr. Wilton.

"Mrs. Plunkett in, Marigold? I have come with my


brother to pay her a little visit. Say only that," added Mrs.
Heavitree softly.

Marigold obeyed with a grateful look, and the four were


soon chatting pleasantly. Mrs. Plunkett was somewhat
flustered, but also pleased. The doctor at first talked to
Marigold; then he made his way to a seat by Mrs. Plunkett,
and drew her into conversation.

"Marigold, I want to speak to you in another room," said


Mrs. Heavitree, rising. "My brother will wait here."

Dr. Wilton made a gesture of assent, and Mrs. Plunkett


showed no disapproval. She did not know him yet to be a
doctor; but his kind manner won confidence immediately,
and already she had begun to talk almost freely about
herself and Marigold.
"That is well," Mrs. Heavitree said, when they were in
the next room. "My brother will manage all the rest."

The interview was a long one; much longer than


Marigold would have expected. Mrs. Plunkett's raised tones
came from time to time through the door; while Dr. Wilton's
low-voiced answers were inaudible.

At length, after what seemed to Marigold an


interminable time, the door opened; Dr. Wilton could be
heard to say "Good-bye," and with a quiet step, he entered.

"Well?" Mrs. Heavitree asked.

"Not so bad as you have all feared," he said. "It is—not


cancer."

"Oh!" Marigold clasped her hands.

"A severe case of tumour, and it must be removed. But,


once removed, she may enjoy good health. I should have
little fear of its return."

"Then the former opinion was a mistake," said Mrs.


Heavitree.

"Yes."

"You don't know who she went to see?"

"She told me. Not a medical man at all, in fact. A


passing quack—nothing more. Extraordinary how people will
take the opinion of anybody and everybody on such a
question!"

"Will she submit to the operation?" asked Mrs.


Heavitree, and Marigold's face asked the same question
eloquently.

"At first she said not. I reasoned the matter with her.
Some measure of risk must exist, of course, in such a case;
but there is every probability that she would bear it well,
and would enjoy excellent health afterwards. If she goes on
in her present state, life cannot be lengthened many
months. A year or two at most."

"And she gave in?"

"Entirely. She will, of course, go to the hospital. I shall


see her again before I leave; and I have promised that you
and her daughter will make all arrangements."

"I don't know how to thank you, sir," said Marigold, with
difficulty. "It is so very very kind!"

The doctor smiled as he went off, and Marigold


hastened to her stepmother. She found Mrs. Plunkett
sobbing.

"Not as I mind. 'Tain't that!" said Mrs. Plunkett. "It's the


relief. I never knowed what a weight it was on me, till now
it's gone. Why, I feel as if anything else was nothing almost!
I did say I'd never go to a hospital, and be in the hands of
all them doctors. But if they're like Dr. Wilton, I'm sure I
won't mind. He is kind! I never saw a kinder person, not in
all my life. And understands like as if he'd got it himself. Oh,
dear me! To think it isn't that, after all; and to think I may
be quite well again. Yes, I'd bear some'at to get strong as I
used to be. And he says he thinks I ought. It ain't but little
risk, he says; and t'other way, if nothing is done, it means
death. He don't think I'd ought to throw away my life, if
there's a good chance of saving it. And I said I'd do what he
thought right."
"Oh, mother, I can't tell you how glad I am."

"Well, I do believe you are," said Mrs. Plunkett. "I do


believe you won't be sorry if I get well. A while back I'd
have thought you wouldn't have been best pleased—not any
of you. But it's different now. And I don't mean to get back
into cross ways, nor to vex your father, nor to have things
all in a mess, no more. It is nice, the house being kep' tidy,
as you do now; and I'll see and go on with it."

"I'm sure you will," said Marigold affectionately. "And


you'll let me be a help to you?"

"You ain't going to marry that Todd?"

"No! Never!" said Marigold, with firmness. Only the


evening before, she had herself seen Todd reeling down the
street in a tipsy condition—a shameful sight! He had
shouted rudely after Marigold. And with burning cheeks she
had thought, "That is the man I would have married!" No,
never! Never! If her mind had not been already made up,
this would have settled the matter.

"I'm glad. He wouldn't have made you a good husband


—I know that! And you're too young—ever so much too
young. When I come home, I'll like to have you with me—."
She paused, and added, "If I ever do come home."

"Mother, Dr. Wilton didn't seem afraid."

"No; he said he wasn't, and he thought it was the right


thing to do. But he said he couldn't be sure. People don't
always get through—only he'd great hopes I should."

"And then you know, we shall be praying for you," said


Marigold softly. "Narcissus and me, and I'm sure Mrs.
Heavitree will."
"Yes, I know that," said Mrs. Plunkett. "I like to think it.
And I want you to read to me every day till I go. The doctor
says I'm to be in the hospital in a week or two. He don't
want it put off long. And I'm frightened when I think of that.
I want to learn how to trust that I shall be taken care of all
through—and then I shan't be so afraid."

Marigold did read every day, as Mrs. Plunkett wished;


and sometimes in her simple way, she would speak about
the great kindness and love of God, and about the living
presence of Christ in days of trouble. Mrs. Plunkett would
drink in such words with positive thirst, feeling her need of
help. Mr. Heavitree also came in two or three times, and his
visits "gave her a sort of lift," she said afterwards. One way
or another comfort seemed to be sent, just when it was
most needed; and as the day drew near, when she would
have to leave home, her dread distinctly lessened. She
actually went at last with a smile on her face; and
Marigold's first visit to the hospital, two days later, found
her the cheerier of the two.

Then came days of suspense for others, gradually


lightening as the operation proved to be a successful one.
Weeks of tardy recovery followed, not lacking drawbacks,
but on the whole satisfactory, and the doctors gave every
hope of a complete and permanent restoration.

Nearly three months of absence drew at length to an


end, and Mrs. Plunkett returned home, not yet strong, but
no longer a sufferer.

"It's like beginning a new life," she said.

Marigold had decorated the little parlour with flowers,


and had prepared quite a festive meal, in honour of her
arrival; and Narcissus had been spared from the Vicarage
for several hours. Mrs. Plunkett seemed quiet and dreamy,
as if a little bewildered with the change from a hospital
ward; but the old acidity of expression had given place to a
look of steady happiness.

"It's like beginning a new life," she repeated. "And I


hope it's going to be new—some ways. I hope I ain't going
back to old ways. I've had a deal of time to think, lying
there."

"Dare say you won't be none the worse," suggested


Plunkett.

"No," she said. "I hope I shan't, nor the girls neither. I'd
like to be a better friend to them than I was before I left;
and a better wife to you. And most of all, I'd like to serve
God truer. I thought I was going to leave you all; and now
He's put me back into life; and I'd like to make a good use
of my time. That's what I want."

"Ain't a bad wish, neither," said her husband; while


Narcissus looked with touched and wondering eyes towards
the speaker, and Marigold murmured:

"That's what I want, too."

LORIMER AND GILLIES, PRINTERS, EDINBURGH.


*** END OF THE PROJECT GUTENBERG EBOOK MARIGOLD'S
DECISION ***

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