Imagine you want to store an object (with a publisher) and update it based on some event. One way to accomplish this would be the following:
- Store the object and its publisher somewhere.
- Create a publisher that describes how to update the object.
- Create a subscription that connects the object and the publisher.
- Store the subscription somewhere.
A basic implementation may look like this:
This implementation is cumbersome, however, because it requires multiple pieces of code in different locations to only really accomplish one thing. So I made a custom publisher that does all of this:
It only requires one declaration:
Personally, I think this publisher makes the code a lot cleaner.