You know about the reserved events such as
removed, but did you know we also have custom events?
Custom events can be handy for passing messages or data between devices, users, different collections or even different parts of the same app.
Here’s one basic example of a custom event listener:
In this example, we set up a listener for a custom event called
custom_event, and then we triggered that event with a message.
In this case, the message was
Just like reserved events, custom events are linked to a collection, but unlike reserved events no data is ever written to disk.
Custom events are handy in that you can use them for nearly anything.
For example, you could set up a custom event for a collection called
users and fire off a message everytime a user logs in or joins which would be seen by all other users currently logged in.
This could also be useful for displaying activity streams, for example we’ll build a basic activity stream now that will display notifications on a page to all users.
Now, whenever you send a trigger to the
activity event, it will display to any users who are listening.
Custom events aren’t limited to just strings, they can also contain JSON objects.
There are plenty of other uses for being able to instantly push custom events to users of your apps, but this is one example.
Custom events helps increase how you can make your apps useful to your users, thereby making life easier for everyone.
Ready To Build Awesome Apps?