Can not get access to class properties inside initialize function for custom element #2606
-
IntroductionI create my own element like below. In export class JointDevider extends dia.Element {
imageSelector = 'devider';
override markup: string | dia.MarkupJSON = deviderJsonMarkup;
override defaults(): Partial<dia.Element.Attributes> {
return {
...super.defaults,
type: 'itk.Devider',
attrs: {
root: {
magnetSelector: 'outline',
},
devider: {
width: 'calc(w)',
height: 'calc(h)',
cursor: 'move',
},
},
moveable: true,
};
}
override initialize(attributes?: dia.Element.Attributes | undefined, options?: any): void {
console.log(this);
console.log(this.imageSelector);
console.log(this.attributes);
super.initialize(attributes, options);
this.setState('NOT_INITED');
this.resize(50, 50);
}
setMoveable(val: boolean) {
this.prop('moveable', val);
}
setState(state: IIntDeviceState) {
console.log(this);
console.log(this.imageSelector);
console.log(this.attributes);
switch (state) {
case 'OK':
this.attr(`${this.imageSelector}/fill`, IntColors.Ok);
break;
case 'WARNING':
this.attr(`${this.imageSelector}/fill`, IntColors.Warning);
break;
case 'ERROR':
this.attr(`${this.imageSelector}/fill`, IntColors.Error);
break;
case 'NOT_INITED':
this.attr(`${this.imageSelector}/fill`, IntColors.NotInited);
break;
default:
canNotReach(state);
}
}
} Steps to reproduceNo response Restrictions & ConstraintsNo response Does your question relate to JointJS or JointJS+. Select both if applicable.JointJS |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You need to assign the values of the class properties inside the preinitialize method. export class JointDevider extends dia.Element {
imageSelector: string;
preinitialize() {
this.imageSelector = 'divider';
}
} For more info please see jashkenas/backbone#3560. |
Beta Was this translation helpful? Give feedback.
You need to assign the values of the class properties inside the preinitialize method.
For more info please see jashkenas/backbone#3560.