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

General discussion of stateless vs stateful components #25

Open
thorsten-de opened this issue Nov 10, 2021 · 2 comments
Open

General discussion of stateless vs stateful components #25

thorsten-de opened this issue Nov 10, 2021 · 2 comments

Comments

@thorsten-de
Copy link

thorsten-de commented Nov 10, 2021

Thanks for all the work going on here to build reusable components for live_view using Bulma.

Recently the new implementation of Panel replaced my own rather naive one, but a default slot is missing. Looking into it, the new Panel seems to be a stateful component handling switching tabs etc.

Since now I had the impression that most components in surface_bulma were intentionally stateless and focused on composing the structure needed to make use of Bulma properly.

Concerning Panel, it should work without any tabs at all, as they are optional, like multiple panel-blocks. And for handling tab switching, it has to be considered whether it is just an UI matter and could be done on the client (via apine.js, etc.) or if it requires behavior on the server (data fetching, etc) that should be handled by LiveView.

Imho, surface_bulma should enable both by keeping components as lean and stateless as possible by focusing on composing the presentation needed for Bulma. On top of that, there could be components that make use of these presentations to enable behaviours such as stateful tabs.

Another example would be a Dropdown component. I am working on an autocomplete component based on Bulmas Dropdown, because it is very flexible in displaying the content. In context of an autocomplete function it does make sense to handle state in my component, as there is open/closing the dropdown, a search string, fetching data, selecting an item, switching the trigger component from an input to a more beautiful representation of the item, etc.
But in general, if the Dropdown is just presenting a static bunch of information or links that are followed, a stateless component with properties setting the required classes ("is-active"/"is-hoverable") should be fine. So the component user has the choice how to toggle its state. And when properly thought out, it is easy to extend with stateful features.

Yet another example would be static tables vs interactive ones that enable sorting and such.

Sorry for writing that much, I just thought it would be wise to point out the direction of the library before we start implementing many components this way or the other.

The other point is that I'd probably wait until surface will work well with live_view >= 0.17 before diving into bulma components more deeply. The recent changes decenty messed up my development environment 😄

@justin-m-morgan
Copy link
Contributor

This is a very helpful point for my final work to be done on the pagination component. I had sort of come to this conclusion also, that it should be available as a stateless group of components but also had the idea of providing a configurable container version that did manage state. Any thoughts on that approach?

@Zurga
Copy link
Collaborator

Zurga commented Dec 12, 2021

I have no real objections with live components for things like modals or the Panel component. At least not until LiveView 0.17 is supported in Surface. A lot of the components are implemented as live components so I don't really believe the argument for 'intentionally stateless' holds up. Furthermore the live components do not use up another process, only more memory. I don't think performance is that big of an issue

Personally, I believe SurfaceBulma should make it easier for the person creating a website to write the code. If there is a performance issue with having a live component somewhere, it can always be made into a non live component by writing the markup in their project.

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

3 participants