Book Image

Meteor Cookbook

By : Isaac Strack
Book Image

Meteor Cookbook

By: Isaac Strack

Overview of this book

Table of Contents (19 chapters)
Meteor Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Stop and think for just a minute about the last time you were delighted.

I'd bet good money that whatever that delightful experience was, it had nothing to do with a new JavaScript framework. Well, that is about to change.

Meteor is not just another JavaScript framework that you'll forget the name of a few weeks from now. It was created—and is continuously improved upon—by legit computer scientists driven by a vision of how software development should be. Their mantra is that "programming should be fun" and as you go through this list of Meteor recipes, you will see exactly how much fun it really is to develop applications using Meteor.

Meteor is modular and declarative, supports data-on-the-wire, is well supported by a thriving development community, and implements full-stack reactivity. This sounds like a bunch of meaningless buzzwords, until you fully grasp their impact on your day-to-day development efforts.

Because Meteor is modular and well supported, it works easily with all of your favorite JavaScript frameworks. You can use the entire Meteor stack, or you can mix and match it with community packages to complement your existing infrastructure / skill set.

Meteor supports data-on-the-wire through the Distributed Data Protocol (DDP). This innovation is significant in that it allows you to create elegant, powerful client applications responsible for their own rendering. You no longer have to rely on complex, outdated server technology rife with state and rendering problems that (frankly) should have been solved years ago. DDP is not unique to Meteor or even to JavaScript. DDP clients are available in nearly every major programming language! This opens up many elegant, powerful integration possibilities, allowing you to build upon existing platforms and infrastructures.

Combining DDP with full-stack reactivity opens up an entirely new way of developing frontend applications. Templates, database transactions, and view/controller logic are vastly simplified, allowing you to write clean, concise, declarative code. Your frontend development efforts will go from weeks to hours as you stop worrying about tedious state and CRUD operations and focus on rapid, elegant prototyping.

The more acquainted you become with Meteor, the more effective and prolific you will become as a developer. Programming with the Meteor framework is truly an enjoyable experience. The recipes found in this book will get you well on your way to being delighted by each project you complete and will serve as an indispensable reference for many projects to come.

What this book covers

Chapter 1, Optimizing Your Workflow, walks you through all the aspects of the Meteor development workflow. It includes best practices for repeatable, consistent project templates; for customizing your Meteor development environment; and for deploying your completed projects.

Chapter 2, Customizing with Packages, covers every aspect of the modular Meteor packaging system. Recipes that cover searching, installing, removing, modifying, creating, and deploying packages of all kinds are included. Information on how to use some of the more useful and popular packages, including npm modules and Iron Router, is also included.

Chapter 3, Building Great User Interfaces, contains essential recipes to develop front-end applications using Blaze, Meteor's reactive template engine. Everything from basic templates to custom components and animations is covered.

Chapter 4, Creating Models, provides clear, concise examples of the reactive data/model capabilities Meteor provides. From implementing a simple data collection to advanced filtering and upserts, this chapter will be your go-to reference for all of your reactive data needs.

Chapter 5, Implementing DDP, covers the major uses of the Distributed Data Protocol. Everything from reading the raw DDP stream to using the protocol with other programming languages is covered, with examples for easy implementation.

Chapter 6, Mastering Reactivity, takes you through the more advanced aspects of Meteor reactivity on the frontend. These recipes take you "under the hood" and show you how to customize and create reactive components as well as how to integrate nonreactive components (such as JQuery UI) into smooth, effective user interfaces.

Chapter 7, Using Client Methods, contains advanced UI recipes designed to take advantage of some of the more useful HTML5 components. Information and examples to create dynamic SVG graphs, implementing touch-based Canvas components, or uploading and serving images with the FileReader are all found in this chapter.

Chapter 8, Integrating Third-party Libraries, walks you through the use of standalone third-party libraries. Instructions and explanations on directly using npm modules, implementing sophisticated D3.js graphs, and building complete UIs with Polymer are included. This chapter uses these examples as guidelines, which you can extend to implement any third-party library in Meteor.

Chapter 9, Securing Your Application, goes through all of the fundamental security features of Meteor. When your application is ready to be deployed to production, the recipes in this chapter will ensure that your app is secure and performant.

Chapter 10, Working with Accounts, dives into the robust and flexible Meteor Accounts packages. You will learn how to customize the Accounts UI, use external OAuth providers such as Twitter, and even perform two-factor authentication.

Chapter 11, Leveraging Advanced Features, provides "graduate-level" methods and examples of how to take advantage of Meteor's full capabilities. Primarily focused on server-side functionality, this chapter covers extending/marshaling objects with EJSON, server methods, and the use of Fibers to elegantly handle asynchronous functions and callbacks.

Chapter 12, Creating Useful Projects, is the culmination of the other chapters in the form of a useful, complete application. The recipes walk you through creating REST services, adding social sharing to an existing app, building a complete application with Iron Router, and deploying to mobile devices.

What you need for this book

This book assumes that you have a working knowledge of JavaScript and HTML. Being familiar with Node, npm, GitHub and the command line/terminal will be very helpful (but not critical) to getting the most out of the recipes in this book.

You will find recipes to install Meteor on Mac OS X or Linux, with links to using Meteor on Windows and Google Chromebooks. In every instance, you will need access to the Internet to download Meteor and community packages, and you will need installation privileges for your developer machine regardless of the operating system.

For deployment to production environments or to mobile devices, the requirements will vary from recipe to recipe. To complete all of the recipes successfully, you will need your own hosted server and DNS domain as well as iOS, Android, or Windows mobile devices and SDKs.

Who this book is for

This book is meant for developers of all experience levels looking to create mobile and full-stack web applications in JavaScript. Many of the simple recipes can easily be followed by less-experienced developers, while some of the advanced recipes will require extensive knowledge of existing web, mobile, and server technologies. Any application or enterprise web developer looking to create full-stack JavaScript-based apps will benefit from the recipes and concepts covered in this book.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

Conventions

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

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "You must have curl installed in order to install Meteor."

A block of code is set as follows:

<head>
<title>FileTemplate</title>
</head>
<body>
<h1>Welcome to Meteor!</h1>
{{> hello}}
</body>

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

Package.onUse(function(api) {
api.versionsFrom('1.0.3.2');
api.addFiles('testpack.js', 'client');
api.addFiles('servertestpack.js', 'server');
});

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

$ sudo apt-get install curl

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "Click on the button labeled NEW ORGANIZATION at the bottom of the screen."

Note

Warnings or important notes appear in a box like this.

Tip

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 disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in 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 at www.packtpub.com/authors.

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 from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. 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. Optionally, the code samples can also be downloaded from https://github.com/strack/PacktMeteorRecipes.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/MeteorCookbook_ColorImages.pdf.

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 could 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/submit-errata, 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.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted 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 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

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.