reactive-python / reactive-python/reactpy
Allow server-side components to send messages to client-side components
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.1k
- Forks
- 332
- PR merge metrics
- No merged PRs in 30d
Description
Current Situation
Presently, custom client-side components are able to send events back to the server. However, it is not possible to send events from server-side components to client-side ones.
Proposed Actions
Now that custom JS components have the ability to register callbacks with the client this should be technologically feasible. With that said, while users can listen in on particular message types, there is no concept of a message "target". We could achieve this by having message types of the form server-event:<the-target>, but this seems like a bit of a hack. Perhaps we can allow (require?) a nullable target field for this purpose.
Before diving into all those details though, we need to work out exactly what this interface should look like.
I can imagine having an interface similar to:
@component
def example():
channel = use_channel()
@use_effect
async def delayed_message():
import asyncio
await asyncio.sleep(5)
await channel.send({"my": "message"})
response = await channel.receive()
return custom_js_component({"channel_id": channel.id})
where custom_js_component would then subscribe to messages of the type channel-message and target channel.id.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the callback registration in src/client/packages/@reactpy/client/src/reactpy-vdom.tsx and trace the existing client-to-server event path. The issue still needs an agreed interface for targets or channels before implementation. Done means server-side components can deliver messages to the intended custom client-side component and the contract is documented and tested.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, python
- Domain
- full-stack
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100