reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Implement publish-subscribe pattern

Open JBetz opened this issue 4 years ago • 2 comments

Implements the publish-subscribe pattern for communication within a reflex network.

The motivation for this came from frustration with communication patterns being tightly coupled to widget hierarchies, particularly when implementing something similar to the Elm architecture by way of EventWriter. PubSub lets you separate these concerns, even inverting the widget hierarchy if so desired, as well as enabling a much more flexible event-handling architecture.

So far the only testing has been in application usage, but it builds upon existing abstractions without introducing anything too alien to reflex. I'm open to writing some documentation with examples if people are interested, but for now, just gauging interest and looking for feedback on merge-ability.

JBetz avatar May 24 '20 15:05 JBetz

Thanks for the comments @endgame. I still feel like there's something useful here, if only a symptom of a deeper problem, but after processing your feedback and others I'm not convinced this is the cure.

@ryantrinkle pointed out that you can get the basic idea for this using QueryT, where your queries end up looking something like DMap Topic (Map Query). And then I was thinking how the topic could be an index into multiple external datasources a reflex network might be interested in, or slices of a single data source. Or if you have some sort of peer-to-peer setup, you could do Map Peer (Map Query a).

In any case, there are already abstractions available for the subscription side of things, and since publishing is what's likely to become intractable, I'd rather sort out a better solution for publishing before trying to push forward something as overpowered as this. I'm not planning to close this PR quite yet, but probably won't be doing much if any work on it either unless we can fix or at least mitigate the "action at a distance" problem.

JBetz avatar Jun 03 '20 12:06 JBetz

Another thought: could this be a standalone library instead of being integrated into reflex itself?

endgame avatar Jun 10 '20 03:06 endgame