Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
KNOCKOUTJS BLUEPRINTS

You're reading from   KNOCKOUTJS BLUEPRINTS Learn how to design and create amazing web applications using KnockoutJS

Arrow left icon
Product type Paperback
Published in Feb 2015
Publisher
ISBN-13 9781783980840
Length 218 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Carlo Russo Carlo Russo
Author Profile Icon Carlo Russo
Carlo Russo
Arrow right icon
View More author details
Toc

Communicating with other components

We realized the form, and now the customer can search for hotels; clicking on the search button will send a request to the backend, and we will use the result inside other components.

We need a way to enable communication between components without the need for direct referencing each other.

In the next chapter, we will look at the concept of Publish/Subscribe, but now we will go with a simple Event Manager module (following the Mediator design pattern).

When you got the files for the communication with the backend, you download BookingOnline/app/services/eventManager.js.

This module exposes three functions:

  • function on (event name, callback): use it to listen for named event
  • function off (event name, callback): use it to stop current listening for a named event
  • function trigger (event name, parameters): use it to send a message to the listeners

If you check the rest.js module, you will find there a function named getHotelByDestination. At the end of the function...

You have been reading a chapter from
KNOCKOUTJS BLUEPRINTS
Published in: Feb 2015
Publisher:
ISBN-13: 9781783980840
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image