unabridged / motion

Reactive frontend UI components for Rails in pure Ruby
https://github.com/unabridged/motion
MIT License
698 stars 19 forks source link

[question] broadcast to multiple clients #65

Open caifara opened 4 years ago

caifara commented 4 years ago

In trying to define where to use Motion/streamline our application, we're trying to change our custom ActionCable adoption to a motion one. We've run into this possible out-of-scope use case:

I have a "slide" that gets updated centrally and is broadcasted from there to all clients in the "room". As of now, we render the html to string and broadcast it to the clients. We also cache the html to be able to render later (ex. for a client upon page reload).

I see three options to do the same with Motion, but each seemingly having severe drawbacks:

Is Motion just not the solution here? Or did I miss a solution that may perform better?

caifara commented 4 years ago

In my opinion, the most logic thing to do is to broadcast rendered html (option 2), but be able to somehow ignore the rendered slide while serializing. Either by customizing the way serializing works per component or by adding one specific ivar like @ignored_state that behaves like a hash (and may need an api to set and get items like ignored_state(:slide_html).

Not only would it be important to ignore serializing those ivar(s), wouldn't these ivar(s) need resetting after render so garbage collection can free up some memory? It would be up to devs to create a backup system in case the state isn't available (using memoization).

On another note: could you elaborate on your intended goals with motion? It's really helpful to us and we see a future with a lot of use of it. That said, we're somewhat hesitant as the project could use extra marketing, documentation and support. We absolutely respect the fact that you don't owe us anything at all. It's just that, we would really like to bet on this tech and would want to know what your goals are.

latortuga commented 4 years ago

The way to solve this problem with Motion right now is your option 3. It's possible that it's not the right choice at the moment based on the fact that you think this would overwhelm server resources. But I won't rule out possibly supporting options 1 and 2.

The intended goals for motion are for it to support building rich frontend components with minimal or no js required. There are lots of different use cases there and I think currently we're open to supporting more.

I'm 100% with on the expanded marketing and documentation and it's something we know we need to work on.

alecdotninja commented 4 years ago

did I miss a solution that may perform better?

With the way Motion's public API works now, I think those are your options. If you're willing to risk breaking in the future, you could provide your own implementations for marshal_dump and marshal_load. Personally, I prefer the first option (cache the slide on the server and put the cache key in the state). This is the closest to "server side state" which is something that I would like to see added to Motion in the future.

In my opinion, the most logic thing to do is to broadcast rendered html (option 2), but be able to somehow ignore the rendered slide while serializing.

This has come up a few times now. I'm hopeful that we will be able to find a way to do things like this that does not involve allowing/denying state at the ivar level, but I'm not opposed to an API that would add support for this. Internally we already maintain a list of problematic ivars that come from the view state.

could you elaborate on your intended goals with motion?

Motion is a passion project for me. I'm still very interested in it and have no shortage of things that I would like to do, but my primary focus right now is settling into a new professional position.

Here are the things that I think need to be done and would like to do when I have the bandwidth/inspiration: