You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/Best_Practices_for_Developers_28fcd55.md
+15-16Lines changed: 15 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,9 @@ Some APIs may be only partially deprecated, for instance passing a non-object `v
90
90
91
91
- Use `sap.ui.require` for requiring an existing module.
92
92
93
-
- Add only valid module IDs from the API Reference \(documented as `Module: .../.../..`\) to the dependency list. For example, use `sap/m/library` for `sap/m/SortOrder`, and require `sap/ui/model/FilterType` as it's a genuine module \(`Module: sap/ui/model/FilterType`\).
93
+
- Add only valid module IDs from the API Reference \(documented as Module: .../.../..\) to the dependency list. For example, use `sap/m/library` for the enum type `sap.ui.core.SortOrder`.
94
+
95
+
For the enum type `sap.ui.model.Filter`, however, require `sap/ui/model/FilterType` as it's a genuine module \(Module: `sap/ui/model/FilterType`\).
94
96
95
97
96
98
<table>
@@ -135,7 +137,7 @@ Some APIs may be only partially deprecated, for instance passing a non-object `v
135
137
```js
136
138
sap.ui.define([
137
139
"sap/m/library", // target use: SortOrder
138
-
"sap/ui/model/FilterType" // remains same
140
+
"sap/ui/model/FilterType", // remains same
139
141
"sap/ui/layout/form/SimpleForm"
140
142
], (sapMLib, FilterType, SimpleForm) => {
141
143
"use strict";
@@ -167,7 +169,7 @@ Some APIs may be only partially deprecated, for instance passing a non-object `v
167
169
168
170
**Third-Party Libraries**
169
171
170
-
When requiring third-party libraries that exportglobalnamesandsupportAMDatthesametime, ensurehavinga`shim`with`amd:true`definedvia [`sap.ui.loader.config`](https://sdk.openui5.org/api/sap.ui.loader%23methods/sap.ui.loader.config) beforehand. Use the required module value instead of the global name of the third-party lib.
172
+
When requiring third-party libraries that exportglobalnamesandsupportAMDatthesametime, ensurehavinga`shim`with`amd:true`definedvia [`sap.ui.loader.config`](https://sdk.openui5.org/api/sap.ui.loader%23methods/sap.ui.loader.config) beforehand. Use the required module value instead of the global name of the third-party library.
171
173
172
174
**Troubleshooting**
173
175
@@ -190,7 +192,7 @@ In the following we'll focus on crucial aspects of app development, specifically
190
192
#### Asynchronous Loading
191
193
192
194
- Use asynchronous loading for views, fragments, and components to enhance performance; see, for example, [Legacy Factories Replacement](Legacy_Factories_Replacement_491bd9c.md).
193
-
- Implement the `sap.ui.core.IAsyncContentCreation` marker interface in your [Component.js File](Component_js_File_27ce0e4.md) to allow the content to be created fully asynchronously and for a stricter handling of certain types of errors during its view processing.
195
+
- Implement the `sap.ui.core.IAsyncContentCreation` marker interface in your [Component.js file](Component_js_File_27ce0e4.md) to allow the content to be created fully asynchronously and for a stricter handling of certain types of errors during its view processing.
194
196
- Load libraries via the new asynchronous APIs in advance before accessing code. Ensure that dependent librares are preloaded through the `manifest.json` in the `sap.ui5/dependencies/libs` section if not already maintained there. For more information, see [Ensure that Library Preloads are Enabled](Performance_Speed_Up_Your_App_408b40e.md#loio408b40efed3c416681e1bd8cdd8910d4__section_LibraryPreloads).
195
197
196
198
**Additional Information:**
@@ -253,7 +255,7 @@ When creating instances of OpenUI5 controls programmatically \(i.e. not declarat
253
255
254
256
- Don't use the section `sap.ui5/resources/js` as it's deprecated. Use regular dependencies in the `Component.js` file instead.
255
257
256
-
- Unless the component intends to load specific OpenUI5 libs manually on demand, avoid adding `{ lazy: true }` to the `sap.ui5/dependencies/libs` section.
258
+
- Unless the component intends to load specific OpenUI5 libraries manually on demand, avoid adding `{ lazy: true }` to the `sap.ui5/dependencies/libs` section.
257
259
258
260
259
261
**Dependency Management**
@@ -285,7 +287,7 @@ Prevent bundling modules \(`Component-preload.js`\) into strings.
285
287
286
288
- Use the `loadFragment` method of the `sap.ui.core.mvc.Controller` to load fragments asynchronously.
287
289
288
-
-XML Templating:Don't use global names. Ensure that the target function or object is defined as a module and require the defined module via [`core:require` in the XML](Require_Modules_in_XML_View_and_Fragment_b11d853.md). Use `template:require` if the XML content needs preprocessing.
290
+
- Don't use global names in your XML. Ensure that the target function or object is defined as a module and require the defined module via [`core:require` in the XML](Require_Modules_in_XML_View_and_Fragment_b11d853.md). Use `template:require` if the XML content needs preprocessing.
- Ensure a dependency on the renderer or embed it within the control class.
351
353
352
-
- Migrate to the rendering `apiVersion 2` or `apiVersion 4`.
354
+
- Migrate to the rendering `apiVersion 2` or `apiVersion 4`.For more information, see the [API Reference](https://sdk.openui5.org/api/sap.ui.core.RenderManager%23overview) .
353
355
354
356
- When utilizing [`RenderManager#icon`](https://sdk.openui5.org/api/sap.ui.core.RenderManager%23methods/icon) during rendering, include a dependency to `sap/ui/core/IconPool` in your code.
355
357
356
-
- Don't use `Control.prototype.rerender` to rerender a control as it's deprecated. Use [`Control.prototype.invalidate`](https://sdk.openui5.org/api/sap.ui.core.Control%23methods/invalidate) instead.
357
-
358
-
- If you want to be informed once a control's rerendering is triggered, override `Control.prototype.invalidate`.
358
+
- Don't use `Control#rerender` to rerender a control as it's deprecated. Use [`Control#invalidate`](https://sdk.openui5.org/api/sap.ui.core.Control%23methods/invalidate) instead.
- Don't use `sap.ui.getCore().initLibrary` to initialize the library as it's deprecated. Use the import of `sap/ui/core/Lib.js` and call its [`Lib.init()`](https://sdk.openui5.org/api/sap.ui.core.Lib%23methods/sap.ui.core.Lib.init) instead.
376
+
- Don't use `sap.ui.getCore().initLibrary` to initialize the library as it's deprecated. Use the import of `sap/ui/core/Lib` and call its [`Lib.init()`](https://sdk.openui5.org/api/sap.ui.core.Lib%23methods/sap.ui.core.Lib.init) instead.
377
377
378
378
- Don't use the global namespace of the library to add types. Use the return value of `Lib.init` instead to add them.
- Define the `appData/manifest/i18n` section in the `.library` file or the `sap.app/i18n` section in the `manifest.json`, so that the framework can load resource bundles in advance.
385
385
386
-
- Properly define library dependencies in all places where it is required.
386
+
- Properly define library dependencies in all places where it is required. For more information, see [Dependencies to Libraries](Descriptor_Dependencies_to_Libraries_and_Components_8521ad1.md#loio8521ad1955f340f9a6207d615c88d7fd__section_DEPLIB)
- Prevent bundling modules \(`Component-preload.js`\) into strings.
400
-
401
-
- Avoid generating the application bundle with an outdated standard Grunt task. LeverageUI5 Tooling to build the bundle.
399
+
Prevent bundling modules \(`Component-preload.js`\) into strings.
402
400
403
-
- Avoid declaring `var`, `let`, or `const`in the global scope above `sap.ui.define`.
401
+
-Avoid generating the application bundle with an outdated standard Grunt task. Leverage UI5 Tooling to build the bundle.
404
402
403
+
- Avoid declaring `var`, `let`, or `const` in the global scope above `sap.ui.define`.
405
404
406
405
- For third-party libraries, set `requiresTopLevelScope="false"` to the `/library/appData/packaging/raw-module` tag within the `.library` file, **provided that** the third-party library is allowed to be bundled together and does not require access to the global scope. Otherwise, consider [excluding the third-party library from the bundle](https://sap.github.io/ui5-tooling/v3/pages/Configuration/#excludes_1).
Copy file name to clipboardExpand all lines: docs/Dates_Times_Timestamps_and_Time_Zones_6c9e61d.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,15 +24,15 @@ When talking about dates, times, or timestamps, we'll use the following definiti
24
24
> -`Date#getTime` returns a timestamp and not a time in our terminology,
25
25
> -`Date#getDate` returns only the day of a date and not the entire date.
26
26
27
-
The intermediate client-side processing of these entities typically uses the JavaScript `Date` object, which represents a timestamp. This may cause issues if dates are used and time zone handling comes into play. Typically, timestamps are displayed in the time zone of the browser. It is also possible to display a timestamp in a different time zone, for example in the `America/New_York` time zone, by using [`sap.ui.model.odata.type.DateTimeWithTimezone`](https://sdk.openui5.org/api/sap.ui.model.odata.type.DateTimeWithTimezone) or [`sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance`](https://sdk.openui5.org/api/sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance).
27
+
The intermediate client-side processing of these entities typically uses the JavaScript `Date` object, which represents a timestamp. This may cause issues if dates are used and time zone handling comes into play. Typically, timestamps are displayed in the time zone of the browser. It is also possible to display a timestamp in a different time zone, for example in the `America/New_York` time zone, by using [`sap.ui.model.odata.type.DateTimeWithTimezone`](https://sdk.openui5.org/api/sap.ui.model.odata.type.DateTimeWithTimezone) or [`sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance`](https://sdk.openui5.org/api/sap.ui.core.format.DateFormat%23methods/sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance).
28
28
29
-
For testing purposes, you can use the `sap-timezone` URL parameter to switch from the browser's time zone to any provided time zone. For example, with `?sap-timezone=Pacific/Honolulu` the Honolulu time zone \(GMT-10:00\), and with `?sap-timezone=Pacific/Kiritimati` the Kiritimati time zone \(GMT+14:00\) is used for formatting and parsing timestamps, except for the timestamps that are formatted or parsed with [`sap.ui.model.odata.type.DateTimeWithTimezone`](https://sdk.openui5.org/api/sap.ui.model.odata.type.DateTimeWithTimezone) or [`sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance`](https://sdk.openui5.org/api/sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance).
29
+
For testing purposes, you can use the `sap-timezone` URL parameter to switch from the browser's time zone to any provided time zone. For example, with `?sap-timezone=Pacific/Honolulu` the Honolulu time zone \(GMT-10:00\), and with `?sap-timezone=Pacific/Kiritimati` the Kiritimati time zone \(GMT+14:00\) is used for formatting and parsing timestamps, except for the timestamps that are formatted or parsed with [`sap.ui.model.odata.type.DateTimeWithTimezone`](https://sdk.openui5.org/api/sap.ui.model.odata.type.DateTimeWithTimezone) or [`sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance`](https://sdk.openui5.org/api/sap.ui.core.format.DateFormat%23methods/sap.ui.core.format.DateFormat.getDateTimeWithTimezoneInstance).
30
30
31
31
> ### Caution:
32
32
> If you use a configured time zone, **your application may break** if it uses the JavaScript `Date` object in combination with functions that use the local browser time zone, for example `oDate.getHours()` or `oDate.getDate()`. To avoid such issues, we strongly recommend the following approach:
33
33
>
34
34
> - Use data binding with the corresponding OpenUI5 OData types wherever possible in your application.
35
-
> - Always use [`UI5Date.getInstance`](https://sdk.openui5.org/api/module:sap/ui/core/date/UI5Date/methods/sap/ui/core/date/UI5Date.getInstance) to create new date instances. For more information, see the [UI5Date section](Dates_Times_Timestamps_and_Time_Zones_6c9e61d.md#loio6c9e61dc157a40c19460660ece8368bc__section_ui5date) below.
35
+
> - Always use [`UI5Date.getInstance`](https://sdk.openui5.org/api/module:sap/ui/core/date/UI5Date%23methods/sap/ui/core/date/UI5Date.getInstance) to create new date instances. For more information, see the [UI5Date section](Dates_Times_Timestamps_and_Time_Zones_6c9e61d.md#loio6c9e61dc157a40c19460660ece8368bc__section_ui5date) below.
36
36
37
37
This topic describes the different OData Edm types and the corresponding OpenUI5 data type, how to display timestamps in a specific time zone, a list of best practices for handling timestamps, dates, and times in OpenUI5, and a list of common pitfalls.
0 commit comments