Skip to content

Instantly share code, notes, and snippets.

@themasch
Last active September 18, 2018 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save themasch/97122794f85a53447b49c2504699839d to your computer and use it in GitHub Desktop.
Save themasch/97122794f85a53447b49c2504699839d to your computer and use it in GitHub Desktop.
UI5 AMD shim?
function define (req, factory) {
if (typeof req === 'function') {
factory = req
req = []
}
return sap.ui.define(req, factory, true)
}
define.amd = true
<!DOCTYPE HTML>
<html>
<head>
<title>example</title>
<script id="sap-ui-bootstrap"
src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
data-sap-ui-libs="sap.m"
data-sap-ui-theme="sap_belize"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"
data-sap-ui-logLevel="INFO"
data-sap-ui-resourceroots='{
"npm": "./node_modules/"
}'>
</script>
<script>
function define (req, factory) {
if (typeof req === 'function') {
factory = req
req = []
}
return sap.ui.define(req, factory, true)
}
define.amd = true
</script>
<script>
sap.ui.getCore().attachInit(function () {
sap.ui.require(['sap/m/Button', 'npm/downloadjs/download'], function (Button, download) {
const press = () => download('Hello World', 'hello_world.txt', 'text/plain')
new Button({ text: 'hi!', press }).placeAt('content')
})
})
</script>
</head>
<body class="sapUiBody" id="content">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment