Als-front-import
Als-front-import it's a small function which allows you:
- Import asynchronous js files
- Manage routes
Syntax:
Import(src,route):Promise
// Example for function for binding html
function bindHTML(selector,content) {
document.querySelector(selector)
.innerHTML = content
}
(async function() {
await Import('/layout/header.js')
await Import('/layout/main.js')
await Import('/layout/footer.js')
})()
If routeName (second parameter) is given, Import became a part of router, like in example below:
<div><a href="/?route=first">first</a></div>
<div><a href="/?route=second">second</a></div>
<div><a href="/">default</a></div>
<div component="app"></div>
<script>
// Imports only if location.search has route=first
Import('first.js','first')
// Imports only if location.search has route=second
Import('second.js','second')
// Imports only if location.search does not have route parameter
Import('default.js','default')
</script>