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

feat: Computed values and state management #185

Closed
2 tasks done
adsonpleal opened this issue Aug 22, 2023 · 2 comments
Closed
2 tasks done

feat: Computed values and state management #185

adsonpleal opened this issue Aug 22, 2023 · 2 comments
Labels

Comments

@adsonpleal
Copy link

Description

Have you ever thought about computed values and state management? While diving into the Mirai project, I noticed something was missing – the ability to create and manage your own states. I'm not entirely sure if skipping this feature was intentional, but I decided to take a shot at it and came up with a solution in this POC pull request.

The core idea is to allow the creation of states for your screen, similar to the classic counter app.

I've introduced a fresh concept called Computed Value to Mirai's engine. This concept revolves around performing calculations in runtime. To go hand in hand with this, I've also added a new action named MiraiSetStateAction, that, as the name implies, sets the state value.

To handle states effectively, I had to write a MiraiStateHolder InheritedWidget. This widget lets the widgets in the subtree access the state through context. Now, I've noticed you've used Cubit in certain areas, and we could have gone that route here. However, given the simplicity of the task at hand, an InheritedWidget seemed like the right tool for the job.

And as for the "computed" part, I've whipped up three simple parsers to showcase the concept: MiraiComputedToString, MiraiComputedSum, and MiraiComputedState. But the concept is extensible, so we can have any kind of runtime computation.

computed-example.mp4

Do you think this idea aligns well with the project's goals?

Requirements

  • State management
  • Computed values engine
@RodolfoSilva
Copy link
Contributor

Hello @adsonpleal i think this maybe this could be achieved using the "signal" (#164) and with a custom action. What do you think?

@i-asimkhan is working in the "signal" feature.

@adsonpleal
Copy link
Author

Hello @adsonpleal i think this maybe this could be achieved using the "signal" (#164) and with a custom action. What do you think?

@i-asimkhan is working in the "signal" feature.

@RodolfoSilva totally! Maybe it is better to keep it simple, adding this new concept could create confusion. Closing this issue in favor of signal.

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

No branches or pull requests

2 participants