mirror of https://github.com/freeCodeCamp/devdocs
parent
92144087a3
commit
e5f852e7c0
@ -1,142 +1,124 @@
|
|||||||
// TODO: This file was created by bulk-decaffeinate.
|
app.collections.Docs = class Docs extends app.Collection {
|
||||||
// Sanity-check the conversion and remove this comment.
|
static model = "Doc";
|
||||||
/*
|
static NORMALIZE_VERSION_RGX = /\.(\d)$/;
|
||||||
* decaffeinate suggestions:
|
static NORMALIZE_VERSION_SUB = ".0$1";
|
||||||
* DS101: Remove unnecessary use of Array.from
|
|
||||||
* DS102: Remove unnecessary code created because of implicit returns
|
|
||||||
* DS202: Simplify dynamic range loops
|
|
||||||
* DS206: Consider reworking classes to avoid initClass
|
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/main/docs/suggestions.md
|
|
||||||
*/
|
|
||||||
(function () {
|
|
||||||
let NORMALIZE_VERSION_RGX = undefined;
|
|
||||||
let NORMALIZE_VERSION_SUB = undefined;
|
|
||||||
let CONCURRENCY = undefined;
|
|
||||||
app.collections.Docs = class Docs extends app.Collection {
|
|
||||||
static initClass() {
|
|
||||||
this.model = "Doc";
|
|
||||||
|
|
||||||
NORMALIZE_VERSION_RGX = /\.(\d)$/;
|
// Load models concurrently.
|
||||||
NORMALIZE_VERSION_SUB = ".0$1";
|
// It's not pretty but I didn't want to import a promise library only for this.
|
||||||
|
static CONCURRENCY = 3;
|
||||||
|
|
||||||
// Load models concurrently.
|
findBySlug(slug) {
|
||||||
// It's not pretty but I didn't want to import a promise library only for this.
|
return (
|
||||||
CONCURRENCY = 3;
|
this.findBy("slug", slug) || this.findBy("slug_without_version", slug)
|
||||||
}
|
);
|
||||||
|
}
|
||||||
findBySlug(slug) {
|
sort() {
|
||||||
return (
|
return this.models.sort(function (a, b) {
|
||||||
this.findBy("slug", slug) || this.findBy("slug_without_version", slug)
|
if (a.name === b.name) {
|
||||||
);
|
if (
|
||||||
}
|
!a.version ||
|
||||||
sort() {
|
a.version.replace(
|
||||||
return this.models.sort(function (a, b) {
|
Docs.NORMALIZE_VERSION_RGX,
|
||||||
if (a.name === b.name) {
|
Docs.NORMALIZE_VERSION_SUB,
|
||||||
if (
|
) >
|
||||||
!a.version ||
|
b.version.replace(
|
||||||
a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) >
|
Docs.NORMALIZE_VERSION_RGX,
|
||||||
b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB)
|
Docs.NORMALIZE_VERSION_SUB,
|
||||||
) {
|
)
|
||||||
return -1;
|
) {
|
||||||
} else {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
} else if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return -1;
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
});
|
} else if (a.name.toLowerCase() > b.name.toLowerCase()) {
|
||||||
}
|
return 1;
|
||||||
load(onComplete, onError, options) {
|
} else {
|
||||||
let i = 0;
|
return -1;
|
||||||
|
}
|
||||||
var next = () => {
|
});
|
||||||
if (i < this.models.length) {
|
}
|
||||||
this.models[i].load(next, fail, options);
|
load(onComplete, onError, options) {
|
||||||
} else if (i === this.models.length + CONCURRENCY - 1) {
|
let i = 0;
|
||||||
onComplete();
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
};
|
|
||||||
|
|
||||||
var fail = function (...args) {
|
|
||||||
if (onError) {
|
|
||||||
onError(...Array.from(args || []));
|
|
||||||
onError = null;
|
|
||||||
}
|
|
||||||
next();
|
|
||||||
};
|
|
||||||
|
|
||||||
for (
|
var next = () => {
|
||||||
let j = 0, end = CONCURRENCY, asc = 0 <= end;
|
if (i < this.models.length) {
|
||||||
asc ? j < end : j > end;
|
this.models[i].load(next, fail, options);
|
||||||
asc ? j++ : j--
|
} else if (i === this.models.length + Docs.CONCURRENCY - 1) {
|
||||||
) {
|
onComplete();
|
||||||
next();
|
|
||||||
}
|
}
|
||||||
}
|
i++;
|
||||||
|
};
|
||||||
|
|
||||||
clearCache() {
|
var fail = function (...args) {
|
||||||
for (var doc of Array.from(this.models)) {
|
if (onError) {
|
||||||
doc.clearCache();
|
onError(args);
|
||||||
|
onError = null;
|
||||||
}
|
}
|
||||||
}
|
next();
|
||||||
|
};
|
||||||
|
|
||||||
uninstall(callback) {
|
for (let j = 0, end = Docs.CONCURRENCY; j < end; j++) {
|
||||||
let i = 0;
|
|
||||||
var next = () => {
|
|
||||||
if (i < this.models.length) {
|
|
||||||
this.models[i++].uninstall(next, next);
|
|
||||||
} else {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getInstallStatuses(callback) {
|
clearCache() {
|
||||||
app.db.versions(this.models, function (statuses) {
|
for (var doc of this.models) {
|
||||||
if (statuses) {
|
doc.clearCache();
|
||||||
for (var key in statuses) {
|
|
||||||
var value = statuses[key];
|
|
||||||
statuses[key] = { installed: !!value, mtime: value };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callback(statuses);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
checkForUpdates(callback) {
|
uninstall(callback) {
|
||||||
this.getInstallStatuses((statuses) => {
|
let i = 0;
|
||||||
let i = 0;
|
var next = () => {
|
||||||
if (statuses) {
|
if (i < this.models.length) {
|
||||||
for (var slug in statuses) {
|
this.models[i++].uninstall(next, next);
|
||||||
var status = statuses[slug];
|
} else {
|
||||||
if (this.findBy("slug", slug).isOutdated(status)) {
|
callback();
|
||||||
i += 1;
|
}
|
||||||
}
|
};
|
||||||
}
|
next();
|
||||||
}
|
}
|
||||||
callback(i);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
updateInBackground() {
|
getInstallStatuses(callback) {
|
||||||
this.getInstallStatuses((statuses) => {
|
app.db.versions(this.models, function (statuses) {
|
||||||
if (!statuses) {
|
if (statuses) {
|
||||||
return;
|
for (var key in statuses) {
|
||||||
|
var value = statuses[key];
|
||||||
|
statuses[key] = { installed: !!value, mtime: value };
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
callback(statuses);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForUpdates(callback) {
|
||||||
|
this.getInstallStatuses((statuses) => {
|
||||||
|
let i = 0;
|
||||||
|
if (statuses) {
|
||||||
for (var slug in statuses) {
|
for (var slug in statuses) {
|
||||||
var status = statuses[slug];
|
var status = statuses[slug];
|
||||||
var doc = this.findBy("slug", slug);
|
if (this.findBy("slug", slug).isOutdated(status)) {
|
||||||
if (doc.isOutdated(status)) {
|
i += 1;
|
||||||
doc.install($.noop, $.noop);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
callback(i);
|
||||||
};
|
});
|
||||||
app.collections.Docs.initClass();
|
}
|
||||||
return app.collections.Docs;
|
|
||||||
})();
|
updateInBackground() {
|
||||||
|
this.getInstallStatuses((statuses) => {
|
||||||
|
if (!statuses) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (var slug in statuses) {
|
||||||
|
var status = statuses[slug];
|
||||||
|
var doc = this.findBy("slug", slug);
|
||||||
|
if (doc.isOutdated(status)) {
|
||||||
|
doc.install($.noop, $.noop);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Loading…
Reference in new issue