SAP / ui5-typescript

Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects
https://sap.github.io/ui5-typescript
Apache License 2.0
201 stars 28 forks source link

ts-types-esm Renderer(s) are not available #340

Closed nlunets closed 2 years ago

nlunets commented 2 years ago

When extending a control sometimes we rely on the same renderer as the parent to render code. However the renderer are not part of the officially availale content of the types. Is that something that could be considered ?

codeworrior commented 2 years ago

Renderers are by intention private. See recent statement here https://github.com/SAP/ui5-typescript/issues/293#issuecomment-1029931597 .

For concrete reuse requirements, please consider to open an issue on https://github.com/SAP/openui5. Control owners then have to decide whether they want to guarantee compatibility for their renderers or not (default currently is: not).

Closing this as a duplicate.

nlunets commented 2 years ago

Hmmm the use case is slightly different and maybe there is a way to write it that would be compatible :

Consider the following control

const MyControl = VBox.extend(
    "MyControl": {
        renderer: {
            apiVersion: 2,
            render: VBoxRenderer.render
        },
        extraThingsICareAbout + extension on the lifecycle method

would you consider this an unsafe usage ?

codeworrior commented 2 years ago

I see.

There are two ways to achieve this already:

a) Name the base render (depends on global names, might no longer be supported in future versions of UI5)

const MyControl = VBox.extend(
    "MyControl": {
        renderer: "sap.m.VBoxRenderer"
    }   
});

b) create the trivial subclass of the renderer (currently preferred)

const MyControl = VBox.extend(
    "MyControl": {
        renderer: {
            apiVersion: 2 // has to be set to indicate that this subclass complies with the contract, too
        }
    }   
});

In the back of my head, I'm in favour of a third way. Discussed it with @aborjinik a few times, but didn't find time to implement it yet.

const MyControl = VBox.extend(
    "MyControl": {
        renderer: "inherit"
    }   
});

P.S.: One might wonder why the most obvious solution "omit the renderer property" is not listed. Unfortunately, we "burned" the undefined value by giving it the meaning "derive renderer name from control name".