Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share context between machines? #135

Open
trafnar opened this issue Dec 24, 2020 · 3 comments
Open

Share context between machines? #135

trafnar opened this issue Dec 24, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@trafnar
Copy link

trafnar commented Dec 24, 2020

Is it possible to share context between machines? The parallel states section of comparison with xstate suggests modeling parallel states as separate machines, but I have parallel machines that share a single context. Is there a recommendation for doing that?

The situation I have is a video timeline where you can move the playhead back and forth, and there are ranges of time on the timeline which can be manipulated (moved, deleted etc). Those manipulations are modeled by one machine, and I have another machine for adding new ranges, (because that can be done at any time), however the new ranges are added at the current playhead position, which is stored in the context of the first machine.

@matthewp
Copy link
Owner

Interesting use case! No, as of now the context is not shared with separate machines. Maybe this is a use case for adding direct parallel states to Robot? 🤔

@matthewp matthewp added the enhancement New feature or request label Dec 29, 2020
@40thieves
Copy link

I'd be interested in parallel states too. My use case is a chat with infinite scroll: scrolling up will trigger an async fetch of old messages, and a websocket subscription can append new messages. I've found it tricky to handle new messages while a fetch is pending.

I found it simpler to model as 2 parallel machines with a shared messages context. Here's a minimal example in the XState visualiser: https://xstate.js.org/viz/?gist=23aa888f7527721be5d138d8446124a7. (If there's another way of achieving this in Robot, then please let me know! I'm new to FSMs 🙂 )

@matthewp
Copy link
Owner

Ah, really nice use case! Yeah you can model this in one machine but it's more elegant in a single one.

Part of me wonders if making machine 2 machine communication easier would solve parallel machines and nested machines at once, without adding a lot of new concepts. Something to continue to ponder on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants