-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
58 lines (52 loc) · 1.41 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import riot from 'riot';
import tag from './tags/header.tag';
//function to load routes from primary chunk
function loadPrimaryChunk(){
return new Promise((resolve,reject)=>{
//this line ensures cart and co tags are bundled into one file
require.ensure(['./tags/home.tag'], (require) => {
require('./tags/home.tag');
resolve();
});
});
}
//function to load routes from secondary chunk
function loadSecondChunk(module){
return new Promise((resolve,reject)=>{
//this line ensures cart and co tags are bundled into one file
require.ensure(['./tags/browse.tag','./tags/product.tag'], (require) => {
switch(module){
case 'BROWSE':
//till we do this the tag will not be executed
require('./tags/browse.tag');
break;
case 'PRODUCT':
require('./tags/product.tag');
break;
}
resolve();
});
});
}
//router configuration
var $app=document.querySelector('.app-root');
riot.route('/',()=>{
loadPrimaryChunk().then(()=>{
$app.innerHTML="<home></home>";
riot.mount('home');
});
})
riot.route('/browse/*',(keyword)=>{
loadSecondChunk('BROWSE').then(()=>{
$app.innerHTML="<browse category='"+keyword+"'></browse>";
riot.mount('browse');
});
})
riot.route('/product/*/*',(category,name)=>{
loadSecondChunk('PRODUCT').then(()=>{
$app.innerHTML="<product cat='"+category+"' name='"+name+"'></product>";
riot.mount('product');
});
})
riot.route.start(true);
riot.mount('*');