als-front-import

0.1.0 • Public • Published

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>

Readme

Keywords

Package Sidebar

Install

npm i als-front-import

Weekly Downloads

1

Version

0.1.0

License

ISC

Unpacked Size

2.08 kB

Total Files

3

Last publish

Collaborators

  • alexsorkin