| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- // TODO: This file was created by bulk-decaffeinate.
- // Sanity-check the conversion and remove this comment.
- /*
- * decaffeinate suggestions:
- * 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)$/;
- NORMALIZE_VERSION_SUB = ".0$1";
- // Load models concurrently.
- // It's not pretty but I didn't want to import a promise library only for this.
- CONCURRENCY = 3;
- }
- findBySlug(slug) {
- return (
- this.findBy("slug", slug) || this.findBy("slug_without_version", slug)
- );
- }
- sort() {
- return this.models.sort(function (a, b) {
- if (a.name === b.name) {
- if (
- !a.version ||
- a.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB) >
- b.version.replace(NORMALIZE_VERSION_RGX, NORMALIZE_VERSION_SUB)
- ) {
- return -1;
- } else {
- return 1;
- }
- } else if (a.name.toLowerCase() > b.name.toLowerCase()) {
- return 1;
- } else {
- return -1;
- }
- });
- }
- load(onComplete, onError, options) {
- let i = 0;
- var next = () => {
- if (i < this.models.length) {
- this.models[i].load(next, fail, options);
- } else if (i === this.models.length + CONCURRENCY - 1) {
- onComplete();
- }
- i++;
- };
- var fail = function (...args) {
- if (onError) {
- onError(...Array.from(args || []));
- onError = null;
- }
- next();
- };
- for (
- let j = 0, end = CONCURRENCY, asc = 0 <= end;
- asc ? j < end : j > end;
- asc ? j++ : j--
- ) {
- next();
- }
- }
- clearCache() {
- for (var doc of Array.from(this.models)) {
- doc.clearCache();
- }
- }
- uninstall(callback) {
- let i = 0;
- var next = () => {
- if (i < this.models.length) {
- this.models[i++].uninstall(next, next);
- } else {
- callback();
- }
- };
- next();
- }
- getInstallStatuses(callback) {
- app.db.versions(this.models, function (statuses) {
- if (statuses) {
- 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) {
- var status = statuses[slug];
- if (this.findBy("slug", slug).isOutdated(status)) {
- i += 1;
- }
- }
- }
- callback(i);
- });
- }
- 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);
- }
- }
- });
- }
- };
- app.collections.Docs.initClass();
- return app.collections.Docs;
- })();
|