Reputation: 23247
I'm trying to build a parent component with several dumped sub-components.
I don't quite figure out how design my dump sub-components. Theorically, each sub-component has to receive all data using @Input
fields. So:
@Component({
selector: '[payment-list]',
...
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PaymentList {
@Input() payments$: Observable<ISource>;
What I'm trying to get using this input field is to list all payments are in payments. This is my IStore
:
export interface IStore {
user: IUser;
plans: IPlanRedux;
sources: ISourceRedux;
errors: IError;
}
export interface ISource {
id: string;
type: string;
customer: string;
}
export interface ISourceRedux {
byId: { [key: string]: ISource };
allIds: Array<string>;
}
Parent component builds an Observable<ISource>
using this:
private sources$: Observable<ISource>;
constructor(private store$: Store<IStore>) {
this.sources$ = this.store$
.select(fromRoot.getSourceEntities);
}
So, into my parent.template.html
:
<div payment-list></div>
@Input
fields? So, how could I send the parent observable to the dumped component? Is it correct?Observables
and use them?Upvotes: 0
Views: 1546
Reputation: 609
Your sub-component dont need a stream for that it only need the ISource object to function.
@Component({
selector: '[payment-list]',
...
changeDetection: ChangeDetectionStrategy.OnPush
})
export class PaymentList {
@Input() payments: ISource;
private sources$: Observable<ISource>;
constructor(private store$: Store<IStore>) {
this.sources$ = this.store$
.select(fromRoot.getSourceEntities);
}
<payment-list payments="sources$ | async"></payment-list>
This approach makes your sub-component dumb in the way that it does not need to be aware of the store
Upvotes: 2