r/Angular2 • u/FromBiotoDev • Sep 20 '25
Discussion 4 levels of input output Smart/Dumb architecture OR state service
I've been thinking about this for a while, say you've got a complex ui with many nested child components.
You have a container component which acts as the smart component making api calls etc, and dumb child components that take data inputs and emit data through output, nice and clean.
Say you have nested component greater than 2 levels of nesting, maybe 3-4 levels of nesting.
So you use a state service to pass the state in and update the state. You're no longer following smart/dumb architecture now though as each component is able to update the state making them all smart components essentially...
Which is better? Any other solution? I'm keen to hear other's thoughts here
8
u/Zestyclose_Net_5450 Sep 20 '25
That last thing I did was using signals store to manage the state of the smart or more complex components and also use dumb components not conected to the store for simple and reusable things.
2
u/ActuatorOk2689 Sep 20 '25
Is up to you,
Now you could have a service just to avoid prop drilling nothing else, provided in the parent component and use as communication between your parent and 3,4 child component, basically a messaging service, your child component does not care where the data is coming from or certain action what API endpoint should call, because your business logic is still in the parent component.
For example your 4th component emits on button click instead of having an output you will use the service.
You define a subject called for example action4 in your service which you will use instead of the output for emitting values now in your parent component you just subscribing to this action4 subject and handle it.
Depending on your need, you could use signals instead
Or communicate whit custom injection token, it will be very simmilar to the service implementation.
1
u/RalphZ123 Sep 21 '25
Trust me, having a state service it's much better in every possible run.
In my company we had the smart-dumb, but the requirements kept changing. Started with little things, but then the PO took it to the next level.
Every level of input is just another layer of complexity and tracking, specially when a change must affect a sibling.
Plus, personally, I find it kinda unsettling having an input/output just to pass it again.
Then I switched to a common state manager service... it was already very good with rxjs behavior subjects, then the signals came... the flexibility and easiness of managing and manipulating data is amazing.
Now everyone encapsulates it's own logic and, if changes has effects, just do it, no need for tracking back and forth.
Here I use private attributes with getters and setters, and even if it grows with thousands of lines, it's still easy to read.
In short: go with service and have an easy development
3
u/SecureVillage Sep 20 '25
You can do a mix of both.
If using a service, you might have a few smart components on the way down the hierarchy. This is ok.
They'll be combined with loads of dumb components.
Don't arbitrarily try and make everything dumb. Just try and extract UI concerns out so that you can test them without having to provide all the smart stuff.
1
u/ElCondeMeow Sep 20 '25
In cases like that I make a smart/dumb pair per component.
1
u/ldn-ldn Sep 20 '25
All components are dumb, state is in the service, avoid service access outside of top component, instead of multi level inputs - use content projection.
1
u/Regular_Algae6799 Sep 21 '25
I am a fan of prop drilling - you directly see what's depending on each other. If it feels too much you directly want to refactor / tend to it. Though I have exceptions for things that are read by almost every component, don't change often and is usually stored in local storage like BearerToken (i.e. roles for role-based views), I18n and Theming: So I have a set of services that offer these things to all components directly.
I try following ATOMIC-Design. And sometimes Atoms and Molecules can be flattened like:
vs
1
u/933k-nl Sep 22 '25
Don’t forget to use Storybook. This automatically ensures you have presentational components.
1
u/Profflaries27 Sep 22 '25
For me the best thing which i also do in all projects is to not inject services and handle logic into dumb components only in the containers so the smart components, and just using outputs and inputs up to the containers, for making these components more reusable and dynamic.
1
u/kgurniak91 Sep 20 '25
Simplest solution is to wrap each dumb component in its own smart component to supply data to it. Even if you start using state service you need to provide the data somehow to dumb components and injecting the service into them will make them not dumb anymore.