3 ms·
A good example for using the dispatch object was how views interact when we send messages out from the compose message form on Sendhub.com. When a user composes
by drags 15y ago
A good example for using the dispatch object was how views interact when we send messages out from the compose message form on Sendhub.com. When a user composes a message and submits the form (ComposeMessageFormWidget), we render the new message in the ThreadView, which is a different view object. The ThreadView object listens for new messages to be sent during render
Another, less complicated, way of achieving this is to have the view listen for model attribute changes.
Presumably the compose form generates a Message model which is part of a Messages collection. Both ComposeView and ThreadView can have access to (and listen on) this Messages collection.
Then when a Message is successfully created server-side (or when it's created client-side), a "saved" attribute on the Message model changes to true. This bubbles up through the Messages collection and ThreadView's listener gets tripped with the relevant Message as an argument.