Docs

Everything You Need to Know

Dispatch

Intro

Truck Wheels

Truck's dispatch system enables decoupling of components. This has two parts: a dispatcher and a receiver. You define a reciever with a handle, which is its address, and a callback to execute when a dispatch is received. The dispatcher can optionally send some data with a dispatch. When this happens, the receiver can respond by doing something with the data it received. Think of dispatches as events. The receivers can respond however you need them to when a dispatch is sent.

Truck's mediators are based on the behavior of the dispatcher. Dispatches enable Truck to perform data binding, etc. Dispatchers are delivery agents that use their handles to deliver data. That's all they do. Receivers are the workers who do something when the dispatcher makes a delivery. Receivers are very patient. They won't do anything until a dispatcher delivers.

If you need to, you can stop a dispatch from happening. Once stopped, you will not be able to use that handle from being dispatched.. It's like taking the keys away from the delivery agent, so can't drive his truck to make a delivery. Stopping a dispatch handle does not eliminate it. You can start it again at any time.

A receiver can handle deliveries from multiple dispatchers. Receiver are simply waiting for a dispatch. They don't care who is making the dispatch. You can have multiple dispatchers using the same handle in different parts of your app, depending on what you need to accomplish.

Receivers can react differently depending on what the dispatcher delivers. One receiver might only accept string data. Another might only want arrays. Or a receiver could do different things depending on the kind of the data delivered - eat the pizza, throw out the junk mail.