Spartacus | Best practise to add some details in existing component where outletRef not available

Viewed 141

This question is more on best practise for including some more details in existing component where outlet ref is not available.

For ex. In checkout, during review-order step, I need to add some custom details with delivery-mode and i want to use the complete component as is.

Do i need to

  • copy all the html & component logic from spartacus code
  • create my custom component and use all copied code
  • add the little detail with my delivery mode section
  • replace the existing component by my custom component using COMPONENT as outlet-ref

There is lot of duplicate code to implement this.

Is there a better way like just inherit all the component detail by importing the component in my module and override the specific section (i am not sure but i was thinking that would be helpful. ).

1 Answers

Here is what I would do:

  • create new component
  • copy all the html from spartacus to this component
  • extend the original component instead of copying all the logic
  • replace component in configuration

We're working on better way to extend templates, but that's not gonna be available soon. In the approach I recommended when updating spartacus you would only need to validate if the template changed, as the component logic will be automatically updated when you extend it.

Related