forked from grgur/Ext.data.proxy.IndexedDB
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExt.data.proxy.BrowserDB.js
More file actions
56 lines (48 loc) · 1.6 KB
/
Ext.data.proxy.BrowserDB.js
File metadata and controls
56 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @author Grgur Grisogono
*
* BrowserDB Proxy for Ext JS 4 uses best available browser (local) database to use for your locally stored data
* Currently available: IndexedDB and WebSQL DB
*
* Version: 0.4
*
*/
(function() {
var idb = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB,
cfg = {};
/**
* Choose which proxy to extend based on available features. IndexedDB is preferred over Web SQL DB
*/
if (!idb) {
cfg.extend = 'Ext.data.proxy.WebDB';
cfg.dbInUse = 'webdb';
} else {
try{
idb.setVersion();
cfg.extend = 'Ext.data.proxy.IndexedDB';
cfg.dbInUse = 'idb';//gona be indexeddb
}catch (e){
cfg.extend = 'Ext.data.proxy.IndexedDB2';
cfg.dbInUse = 'idb2';//gona be indexeddb
}
}
Ext.define('Ext.data.proxy.BrowserDB', {
extend : cfg.extend,
alias : 'proxy.browserdb',
alternateClassName : 'Ext.data.proxy.BrowserCache',
dbInUse : cfg.dbInUse,
/**
* Route to the right proxy.
* @param {Object} config (optional) Config object.
*/
constructor: function(config) {
// make sure config options are synced
if (this.dbInUse !== 'idb' && this.dbInUse !== 'idb2' ) {
config.dbTable = config.dbTable || config.objectStoreName;
} else {
config.objectStoreName = config.objectStoreName || config.dbTable;
}
this.callParent(arguments);
}
});
}());