babel-plugin-transform-modules-ui5 icon indicating copy to clipboard operation
babel-plugin-transform-modules-ui5 copied to clipboard

Allow feature `moveControllerPropsToOnInit` to be overriden with a local annotation, per declaration

Open GuillaumedesPommareSAP opened this issue 1 year ago • 0 comments

Hello,

In our projects we always activate the feature moveControllerPropsToOnInit=true so that controls are assigned in onInit function time so that their programmatic configuration is possible.

But some UI5 patterns, like formatters in our case, would require an exception. A formatter pattern as UI5 expects it is defined in a formatter variable defined in the controller. Of course they are other ways of defining it, but this is one of the most convenient, a lot more than core:require of functions. In TypeScript, this would look like :

@namespace("ccCockpit.tree.node.comparator.timeSlot.controller")
export default class ElseController extends DisplayBaseController {

    public formatter = {
        formatElseMessageStrip
    };

    constructor(name: string | object[]) {
        super(name);
    }
}

Control in View: <MessageStrip text="{parts: ['Node>/property/key', {value: 'valueCategory_i18n'}], formatter: '.formatter.formatElseMessageStrip'}" />

Issue: doing so is most probably the better way of writing a formatter, it is aligned with UI5 coding conventions, samples ... but assignment code is moved to onInit and it looks to be late for UI5 binding when creating the control, and formatter remains undefined in the control's binding

So maybe a feature like:

   @movePropsToConstructor
    public formatter = {
        formatElseMessageStrip
    };

Could help in such situation.

GuillaumedesPommareSAP avatar Sep 20 '23 17:09 GuillaumedesPommareSAP