cbcore-ts
Version:
CBCore is a library to build web applications using pure Typescript.
90 lines (89 loc) • 3.17 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var CBServerClient_exports = {};
__export(CBServerClient_exports, {
CBServerClient: () => CBServerClient
});
module.exports = __toCommonJS(CBServerClient_exports);
var import_uicore_ts = require("../../uicore-ts");
class CBServerClient extends import_uicore_ts.UIObject {
constructor(core) {
super();
this._core = core;
}
sendJSONObject(URL, objectToSend, completion) {
this.sendRequest("POST", URL, objectToSend, function(status, response) {
if (status != 200) {
console.log("GET " + URL + " " + status);
if ((0, import_uicore_ts.IS)(completion)) {
completion(import_uicore_ts.nil);
}
return;
}
const result = JSON.parse(response);
if ((0, import_uicore_ts.IS)(completion)) {
completion(result);
}
}.bind(this));
}
retrieveJSONObject(URL, completion) {
this.retrieveJSONObjectWithCaching(URL, import_uicore_ts.nil, import_uicore_ts.nil, import_uicore_ts.YES, completion);
}
retrieveJSONObjectWithCaching(URL, cacheObject, cacheKey, forceUpdate, completion) {
if ((0, import_uicore_ts.IS)(cacheObject[cacheKey]) && !forceUpdate) {
if ((0, import_uicore_ts.IS)(completion)) {
completion(cacheObject[cacheKey]);
}
return;
}
this.sendRequest("GET", URL, null, function(status, response) {
if (status != 200) {
console.log("GET " + URL + " " + status);
if ((0, import_uicore_ts.IS)(completion)) {
completion(import_uicore_ts.nil);
}
return;
}
const result = JSON.parse(response);
cacheObject[cacheKey] = result;
if ((0, import_uicore_ts.IS)(completion)) {
completion(result);
}
}.bind(this));
}
sendRequest(method, URL, data, completion) {
const xhr = new XMLHttpRequest();
xhr.open(method, URL, true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.onreadystatechange = processRequest;
function processRequest(event) {
if (xhr.readyState == 4) {
if ((0, import_uicore_ts.IS)(completion)) {
completion(xhr.status, xhr.responseText);
}
}
}
xhr.send(JSON.stringify(data));
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CBServerClient
});
//# sourceMappingURL=CBServerClient.js.map