ui5-community / babel-plugin-transform-modules-ui5

A Babel transformer plugin for OpenUI5/SAPUI5. It allows you to develop UI5 applications by using the latest ECMAScript or TypeScript, including new syntax and objective oriented programming technology.
MIT License
34 stars 16 forks source link

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

Open GuillaumedesPommareSAP opened 1 year ago

GuillaumedesPommareSAP commented 1 year ago

Hello,

In our projects we always activate the feature moveControllerPropsToOnInit=true so that controls are assigned in onInitfunction 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.