forked from docsifyjs/docsify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocsify.js
53 lines (46 loc) · 1.35 KB
/
Docsify.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
import { Router } from './router/index.js';
import { Render } from './render/index.js';
import { Fetch } from './fetch/index.js';
import { Events } from './event/index.js';
import { VirtualRoutes } from './virtual-routes/index.js';
import initGlobalAPI from './global-api.js';
import config from './config.js';
import { isFn } from './util/core';
import { Lifecycle } from './init/lifecycle';
/** @typedef {new (...args: any[]) => any} Constructor */
// eslint-disable-next-line new-cap
export class Docsify extends Fetch(
// eslint-disable-next-line new-cap
Events(Render(VirtualRoutes(Router(Lifecycle(Object)))))
) {
constructor() {
super();
this.config = config(this);
this.initLifecycle(); // Init hooks
this.initPlugin(); // Install plugins
this.callHook('init');
this.initRouter(); // Add router
this.initRender(); // Render base DOM
this.initEvent(); // Bind events
this.initFetch(); // Fetch data
this.callHook('mounted');
}
initPlugin() {
[].concat(this.config.plugins).forEach(fn => {
try {
isFn(fn) && fn(this._lifecycle, this);
} catch (err) {
if (this.config.catchPluginErrors) {
const errTitle = 'Docsify plugin error';
console.error(errTitle, err);
} else {
throw err;
}
}
});
}
}
/**
* Global API
*/
initGlobalAPI();