Files
Hydro/ui/Entry.js
T
masnn f9468536de upgrade dep:
css-loader 0.28->3.5
del 4.1->5.1
eslint 5.18->6.8
eslint-config-airbnb 17.1->18.1
eslint-loader 2.1->4.0
file-loader 2.0->6.0
fs.extra 8.0->9.0
gulp 2.0->3.0
gulp-nunjucks 4.0->5.0
json-loader 0.5->Removed
style-loader 0.23->1.1
uglifyjs-webpack-plugin 1.3->2.2
yargs 13.2->15.3
katex 0.10->0.11
react-monaco-editor 0.35->0.36
timeage-react 1.2->3.0
timeago.js 3.0->4.0
uuid 3.3->7.0
2020-04-15 12:47:55 +08:00

93 lines
2.6 KiB
JavaScript

import 'jquery.transit';
import 'normalize.css/normalize.css';
import 'codemirror/lib/codemirror.css';
import _ from 'lodash';
import 'vj/misc/float.styl';
import 'vj/misc/typography.styl';
import 'vj/misc/textalign.styl';
import 'vj/misc/grid.styl';
import 'vj/misc/slideout.styl';
import 'vj/misc/.iconfont/webicon.styl';
import 'vj/misc/immersive.styl';
import 'vj/misc/structure.styl';
import 'vj/misc/section.styl';
import 'vj/misc/nothing.styl';
import { PageLoader } from 'vj/misc/PageLoader';
import delay from 'vj/utils/delay';
// eslint-disable-next-line camelcase
__webpack_public_path__ = UiContext.cdn_prefix;
const pageLoader = new PageLoader();
const currentPage = pageLoader.getNamedPage(document.documentElement.getAttribute('data-page'));
const includedPages = pageLoader.getAutoloadPages();
function buildSequence(pages, type) {
if (process.env.NODE_ENV !== 'production') {
if (['before', 'after'].indexOf(type) === -1) {
throw new Error(`'type' should be one of 'before' or 'after'`); // eslint-disable-line quotes
}
}
return pages
.filter((p) => p && p[`${type}Loading`])
.map((p) => ({
page: p,
func: p[`${type}Loading`],
type,
}));
}
async function load() {
const loadSequence = [
...buildSequence(includedPages, 'before'),
...buildSequence([currentPage], 'before'),
...buildSequence(includedPages, 'after'),
...buildSequence([currentPage], 'after'),
];
// eslint-disable-next-line no-restricted-syntax
for (const { page, func, type } of loadSequence) {
if (typeof func !== 'function') {
if (process.env.NODE_ENV !== 'production') {
throw new Error(`The '${type}Loading' function of '${page.name}' is not callable`);
}
continue;
}
if (process.env.NODE_ENV !== 'production') {
console.time(`${page.name}: ${type}Loading`);
}
try {
await func();
} catch (e) {
console.error(`Failed to call '${type}Loading' of ${page.name}\n${e.stack}`);
}
if (process.env.NODE_ENV !== 'production') {
console.timeEnd(`${page.name}: ${type}Loading`);
}
}
const sections = _.map($('.section').get(), (section, idx) => ({
shouldDelay: idx < 5, // only animate first 5 sections
$element: $(section),
}));
// eslint-disable-next-line no-restricted-syntax
for (const { $element, shouldDelay } of sections) {
$element.addClass('visible');
if (shouldDelay) {
await delay(50);
}
}
await delay(500);
// eslint-disable-next-line no-restricted-syntax
for (const { $element } of sections) {
$element.trigger('vjLayout');
}
$(document).trigger('vjPageFullyInitialized');
}
load();