1
0
mirror of https://github.com/moparisthebest/kaiwa synced 2024-11-23 01:32:18 -05:00
kaiwa/clientapp/storage/index.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2013-08-29 23:38:28 -04:00
/*global indexedDB*/
"use strict";
var AvatarStorage = require('./avatars');
var RosterStorage = require('./roster');
var DiscoStorage = require('./disco');
var ArchiveStorage = require('./archive');
2013-09-05 19:53:23 -04:00
var RosterVerStorage = require('./rosterver');
2013-08-29 23:38:28 -04:00
function Storage() {
this.db = null;
this.init = [];
this.avatars = new AvatarStorage(this);
this.roster = new RosterStorage(this);
this.disco = new DiscoStorage(this);
this.archive = new ArchiveStorage(this);
2013-09-05 19:53:23 -04:00
this.rosterver = new RosterVerStorage(this);
2013-08-29 23:38:28 -04:00
}
Storage.prototype = {
constructor: {
value: Storage
},
version: 2,
2013-08-29 23:38:28 -04:00
open: function (cb) {
cb = cb || function () {};
var self = this;
var request = indexedDB.open('datastorage', this.version);
request.onsuccess = function (e) {
self.db = e.target.result;
cb(false, self.db);
};
request.onupgradeneeded = function (e) {
var db = e.target.result;
self.avatars.setup(db);
self.roster.setup(db);
self.disco.setup(db);
self.archive.setup(db);
2013-09-05 19:53:23 -04:00
self.rosterver.setup(db);
2013-08-29 23:38:28 -04:00
};
request.onerror = cb;
}
};
module.exports = Storage;