-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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: update BlocBuilder and BlocListener to use a deps API for simpler state comparisons #4295
Comments
Hi @ricardodalarme 👋 I highly recommend using Let me know if |
I don't think The proposal would imo bring a better balance between flexibility, speed (in terms of unnecessary widget builds) and clean code. It also looks a bit like React's |
I completely agree with @h3x4d3c1m4l's. Using I've been using Bloc in professional projects for over three years now, and I’ve rarely seen Additionally, my proposal extends beyond just Instead, I’d suggest considering the opposite approach: deprecate Let me know your thoughts! I’d love to keep the discussion going. 🙏 |
Can you please share some real-world code samples to help me better understand? I don't fully understand why you'd want to be watching/rebuilding in response to properties on a state that aren't directly rendered in the UI.
React's useEffect is actually quite problematic in my opinion. It gets misused all the time and can cause subtle/hard to debug issues. I would love to better understand what use-cases you have in mind that require a |
The generics should generally be able to be inferred so that you don't need to explicitly specify the three types. In addition, you can use
That's likely because
Can you please share some real-world code snippets that illustrate how you use
As I mentioned above, Regarding the unified API, we'd also deprecate and remove
Looking forward to hear back and learning more about your specific use-cases, thanks! 🙏 |
Description
One thing that’s always been a bit frustrating when working with
BlocBuilder
andBlocListener
is how verbose thebuildWhen
function can get. For example, if you need to rebuild the widget only when specific parts of the state change, you end up writing something like this:While this works, it can quickly become tedious and hard to read, especially as the state grows more complex. It feels like there’s room for improvement to make this cleaner and more intuitive.
Desired Solution
It would be great if we could replace the
buildWhen
function with adeps
parameter that takes a function to define the specific parts of the state we care about. The library would then handle comparing these properties under the hood. Here's what it could look like:Internally, the Bloc library could:
deps
with both theprevious
andcurrent
state.This would make the code much more readable and concise while keeping the same level of flexibility.
On top of that, adding a lint rule to encourage proper use of
deps
would be a nice touch. For example, it could check that all the necessary fields are included indeps
or flag unused fields in the state.Potential Challenges
deps
handles mutable lists correctly to avoid issues with false positives or negatives.buildWhen
logic still works as expected.The text was updated successfully, but these errors were encountered: