@web-atoms/core
Version:
115 lines (114 loc) • 3.18 kB
JavaScript
System.register(["tslib"], function (_export, _context) {
"use strict";
var __awaiter, Atom;
_export("Atom", void 0);
return {
setters: [function (_tslib) {
__awaiter = _tslib.__awaiter;
}],
execute: function () {
_export("Atom", Atom = class Atom {
static superProperty(tc, target, name) {
let c = tc;
do {
c = Object.getPrototypeOf(c);
if (!c) {
throw new Error("No property descriptor found for " + name);
}
const pd = Object.getOwnPropertyDescriptor(c.prototype, name);
if (!pd) {
continue;
}
return pd.get.apply(target);
} while (true);
}
static get(target, path) {
const segments = path.split(".");
for (const iterator of segments) {
if (target === undefined || target === null) {
return target;
}
target = target[iterator];
}
return target;
}
static delay(n, ct) {
return new Promise((resolve, reject) => {
const h = {};
h.id = setTimeout(() => {
resolve();
}, n);
if (ct) {
ct.registerForCancel(() => {
clearTimeout(h.id);
reject(new Error("cancelled"));
});
}
});
}
static encodeParameters(p) {
if (!p) {
return "";
}
let s = "";
for (const key in p) {
if (p.hasOwnProperty(key)) {
const element = p[key];
let v = element;
if (v === undefined || v === null) {
continue;
}
if (v instanceof Date) {
v = v.toISOString();
} else if (typeof element === "object") {
v = JSON.stringify(element);
}
if (s) {
s += "&";
}
s += `${key}=${encodeURIComponent(v)}`;
}
}
return s;
}
static url(url, query, hash) {
if (!url) {
return url;
}
let p = this.encodeParameters(query);
if (p) {
if (url.indexOf("?") === -1) {
url += "?";
} else {
url += "&";
}
url += p;
}
p = this.encodeParameters(hash);
if (p) {
if (url.indexOf("#") === -1) {
url += "#";
} else {
url += "&";
}
url += p;
}
return url;
}
static postAsync(app, f) {
return new Promise((resolve, reject) => {
app.callLater(() => __awaiter(this, void 0, void 0, function* () {
try {
resolve(yield f());
} catch (error) {
reject(error);
}
}));
});
}
});
Atom.designMode = false;
}
};
});
//# sourceMappingURL=Atom.js.map