Live data from Hacker News

Bubble Tea: fun, functional and stateful way to build terminal apps

github.com

1–10 of 116 posts

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#2
One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is that the model structure can only contain value type (e.g. no pointers, arrays, or maps).

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#3

One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is…

Just curious, I'm not familiar with Go. Will it copy the references anyway, meaning both structures now have a pointer to the same object? That's the way it works in other languages I'm familiar with, so you have to be careful about what you copy and how you use it.

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#4

One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is…

>One limitation of this is that the model structure can only contain value type (e.g. no pointers, arrays, or maps)

How does one manage dynamically sized lists of elements, if arrays are disallowed?

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#5

One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is…

Just curious, I'm not familiar with Go. Will it copy the references anyway, meaning both structures now have a pointer to the same object? That's the way it works in other languages I'm familiar with, so you have to be careful about what you copy and how you use it.

>Will it copy the references anyway, meaning both structures now have a pointer to the same object?

Correct. A value copy is a simple shallow copy. Deep copy requires use of reflection (if you don't want to manually manage copying).

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#6

One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is…

Just curious, I'm not familiar with Go. Will it copy the references anyway, meaning both structures now have a pointer to the same object? That's the way it works in other languages I'm familiar with, so you have to be careful about what you copy and how you use it.

yes, that's what it does in go

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#8

One thing that I like about this is the implementation of returning state from the Update function. My only experience with Elm-style architecture is with react / redux which involves meticulously copying pieces of the state object to return two distinct before / after states. Using a Go struct with copy semantics makes this extremely easy and more natural to write in an imperative fashion. One limitation of this is…

Just curious, I'm not familiar with Go. Will it copy the references anyway, meaning both structures now have a pointer to the same object? That's the way it works in other languages I'm familiar with, so you have to be careful about what you copy and how you use it.

Yes, but it doesn't actually matter. You can use pointers for models, return the same pointer, and it will re-render fine. We do this for our CLI at https://www.inngest.com for creating new serverless functions via a quick walkthrough.

It's actually the `tea.Msg` that causes re-renders. Here's the code: https://github.com/charmbracelet/bubbletea/blob/v0.20.0/tea.....

tea.Msg is, in Redux land, an "action" that triggers some state updates and _always_ triggers a re-render, even if nothing changes.

This is elm-like, but we have to understand the limitations of what we're working with: a terminal with no way of (nicely) updating elements in place. It's essentially an immediate-mode UI, and so it always paints.

Re: Bubble Tea: fun, functional and stateful way to build terminal apps

#10
post #7

One of my favorite TUI frameworks. I made https://github.com/mathaou/termdbms with it. A very pleasant experience.

That looks pretty cool, but as most/all DBMSs come with a TUI utility*, what is the advantage?

*(psql, sqlplus, isql, etc....)

Post reply on HN