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

Direct messages to Ratatouille. Is it implemented? #13

Open
ADodulad opened this issue Oct 7, 2019 · 7 comments
Open

Direct messages to Ratatouille. Is it implemented? #13

ADodulad opened this issue Oct 7, 2019 · 7 comments

Comments

@ADodulad
Copy link

ADodulad commented Oct 7, 2019

Is there a way to update model and trigger view rendering via direct message to Ratatouille without Command invocation?

@ndreynolds
Copy link
Owner

So officially, there are 3 ways to trigger an update and re-render (update is always followed by a render):

  1. The runtime receives an event (e.g., key press, resize), calls your application's update/2 function, and then renders the result.
  2. After receiving an event, your update/2 returns a Command, the command is evaluated, and update/2 is called with the command result followed by a re-render.
  3. With a subscription configured, your update/2 is called periodically at approximately the configured interval with a re-render after each call.

Unofficially, you could also achieve 1. above by manually sending the runtime an event (e.g., send(pid, {:event, :foo})), but hopefully there's a better way to achieve what you're looking for within the system.

Could you elaborate on your use-case a bit? If none of these fit, I'd be happy to explore adding something new to address it.

@ADodulad
Copy link
Author

ADodulad commented Oct 8, 2019

Ok, nothing fancy, for example, when building chat room I have a process that constantly receive messages and update needs to be triggered each time such messages received.

Time interval subscription might be an option and it will do its job but it would feel slow due to low frequency update. It might be a ground for discussion whether or not TUI has to have immediate response, but for me it feels like positive answer.

Oh, another case I almost forgot. I have GenServer having a process status wothin its state. 90% of the time it is idle and 10% either transmitting or receiving. It would be nice to have blinking which is not possible with time interval subscription.

Work around with event might be a good option tho, havent though about it this way.

PS. Btw, another thing which I find quite useful is logger backend for ratatouille. If I will manage to implement it I will create PR. Currently any output to console breaks the interface, if there are any guidelines or best practices I would appreciate it.

@zorbash
Copy link

zorbash commented Feb 20, 2020

@ADodulad You can use https://hex.pm/packages/logger_file_backend for logging.

@paveltyk
Copy link

@ndreynolds Hi, Nick,

Here is my use case: I have a WebSocket process that will send a message to its' subscriber. What would be the best approach to handle those events in Ratatouille app?

@brendalf
Copy link

Hi, how can I get the runtime PID to send messages?

@ughitsaaron
Copy link

@ndreynolds and others, I'm working on an application which calls out to an external library from within Ratatouille. I need to share some state from this library and Ratatouille. Would this be a valid use case for the runtime event escape hatch?

@octosteve
Copy link

@brendalf You can start the process in your supervision tree with a transient strategy. I believe that pid is what you want.

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

No branches or pull requests

7 participants