@@ -9,61 +9,33 @@ The easiest way to try out FicusJS script loader is using a simple example.
99Create an ` index.html ` file and copy the following between the ` <body> ` tags.
1010
1111``` html
12- <top-nav ></top-nav >
13- <div id =" router-outlet" ></div >
12+ <div id =" content" ></div >
1413
1514<script type =" module" >
16- import { createRouter } from ' https://unpkg.com/ficusjs-router?module'
17- import { createComponent } from ' https://unpkg.com/ficusjs?module'
18- import { render as renderer , html } from ' https://unpkg.com/lit-html?module'
19-
20- createComponent (' home-page' , {
21- renderer,
22- render () {
23- return html ` <div >Welcome to the home page!</div >`
24- }
25- })
26-
27- createComponent (' page-one' , {
28- renderer,
29- render () {
30- return html ` <div >Welcome to the page one!</div >`
31- }
32- })
33-
34- createComponent (' page-two' , {
35- renderer,
36- render () {
37- return html ` <div >Welcome to the page two!</div >`
38- }
39- })
40-
41- const router = createRouter ([
42- { path: ' ' , component: ' home-page' },
43- { path: ' /one' , component: ' page-one' },
44- { path: ' /two' , component: ' page-two' }
45- ], ' #router-outlet' , { mode: ' hash' })
46-
47- createComponent (' top-nav' , {
48- renderer,
49- navigateTo (path ) {
50- router .push (path)
51- },
52- render () {
53- return html `
54- <nav >
55- <ul >
56- <li ><button type =" button" @click =" ${() => this.navigateTo('/')}" >Home</button ></li >
57- <li ><button type =" button" @click =" ${() => this.navigateTo('/one')}" >Page one</button ></li >
58- <li ><button type =" button" @click =" ${() => this.navigateTo('/two')}" >Page two</button ></li >
59- </ul >
60- </nav >
61- `
62- }
63- })
15+ import { loadScript } from ' https://unpkg.com/ficusjs-script?module'
16+ const markdownToRender = ` # FicusJS script loader
17+
18+ Dynamically load ES modules and ES5 scripts.
19+
20+ - Lazy load ES modules
21+ - Lazy load ES5 scripts
22+ - Dynamically load based on path
23+ - Functional programming patterns
24+ - Small footprint (1.3 KB gzipped for everything!)
25+ - No dependencies
26+ - Works with client-side frameworks
27+ `
28+
29+ // load the ES module for marked
30+ loadScript (' https://unpkg.com/marked@1.2.0/lib/marked.esm.js' )
31+ .then (mod => mod .default )
32+ .then (marked => {
33+ const content = document .getElementById (' content' )
34+ content .innerHTML = marked (markdownToRender)
35+ })
6436 </script >
6537```
6638
67- > Alternatively, fork this Codepen to see it in action - [ https://codepen.io/ducksoupdev/pen/PoNvGwK ] ( https://codepen.io/ducksoupdev/pen/PoNvGwK )
39+ > Alternatively, fork this Codepen to see it in action - [ https://codepen.io/ducksoupdev/pen/abZbdbq ] ( https://codepen.io/ducksoupdev/pen/abZbdbq )
6840
6941The example creates a set of page components, a page navigation component and a new router using hash mode.
0 commit comments