basic get&set of Map properties works
This commit is contained in:
@@ -113,11 +113,16 @@ Y.IndexedDB = (function(){ //eslint-disable-line no-unused-vars
|
||||
if (opts == null) {
|
||||
opts = {};
|
||||
}
|
||||
if (opts.namespace != null || typeof opts.namespace !== "string") {
|
||||
if (opts.namespace == null || typeof opts.namespace !== "string") {
|
||||
throw new Error("IndexedDB: expect a string (opts.namespace)!");
|
||||
} else {
|
||||
this.namespace = opts.namespace;
|
||||
}
|
||||
if (opts.idbVersion != null) {
|
||||
this.idbVersion = opts.idbVersion;
|
||||
} else {
|
||||
this.idbVersion = 5;
|
||||
}
|
||||
|
||||
this.transactionQueue = {
|
||||
queue: [],
|
||||
@@ -127,7 +132,7 @@ Y.IndexedDB = (function(){ //eslint-disable-line no-unused-vars
|
||||
var store = this;
|
||||
|
||||
var tGen = (function *transactionGen(){
|
||||
store.db = yield indexedDB.open(opts.namespace, 3);
|
||||
store.db = yield indexedDB.open(opts.namespace, store.idbVersion);
|
||||
var transactionQueue = store.transactionQueue;
|
||||
|
||||
var transaction = null;
|
||||
@@ -174,8 +179,12 @@ Y.IndexedDB = (function(){ //eslint-disable-line no-unused-vars
|
||||
};
|
||||
request.onupgradeneeded = function(event){
|
||||
var db = event.target.result;
|
||||
db.createObjectStore("OperationStore", {keyPath: "id"});
|
||||
db.createObjectStore("StateVector", {keyPath: "user"});
|
||||
try {
|
||||
db.createObjectStore("OperationStore", {keyPath: "id"});
|
||||
db.createObjectStore("StateVector", {keyPath: "user"});
|
||||
} catch (e) {
|
||||
// console.log("Store already exists!");
|
||||
}
|
||||
};
|
||||
} else {
|
||||
tGen.throw("You can not yield this type!");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
if(typeof window !== "undefined"){
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000;
|
||||
describe("IndexedDB", function() {
|
||||
var ob = new IndexedDB("Test");
|
||||
var ob = new Y.IndexedDB(null, {namespace: "Test"});
|
||||
|
||||
it("can add and get operation", function(done) {
|
||||
ob.requestTransaction(function*(){
|
||||
|
||||
@@ -16,7 +16,7 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
|
||||
|
||||
constructor (store : OperationStore) {
|
||||
super(store);
|
||||
this.sv = store.ss;
|
||||
this.ss = store.ss;
|
||||
this.os = store.os;
|
||||
}
|
||||
*setOperation (op) {
|
||||
@@ -30,7 +30,7 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
|
||||
delete this.os[JSON.stringify(id)];
|
||||
}
|
||||
*setState (state : State) : State {
|
||||
this.sv[state.user] = state.clock;
|
||||
this.ss[state.user] = state.clock;
|
||||
}
|
||||
*getState (user : string) : State {
|
||||
var clock = this.ss[user];
|
||||
@@ -80,18 +80,21 @@ Y.Memory = (function(){ //eslint-disable-line no-unused-vars
|
||||
}
|
||||
}
|
||||
class OperationStore extends AbstractOperationStore { //eslint-disable-line no-undef
|
||||
namespace: string;
|
||||
ready: Promise;
|
||||
whenReadyListeners: Array<Function>;
|
||||
constructor (y) {
|
||||
super(y);
|
||||
this.os = {};
|
||||
this.ss = {};
|
||||
}
|
||||
requestTransaction (makeGen : Function) {
|
||||
var t = new Transaction(this);
|
||||
var gen = makeGen.call(t);
|
||||
gen.next();
|
||||
if (gen.done !== true) {
|
||||
throw new Error("transaction is supposed to be done. Note: you may not yield with this transaction! (yield* is allowed though)");
|
||||
var res = gen.next();
|
||||
while(!res.done){
|
||||
if (res.value === "transaction") {
|
||||
res = gen.next(t);
|
||||
} else {
|
||||
throw new Error("You may not yield this type. (Maybe you meant to use 'yield*'?)");
|
||||
}
|
||||
}
|
||||
}
|
||||
*removeDatabase () {
|
||||
|
||||
Reference in New Issue
Block a user