@trullock/page-manager 0.6.9 → 0.6.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.js +16 -6
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -30,7 +30,7 @@ var options = {
|
|
|
30
30
|
});
|
|
31
31
|
},
|
|
32
32
|
pageInterrupt: route => null,
|
|
33
|
-
|
|
33
|
+
attachMarkup: $html => document.body.appendChild($html),
|
|
34
34
|
prepareMarkup: $html => { },
|
|
35
35
|
loadingPageName: 'loading',
|
|
36
36
|
error404PageName: 'error-404',
|
|
@@ -107,14 +107,16 @@ function loadPage(route, data) {
|
|
|
107
107
|
return fetchPage.then($template => {
|
|
108
108
|
var $html = $template.cloneNode(true);
|
|
109
109
|
options.prepareMarkup($html);
|
|
110
|
-
options.
|
|
110
|
+
options.attachMarkup($html);
|
|
111
111
|
pageCache[route.path] = {
|
|
112
112
|
$html,
|
|
113
113
|
page: new (route.pageClass)($html)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
var page = pageCache[route.path].page;
|
|
117
|
-
|
|
117
|
+
|
|
118
|
+
let booted = new Promise(resolve => resolve(page.boot(data)));
|
|
119
|
+
return booted.then(() => page);
|
|
118
120
|
});
|
|
119
121
|
}
|
|
120
122
|
|
|
@@ -159,6 +161,7 @@ function showPage(url, data, event) {
|
|
|
159
161
|
if (event.action == 'load')
|
|
160
162
|
{
|
|
161
163
|
return getPage
|
|
164
|
+
.then(page => doShow(page, data))
|
|
162
165
|
.then(page => {
|
|
163
166
|
// clean initial load
|
|
164
167
|
if(stackPointer == -1)
|
|
@@ -173,8 +176,7 @@ function showPage(url, data, event) {
|
|
|
173
176
|
stack[stackPointer].data = data;
|
|
174
177
|
}
|
|
175
178
|
return page;
|
|
176
|
-
})
|
|
177
|
-
.then(page => doShow(page, data));
|
|
179
|
+
});
|
|
178
180
|
}
|
|
179
181
|
|
|
180
182
|
let currentState = stack[stackPointer];
|
|
@@ -321,8 +323,16 @@ export async function init(opts) {
|
|
|
321
323
|
// set initial page
|
|
322
324
|
showPage(window.location.pathname + window.location.search + window.location.hash, null, { action: 'load', distance: 0 }).catch(e => {
|
|
323
325
|
console.error(e);
|
|
326
|
+
|
|
324
327
|
if (e instanceof PageShowError)
|
|
325
|
-
|
|
328
|
+
{
|
|
329
|
+
return showPage(e.url, e.data, { action: stackPointer == -1 ? 'load' : e.action || 'show' }).then(page => {
|
|
330
|
+
if(e.action == 'replace')
|
|
331
|
+
handleHistoryAction({ action: e.action }, e.url, e.data, page);
|
|
332
|
+
return page;
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
}
|
|
326
336
|
});
|
|
327
337
|
|
|
328
338
|
function handlePopstate(context, direction, distance) {
|