-
Notifications
You must be signed in to change notification settings - Fork 5
/
app.js
101 lines (91 loc) · 3.49 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
__webpack_public_path__ = window.__webpack_public_path__; // eslint-disable-line
import Global from './theme/global';
const getAccount = () => import('./theme/account');
const getLogin = () => import('./theme/auth');
const noop = null;
const pageClasses = {
account_orderstatus: getAccount,
account_order: getAccount,
account_addressbook: getAccount,
shippingaddressform: getAccount,
account_new_return: getAccount,
'add-wishlist': () => import('./theme/wishlist'),
account_recentitems: getAccount,
account_downloaditem: getAccount,
editaccount: getAccount,
account_inbox: getAccount,
account_saved_return: getAccount,
account_returns: getAccount,
account_paymentmethods: getAccount,
account_addpaymentmethod: getAccount,
account_editpaymentmethod: getAccount,
login: getLogin,
createaccount_thanks: getLogin,
createaccount: getLogin,
getnewpassword: getLogin,
forgotpassword: getLogin,
blog: noop,
blog_post: noop,
brand: () => import('./theme/brand'),
brands: noop,
cart: () => import('./theme/cart'),
category: () => import('./theme/category'),
compare: () => import('./theme/compare'),
page_contact_form: () => import('./theme/contact-us'),
error: noop,
404: noop,
giftcertificates: () => import('./theme/gift-certificate'),
giftcertificates_balance: () => import('./theme/gift-certificate'),
giftcertificates_redeem: () => import('./theme/gift-certificate'),
default: noop,
page: noop,
product: () => import('./theme/product'),
amp_product_options: () => import('./theme/product'),
search: () => import('./theme/search'),
rss: noop,
sitemap: noop,
newsletter_subscribe: noop,
wishlist: () => import('./theme/wishlist'),
wishlists: () => import('./theme/wishlist'),
};
const customClasses = {
'pages\\custom\\category\\react-demo': () => import('./theme/custom/react-demo'), // Windows
'pages/custom/category/react-demo': () => import('./theme/custom/react-demo'), // Mac/Linux
};
/**
* This function gets added to the global window and then called
* on page load with the current template loaded and JS Context passed in
* @param pageType String
* @param contextJSON
* @returns {*}
*/
window.stencilBootstrap = function stencilBootstrap(pageType, contextJSON = null, loadGlobal = true) {
const context = JSON.parse(contextJSON || '{}');
return {
load() {
$(() => {
// Load globals
if (loadGlobal) {
Global.load(context);
}
const importPromises = [];
// Find the appropriate page loader based on pageType
const pageClassImporter = pageClasses[pageType];
if (typeof pageClassImporter === 'function') {
importPromises.push(pageClassImporter());
}
// See if there is a page class default for a custom template
const customTemplateImporter = customClasses[context.template];
if (typeof customTemplateImporter === 'function') {
importPromises.push(customTemplateImporter());
}
// Wait for imports to resolve, then call load() on them
Promise.all(importPromises).then(imports => {
imports.forEach(imported => {
imported.default.load(context);
});
});
});
},
};
};