If I don’t call this.execute() in render() but call this.execute() in initialise and refresh, then the class properties set in execute won’t work.
For example, the following code (written in TypeScript, but does not affect reading):
But I printed some logs and found that execute and initialise in update do get called, and before render; also, if I print this and this.value1 in update, I find that value1 in this does change, but this.value1 does not.
import { TWElement, IParseTreeNode, IWidgetInitialiseOptions } from 'tw5-typed';
import { widget as Widget } from '$:/core/modules/widgets/widget.js';
class TestWidget extends Widget {
value1: string = '1';
value2: string = '3';
execute() {
this.value1 = '2';
}
initialise(parseTreeNode: IParseTreeNode, options: IWidgetInitialiseOptions) {
super.initialise(parseTreeNode, options);
this.computeAttributes();
this.execute();
}
update() {
this.computeAttributes();
this.execute();
}
render(parent: TWElement, nextSibling: TWElement) {
this.value2 = '4';
this.domNodes.push(
parent.insertBefore(
$tw.utils.domMaker('div', { text: `value1:${this.value1}, value2:${this.value2}` }),
nextSibling,
),
);
}
}
exports['test-widget'] = TestWidget;
and Use it(<$test-widget>), with the content of value1:1, value2:4.
- core version: v5.2.5
- test-widget: test-widget.tid (934 Bytes)