0.1.0 • Published 2 years ago

als-front-import v0.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Als-front-import

Als-front-import it's a small function which allows you: 1. Import asynchronous js files 2. 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>
0.1.0

2 years ago