97 lines
2.5 KiB
JavaScript
97 lines
2.5 KiB
JavaScript
// Generated by CoffeeScript 1.9.2
|
|
(function() {
|
|
var Buffer;
|
|
|
|
Buffer = (function() {
|
|
function Buffer(buffer) {
|
|
this.buffer = buffer;
|
|
}
|
|
|
|
Buffer.prototype.set = function(op) {
|
|
var that;
|
|
that = this;
|
|
return new Promise((function(_this) {
|
|
return function(resolve, reject) {
|
|
var request;
|
|
request = that.buffer.put(op);
|
|
request.onsuccess = function(event) {
|
|
return resolve(op);
|
|
};
|
|
return request.onerror = function(event) {
|
|
return reject("Could not set value!");
|
|
};
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
Buffer.prototype.get = function(uid) {
|
|
var that;
|
|
that = this;
|
|
return new Promise((function(_this) {
|
|
return function(resolve, reject) {
|
|
var request;
|
|
request = that.buffer.get(uid);
|
|
request.onsuccess = function(event) {
|
|
return resolve(request.result);
|
|
};
|
|
return request.onerror = function(event) {
|
|
return reject("Could not set value!");
|
|
};
|
|
};
|
|
})(this));
|
|
};
|
|
|
|
return Buffer;
|
|
|
|
})();
|
|
|
|
window.HB = (function() {
|
|
function HB() {
|
|
this.ready = (new Promise(function(resolve, reject) {
|
|
var request;
|
|
request = indexedDB.open("Testy", 7);
|
|
request.onerror = function() {
|
|
return reject("Couldn't open the IndexedDB database!");
|
|
};
|
|
request.onsuccess = function(event) {
|
|
return resolve(event.target.result);
|
|
};
|
|
return request.onupgradeneeded = function(event) {
|
|
var db, objectStore;
|
|
db = event.target.result;
|
|
return objectStore = db.createObjectStore("HistoryBuffer", {
|
|
keyPath: "uid"
|
|
});
|
|
};
|
|
}))["catch"](function(message) {
|
|
throw new Error(message);
|
|
});
|
|
}
|
|
|
|
HB.prototype.requestBuffer = function() {
|
|
return this.ready.then(function(db) {
|
|
return new Promise(function(resolve, reject) {
|
|
return resolve(new Buffer(db.transaction(["HistoryBuffer"], "readwrite").objectStore("HistoryBuffer")));
|
|
});
|
|
});
|
|
};
|
|
|
|
HB.prototype.removeDatabase = function() {
|
|
var req;
|
|
req = indexedDB.deleteDatabase("Testy");
|
|
req.onsuccess = function() {
|
|
return console.log("Deleted database successfully");
|
|
};
|
|
return req.onerror = function() {
|
|
return console.log("Couldn't delete database");
|
|
};
|
|
};
|
|
|
|
return HB;
|
|
|
|
})();
|
|
|
|
window.hb = new HB();
|
|
|
|
}).call(this);
|