class App extends Events

pull/1441/head
Simon Legner 1 year ago
parent 164fa9a0c0
commit f839ec5630

@ -6,17 +6,16 @@
* DS102: Remove unnecessary code created because of implicit returns * DS102: Remove unnecessary code created because of implicit returns
* DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining * DS103: Rewrite code to no longer use __guard__, or convert again using --optional-chaining
* DS207: Consider shorter variations of null checks * DS207: Consider shorter variations of null checks
* DS208: Avoid top-level this
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md * Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
*/ */
this.app = { class App extends Events {
_$: $, _$ = $;
_$$: $$, _$$ = $$;
_page: page, _page = page;
collections: {}, collections = {};
models: {}, models = {};
templates: {}, templates = {};
views: {}, views = {};
init() { init() {
try { try {
@ -55,7 +54,7 @@ this.app = {
} else { } else {
this.onBootError(); this.onBootError();
} }
}, }
browserCheck() { browserCheck() {
if (this.isSupportedBrowser()) { if (this.isSupportedBrowser()) {
@ -64,7 +63,7 @@ this.app = {
document.body.innerHTML = app.templates.unsupportedBrowser; document.body.innerHTML = app.templates.unsupportedBrowser;
this.hideLoadingScreen(); this.hideLoadingScreen();
return false; return false;
}, }
initErrorTracking() { initErrorTracking() {
// Show a warning message and don't track errors when the app is loaded // Show a warning message and don't track errors when the app is loaded
@ -118,7 +117,7 @@ this.app = {
window.onerror = this.onWindowError.bind(this); window.onerror = this.onWindowError.bind(this);
CookiesStore.onBlocked = this.onCookieBlocked; CookiesStore.onBlocked = this.onCookieBlocked;
} }
}, }
bootOne() { bootOne() {
this.doc = new app.models.Doc(this.DOC); this.doc = new app.models.Doc(this.DOC);
@ -128,7 +127,7 @@ this.app = {
}); });
new app.views.Notice("singleDoc", this.doc); new app.views.Notice("singleDoc", this.doc);
delete this.DOC; delete this.DOC;
}, }
bootAll() { bootAll() {
const docs = this.settings.getDocs(); const docs = this.settings.getDocs();
@ -141,7 +140,7 @@ this.app = {
writeCache: true, writeCache: true,
}); });
delete this.DOCS; delete this.DOCS;
}, }
start() { start() {
let doc; let doc;
@ -163,14 +162,14 @@ this.app = {
} }
return this.removeEvent("ready bootError"); return this.removeEvent("ready bootError");
}, 50); }, 50);
}, }
initDoc(doc) { initDoc(doc) {
for (var type of Array.from(doc.types.all())) { for (var type of Array.from(doc.types.all())) {
doc.entries.add(type.toEntry()); doc.entries.add(type.toEntry());
} }
this.entries.add(doc.entries.all()); this.entries.add(doc.entries.all());
}, }
migrateDocs() { migrateDocs() {
let needsSaving; let needsSaving;
@ -201,7 +200,7 @@ this.app = {
if (needsSaving) { if (needsSaving) {
this.saveDocs(); this.saveDocs();
} }
}, }
enableDoc(doc, _onSuccess, onError) { enableDoc(doc, _onSuccess, onError) {
if (this.docs.contains(doc)) { if (this.docs.contains(doc)) {
@ -225,7 +224,7 @@ this.app = {
}; };
doc.load(onSuccess, onError, { writeCache: true }); doc.load(onSuccess, onError, { writeCache: true });
}, }
saveDocs() { saveDocs() {
this.settings.setDocs(Array.from(this.docs.all()).map((doc) => doc.slug)); this.settings.setDocs(Array.from(this.docs.all()).map((doc) => doc.slug));
@ -233,7 +232,7 @@ this.app = {
return this.serviceWorker != null return this.serviceWorker != null
? this.serviceWorker.updateInBackground() ? this.serviceWorker.updateInBackground()
: undefined; : undefined;
}, }
welcomeBack() { welcomeBack() {
let visitCount = this.settings.get("count"); let visitCount = this.settings.get("count");
@ -244,7 +243,7 @@ this.app = {
new app.views.News(); new app.views.News();
new app.views.Updates(); new app.views.Updates();
return (this.updateChecker = new app.UpdateChecker()); return (this.updateChecker = new app.UpdateChecker());
}, }
reboot() { reboot() {
if (location.pathname !== "/" && location.pathname !== "/settings") { if (location.pathname !== "/" && location.pathname !== "/settings") {
@ -252,7 +251,7 @@ this.app = {
} else { } else {
window.location = "/"; window.location = "/";
} }
}, }
reload() { reload() {
this.docs.clearCache(); this.docs.clearCache();
@ -262,7 +261,7 @@ this.app = {
} else { } else {
this.reboot(); this.reboot();
} }
}, }
reset() { reset() {
this.localStorage.reset(); this.localStorage.reset();
@ -274,7 +273,7 @@ this.app = {
this.serviceWorker.update(); this.serviceWorker.update();
} }
window.location = "/"; window.location = "/";
}, }
showTip(tip) { showTip(tip) {
if (this.isSingleDoc()) { if (this.isSingleDoc()) {
@ -286,14 +285,14 @@ this.app = {
this.settings.setTips(tips); this.settings.setTips(tips);
new app.views.Tip(tip); new app.views.Tip(tip);
} }
}, }
hideLoadingScreen() { hideLoadingScreen() {
if ($.overlayScrollbarsEnabled()) { if ($.overlayScrollbarsEnabled()) {
document.body.classList.add("_overlay-scrollbars"); document.body.classList.add("_overlay-scrollbars");
} }
document.documentElement.classList.remove("_booting"); document.documentElement.classList.remove("_booting");
}, }
indexHost() { indexHost() {
// Can't load the index files from the host/CDN when service worker is // Can't load the index files from the host/CDN when service worker is
@ -303,12 +302,12 @@ this.app = {
? "index_path" ? "index_path"
: "docs_origin" : "docs_origin"
]; ];
}, }
onBootError(...args) { onBootError(...args) {
this.trigger("bootError"); this.trigger("bootError");
this.hideLoadingScreen(); this.hideLoadingScreen();
}, }
onQuotaExceeded() { onQuotaExceeded() {
if (this.quotaExceeded) { if (this.quotaExceeded) {
@ -316,7 +315,7 @@ this.app = {
} }
this.quotaExceeded = true; this.quotaExceeded = true;
new app.views.Notif("QuotaExceeded", { autoHide: null }); new app.views.Notif("QuotaExceeded", { autoHide: null });
}, }
onCookieBlocked(key, value, actual) { onCookieBlocked(key, value, actual) {
if (this.cookieBlocked) { if (this.cookieBlocked) {
@ -328,7 +327,7 @@ this.app = {
level: "warning", level: "warning",
extra: { value, actual }, extra: { value, actual },
}); });
}, }
onWindowError(...args) { onWindowError(...args) {
if (this.cookieBlocked) { if (this.cookieBlocked) {
@ -346,7 +345,7 @@ this.app = {
} }
this.errorNotif.show(); this.errorNotif.show();
} }
}, }
onInjectionError() { onInjectionError() {
if (!this.injectionError) { if (!this.injectionError) {
@ -356,7 +355,7 @@ JavaScript code has been injected in the page which prevents DevDocs from runnin
Please check your browser extensions/addons. `); Please check your browser extensions/addons. `);
Raven.captureMessage("injection error", { level: "info" }); Raven.captureMessage("injection error", { level: "info" });
} }
}, }
isInjectionError() { isInjectionError() {
// Some browser extensions expect the entire web to use jQuery. // Some browser extensions expect the entire web to use jQuery.
@ -368,7 +367,7 @@ Please check your browser extensions/addons. `);
typeof $.empty !== "function" || typeof $.empty !== "function" ||
typeof page.show !== "function" typeof page.show !== "function"
); );
}, }
isAppError(error, file) { isAppError(error, file) {
// Ignore errors from external scripts. // Ignore errors from external scripts.
@ -377,7 +376,7 @@ Please check your browser extensions/addons. `);
file.indexOf("devdocs") !== -1 && file.indexOf("devdocs") !== -1 &&
file.indexOf(".js") === file.length - 3 file.indexOf(".js") === file.length - 3
); );
}, }
isSupportedBrowser() { isSupportedBrowser() {
try { try {
@ -409,33 +408,31 @@ Please check your browser extensions/addons. `);
}); });
return false; return false;
} }
}, }
isSingleDoc() { isSingleDoc() {
return document.body.hasAttribute("data-doc"); return document.body.hasAttribute("data-doc");
}, }
isMobile() { isMobile() {
return this._isMobile != null return this._isMobile != null
? this._isMobile ? this._isMobile
: (this._isMobile = app.views.Mobile.detect()); : (this._isMobile = app.views.Mobile.detect());
}, }
isAndroidWebview() { isAndroidWebview() {
return this._isAndroidWebview != null return this._isAndroidWebview != null
? this._isAndroidWebview ? this._isAndroidWebview
: (this._isAndroidWebview = app.views.Mobile.detectAndroidWebview()); : (this._isAndroidWebview = app.views.Mobile.detectAndroidWebview());
}, }
isInvalidLocation() { isInvalidLocation() {
return ( return (
this.config.env === "production" && this.config.env === "production" &&
location.host.indexOf(app.config.production_host) !== 0 location.host.indexOf(app.config.production_host) !== 0
); );
}, }
}; }
$.extend(app, Events);
function __guard__(value, transform) { function __guard__(value, transform) {
return typeof value !== "undefined" && value !== null return typeof value !== "undefined" && value !== null
@ -453,3 +450,5 @@ function __guardMethod__(obj, methodName, transform) {
return undefined; return undefined;
} }
} }
this.app = new App();

Loading…
Cancel
Save