Coder Social home page Coder Social logo

Comments (4)

sudoevans avatar sudoevans commented on June 12, 2024 1

@ksyro98 Thank you for answering this.

from bloc.

ksyro98 avatar ksyro98 commented on June 12, 2024 1

Hey, these diagrams are very different from the initial one, because there aren't two layers of Blocs and no Bloc depends on another Bloc. (That's good!)

In the two versions that you sent the main change seems to be that the ViewClientBloc is split in two Blocs. I believe that whether this is a good idea or not depends on what that Bloc does, and is not specific to the BLoC architecture.

The Single-Responsibility Principle comes to mind: "A module should be responsible to one, and only one, actor." If that Bloc is responsible to more than one actors (user group/stakeholder group) or if there is more than one reason to change, perhaps breaking it into two is a good idea.

Which widget will depend on the Bloc isn't that important. I think it's actually better to have a BlocBuilder (or similar widget) lower in the widget tree to avoid unnecessary rebuilds. (And the widget that includes the BlocProvider will depend on the Bloc anyways.)

Creating a different module for the grouped classes has to do with your enterprise architecture. Do keep in mind that, if your grouped classes (cmp, bloc, repository) are in one module and the BlocProvider is separate from it; the module will need to expose the Bloc which in that case will be an implementation detail. I believe that a widget which includes a BlocBuilder and the widget UI can be adequately reused. That being said, do keep in mind that you know your enterprise's code much better than me.

from bloc.

ksyro98 avatar ksyro98 commented on June 12, 2024

Hey!

No this is not considered a best practice. In general you want to have one Bloc/Cubit for each feature (which usually means one Bloc per page).

For your situation, if you haven't included DataProviders already they might help you. You might be able to move most of the Repository logic to the DataProviders and then use the Repository as the middle layer. This is actually consistent with the Bloc architecture: https://bloclibrary.dev/architecture/

If you already have DataProviders defined, you might be able to use helper classes that will contain the code that is shared by more than one Blocs

from bloc.

chedwin41 avatar chedwin41 commented on June 12, 2024

Hello, thank you for your response.

I'd like to provide some additional details about our situation and our objectives. We have common widgets that are shared across different views and even applications. From my understanding, the preferable approach should resemble the following:

image
image

(In these diagrams, the orange components are the ones being reused).

What we have experimented with is depicted below:

image
image

In this model, blocs are still organized by feature but are utilized in multiple subwidgets that require these blocs to function correctly. This strategy facilitates the sharing of widgets between views without the need to propagate properties through numerous subcomponents.

Additionally, each component manages its own loading state based on the bloc it relies on. For instance, some components in my view that utilize the product bloc can display product details, etc., while the stock indicator might not load. This loading behavior is managed within each individual featured component.

This approach feels akin to assigning one bloc per feature, yet each feature is utilized by multiple components.

from bloc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.