Book Image

Build Applications with Meteor

Book Image

Build Applications with Meteor

Overview of this book

This book starts with the basic installation and overview of the main components in Meteor. You’ll get hands-on multiple versatile applications covering a wide range of topics from adding a front-end views with the hottest rendering technology React to implementing a microservices oriented architecture.All the code is written with ES6/7 which is the latest significantly improved JavaScript language. We’ll also look at real-time data streaming, server to server data exchange, responsive styles on the front-end, full-text search functionality, and integration of many third-party libraries and APIs using npm. By the end of the book, you’ll have the skills to quickly prototype and even launch your next app idea in a matter of days.
Table of Contents (16 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
8
Build a Chatbot with Facebook’s Messenger Platform

Async actions in Redux


Out-of-the-box, Redux is synchronous. If you try to dispatch an async function, you'll get an error:

Actions must be plain objects. Use custom middleware for async actions.
importthunk from 'redux-thunk'
import createLogger from 'redux-logger'
const middleware = [thunk]
if (process.env.NODE_ENV !== 'production') {
 middleware.push(createLogger())
}
const store = createStore(reducers, applyMiddleware(...middleware))

redux-thunk is  middleware that will allow us to dispatch a function and wait for the result; then we can dispatch another action(s).

Here's how we can use async actions:

export const track = filter => {
   return dispatch => {
       Meteor.call('track_phrase', filter.phrase, err => {
           if (!err) {
               dispatch(selectFilter(filter.id));
          }
           //do something if you have an error. you can dispatch another action
       })
   }
}

In the action, we call a standard Meteor method by passing a filter phrase to the server...