
$> git clone https://github.com/vobu/ui5-webcomponents-showcase
$> cd ui5-webcomponents-showcase
# yarn needed
$> yarn
$> yarn start
# ... build output ...
# ... finished!
# point browser to
# http://localhost:9081/index.html and
# http://localhost:9082/index.html
<glass raised content="beer">🍺</glass>
<div id="__hbox6" data-sap-ui="__hbox6"
class="sapMFlexBox sapMHBox sapMFlexBoxJustifyStart
sapMFlexBoxAlignItemsCenter sapMFlexBoxWrapNoWrap
sapMFlexBoxAlignContentStretch sapMFlexBoxBGTransparent
sapUiTinyMargin sapMFlexItem">
<div id="__data30" class="sapMFlexItemAlignAuto sapMFlexBoxBGTransparent sapMFlexItem"
style="order: 0; flex-grow: 0; flex-shrink: 1; flex-basis: auto; min-height: auto;
min-width: auto;">
<span id="__text5" data-sap-ui="__text5" class="sapMText sapUiSelectable sapMTextMaxWidth"
style="text-align: left;">🍺</span>
</div>
</div>
<!-- div div div, the train arrives, as we used to say 🙂 -->
ui5
prefix:<ui5-datepicker></ui5-datepicker>
Shadow DOM
and ES Modules
, as e.g. explained on https://www.webcomponents.org/introduction - but let’s leave it at that and just acknowledge:sap.ui.core.Control
is extended as custom element ui5webc.Item
:sap.ui.define(["sap/ui/core/Control"], Control => {
return Control.extend("ui5webc.Item", {
// ...
})
})
sap.ui.define(["sap/ui/core/Control"], Control => {
return Control.extend("ui5webc.Item", {
metadata: {
properties: {
// mapped to <ui5-li>$text</ui5>
text: { type: "string", defaultValue: "" }
}
}
// ...
})
})
sap.ui.define(["sap/ui/core/Control"], Control => {
return Control.extend("ui5webc.Item", {
metadata: {
properties: {
// mapped to <ui5-li>$text</ui5>
text: { type: "string", defaultValue: "" }
}
},
renderer: {
apiVersion: 2, // high-perf!
/**
* renders as <ui5-li>some content here</ui5-li>
* @param {sap.ui.core.RenderManager} oRM - UI5's render manager
* @param {ui5webc.Item} oLI - this UI5 custom control
*/
render(oRM, oLI) {
oRM.openStart("ui5-li", oLI)
oRM.openEnd()
oRM.text(oLI.getText()) // see metadata property "text" above
oRM.close("ui5-li")
}
}
})
})
Note theapiVersion: 2
as part of the renderer declaration!
It instructs the Rendering Manager to enable in-place DOM patching, massively improving rendering performance.
UI5 architect Cahit Gürgüc gave a talk on this at UI5con 2019 - ever since he implemented it into UI5’s core,apiVersion: 2
should always be used when developing custom controls!
<mvc:View controllerName="test.Sample.controller.Main"
xmlns:webc="ui5webc"> <!-- declare a namespace -->
<!-- ... -->
<!-- UI5 Web Component with data binding, yay! -->
<webc:Item text="{Backend>boundProperty}" />
</mvc:View>
─── packages
├── ui5-app-webcomponents
├── ui5-app-xmlcontrols
└── ui5-webcomponents-lib
ui5-app-xmlcontrols
),ui5-app-webcomponents
)ui5-webcomponents-lib
with the bespoken "custom web component controls". The library is used in the web component's app and set up for further development.yarn start
in /
of the repository first builds the UI5 library, then starts two local UI5 tooling servers: http://localhost:9081/index.html for the regular UI5 controls, http://localhost:9082/index.html for the UI5 Web Components; both including OData v4- + REST-bindings.rollup
is used to createa a custom bundle in ui5-webcomponents-lib/dist/resources/$libraryName/lib/bundles.js
consisting of:ui5-webcomponents
specified in ui5-webcomponents-lib/lib/bundle.js
ui5-webcomponents-lib/src/ui5webc
ui5 build $library
is used to create ...well… a UI5 library in ui5-webcomponents-lib/dist/resources/ui5webc/*
.ui5-webcomponents-lib/src/ui5webc/library.js
😞 in there, the above created rollup-bundle is consumed:sap.ui.define(["./lib/bundle"]), () => {})
ui5-app-webcomponents/package.json
:"dependencies": {
// ...
"ui5-webcomponents-lib": "0.0.1"
}
yarn
allow for locally resolving this via its workspaces
, see /package.json
.ui5-tooling
takes care of exposing the library (via ui5-webcomponents-lib/ui5.yaml
) to the application.yarn start:dev
in the project’s /
starts two UI5 tooling servers (XML controls at http://localhost:8081, web components at http://localhost:8082), then puts a watch mode on packages/ui5-webcomponents-lib
: whenever source files of the library change, it is rebuild and quickly ready to be re-consumed:[build] [nodemon] restarting due to changes...
[build] [nodemon] starting `npm run -s build`
[build]
lib/bundle.js → dist/resources/ui5webc/lib/bundle.js...
[build] info[build] [build] builder:builder[build] Building project webcomponents not including dependencies...
[build] info[build] [build] builder:builder ? [build] (1/1) Building project webcomponents
# ...
[build] info[build] builder:builder Build succeeded in 798 ms
[build] info [build] builder:builder Executing cleanup tasks...
[build] created dist/resources/ui5webc/lib/bundle.js in 5.7s
[build] [nodemon] clean exit - waiting for changes before restart
ui5-webcomponent
s in $lib/lib/bundle.js
$lib/src/$libraryName/$controlName.js
, making it a UI5 custom controlmetadata: {
properties: {
placeholder: { type: "string", defaultValue: "" },
// ...
}
}
//...
renderer: {
apiVersion: 2, // don't forget: high perf DOM rendering!
render(oRM, oCustomControl) {
oRM.openStart("ui5-datepicker", oCustomControl)
oRM.attr("placeholder", oCustomControl.getPlaceholder())
// ...
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
7 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |