Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

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

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. ).

question from:https://stackoverflow.com/questions/65833663/spartacus-best-practise-to-add-some-details-in-existing-component-where-outlet

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...