में एब्स्ट्रक्शन मैं अपने प्रतिक्रिया घटकों के निर्माण में कुछ अमूर्तता का उपयोग करना चाहता हूं। उदाहरण के लिए:React.js
class AbstractButton extends React.Component {
render() {
return (
<button
onClick={this.props.onClick}
className={this.definitions.className}>
{this.props.text}
</button>
}
}
class PrimaryButton extends AbstractButton {
constructor(options) {
super(options);
this.definitions = {
className: 'btn btn-primary'
};
}
}
class SuccessButton extends AbstractButton {
constructor(options) {
super(options);
this.definitions = {
className: 'btn btn-success'
};
}
}
मैं props
के माध्यम से इन definitions
पारित करने के लिए है क्योंकि मुझे पता है कि इन definitions
इस मामले --in class
कभी नहीं बदल --will नहीं करना चाहती।
क्या यह प्रतिक्रिया में एक विरोधी पैटर्न है? या यह ठीक है?
मेरा प्रश्न this altjs issue को संदर्भित करता है: इस तरह का अमूर्त @connectToStores
के साथ संगत नहीं है।
प्रतिक्रिया विरासत की बजाय संरचना पर ध्यान केंद्रित करती है, लेकिन आपका कोड मेरे लिए बुरा नहीं लग रहा है। – christopher
हां, इसे आम तौर पर एक विरोधी पैटर्न माना जाता है। यहां इसके बारे में एक दिलचस्प लेख है: https://medium.com/@dan_abramov/how-to-use-classes-and-sleep-at-night-9af8de78ccb4 –