Skip to content
This repository was archived by the owner on Apr 17, 2023. It is now read-only.

Commit 10e532d

Browse files
author
Wei Li
authored
Merge pull request #50 from wei-lee/indexdb-open-error
Indexdb open error
2 parents b8f3864 + 8e6171c commit 10e532d

File tree

6 files changed

+26
-7
lines changed

6 files changed

+26
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog - fh-sync-js lib
22

3+
## 1.4.1 - 2019-11-07
4+
## Change
5+
- Emit an error if it takes too long to open index-db.
36

47
## 1.4.0 - 2019-04-15
58
## Change

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
crossorigin="anonymous"></script>
66
<!-- TODO improve example to use local distribution build !-->
77
<script src="../dist/fh-sync.js" type="text/javascript"></script>
8-
<script src="./sync.js" type="text/javascript"></script>
8+
<script src="./example/sync.js" type="text/javascript"></script>
99
</head>
1010
<body>
1111
Messages will be printed to console.

example/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $fh.sync.init({
66
"cloudUrl": "http://localhost:3000",
77
"sync_frequency": 10,
88
"do_console_log": true,
9-
"storage_strategy": "dom"
9+
"storage_strategy": "indexed-db"
1010
});
1111

1212
//provide listeners for notifications.

libs/lawnchair/lawnchairIndexDbAdapter.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ module.exports = function (Lawnchair) {
3131
//FEEDHENRY CHANGE TO ALLOW ERROR CALLBACK
3232
if(options && 'function' === typeof options.fail) fail = options.fail
3333
//END CHANGE
34+
35+
var to = setTimeout(function(){
36+
if (request.readyState != 'done') {
37+
console.error('opendb request is still not ready. current readyState: ' + request.readyState + '. Returning error.');
38+
return fail(new Error('OPEN_DB_ERROR'));
39+
}
40+
}, 2000);
41+
3442
request.onupgradeneeded = function (event) {
43+
clearTimeout(to);
3544
self.store = request.result.createObjectStore("teststore", { autoIncrement: true });
3645
for (var i = 0; i < self.waiting.length; i++) {
3746
self.waiting[i].call(self);
@@ -41,6 +50,7 @@ module.exports = function (Lawnchair) {
4150
};
4251

4352
request.onsuccess = function (event) {
53+
clearTimeout(to);
4454
self.db = request.result;
4555

4656
if (self.db.version != "2.0") {
@@ -72,7 +82,11 @@ module.exports = function (Lawnchair) {
7282
}
7383
};
7484

75-
request.onerror = fail;
85+
request.onerror = function(){
86+
clearTimeout(to);
87+
var error = request.error;
88+
fail(error);
89+
};
7690
},
7791

7892
save:function(obj, callback) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fh-sync-js",
3-
"version": "1.4.0",
3+
"version": "1.4.1",
44
"description": "Javascript client for fh-sync offline synchronization library",
55
"main": "src/index.js",
66
"types": "./fh-sync-js.d.ts",

src/sync-client.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,9 +974,11 @@ function newClient(id) {
974974
},
975975

976976
getStorageAdapter: function (dataset_id, isSave, cb) {
977-
var onFail = function(msg, err){
978-
var errMsg = (isSave?'save to': 'load from' ) + ' local storage failed msg: ' + msg + ' err: ' + err;
979-
self.doNotify(dataset_id, null, self.notifications.CLIENT_STORAGE_FAILED, errMsg);
977+
var onFail = function(err){
978+
err = err || new Error('storage error');
979+
var msg = err.message || err;
980+
var errMsg = (isSave?'save to': 'load from' ) + ' local storage failed msg: ' + msg;
981+
self.doNotify(dataset_id, null, self.notifications.CLIENT_STORAGE_FAILED, msg);
980982
self.consoleLog(errMsg);
981983
};
982984

0 commit comments

Comments
 (0)