fix(component): bug when extending legacy notation#570
fix(component): bug when extending legacy notation#570
Conversation
|
TODO: need to ponder this more, but the solution may be to refactor out all legacy notation so that the className can be overwritten when using the condensed notation. As you can see using the condensed notation when extending a component using the condensed notation works. |
|
As suspected, the condensed notation cannot be mixed with the legacy notation as the order of instantiation of let n = 0;
const prefixString = (prefix) => {
console.log(prefix, ++n);
return `${prefix}${n}`;
}
class Component {
className = 'Component';
constructor(className) {
this.className = className;
}
}
class DerivedComponent extends Component {
className = prefixString('DerivedComponent');
}
class DerivedDerivedComponent extends DerivedComponent {
constructor() {
super(prefixString('DerivedDerivedComponent'))
}
}
console.log((new DerivedDerivedComponent()).className)In this example If you look closer at the output of the this is because: constructor() {
super(prefixString('DerivedDerivedComponent'))
}is executed before: className = prefixString('DerivedComponent');which means that The key to achieving our desired behavior is to only set a class Component {
constructor(className) {
this.className = className ? className : 'Component';
}
}
class DerivedComponent extends Component {
constructor(className) {
super(className ? className : 'DerivedComponent')
}
}
class DerivedDerivedComponent extends DerivedComponent {
constructor() {
super('DerivedDerivedComponent')
}
}With this, |
|
For now, opting not to support a |
The new condensed notation doesn't work when you extend a component with the legacy notation. This issue was detected by redgeoff/mson-react#316