Skip to content

Commit be4e333

Browse files
committed
Fixed cache / database error message.
1 parent 40e1fa9 commit be4e333

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
"private": true,
88
"dependencies": {
99
"closure-builder": "^2.2.39",
10-
"command-line-usage": "^5.0.3",
10+
"command-line-usage": "^5.0.4",
1111
"jsdoc": "^3.5.5",
1212
"npm": "^5.8.0",
1313
"npm-check-updates": "^2.14.1",
14-
"nw": "^0.29.2",
14+
"nw": "^0.29.3",
1515
"nw-builder": "^3.5.1",
1616
"rimraf": "^2.6.2"
1717
},

src/cache/cache.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ goog.provide('cwc.Cache');
2222
goog.require('cwc.framework.External');
2323
goog.require('cwc.framework.Internal');
2424
goog.require('cwc.framework.StyleSheet');
25-
goog.require('cwc.renderer.Helper');
2625
goog.require('cwc.utils.Database');
2726
goog.require('cwc.utils.Logger');
2827
goog.require('cwc.utils.Resources');
@@ -42,11 +41,11 @@ cwc.Cache = function(helper) {
4241
/** @type {!cwc.utils.Helper} */
4342
this.helper = helper;
4443

45-
/** @type {!cwc.renderer.Helper} */
46-
this.rendererHelper = new cwc.renderer.Helper();
44+
/** @private {!string} */
45+
this.version = '3';
4746

4847
/** @private {!cwc.utils.Database} */
49-
this.database_ = new cwc.utils.Database(this.name);
48+
this.database_ = new cwc.utils.Database(this.name, this.version);
5049

5150
/** @private {!Object} */
5251
this.databaseConfig_ = {
@@ -55,9 +54,6 @@ cwc.Cache = function(helper) {
5554

5655
/** @private {!cwc.utils.Logger} */
5756
this.log_ = new cwc.utils.Logger(this.name);
58-
59-
/** @private {!string} */
60-
this.version_ = '3';
6157
};
6258

6359

@@ -77,12 +73,12 @@ cwc.Cache.prototype.prepare = function() {
7773
* @param {!string|number} version
7874
*/
7975
cwc.Cache.prototype.update = function(version) {
80-
if (version && this.version_ <= version) {
81-
this.log_.info('No updates needed', version, '>=', this.version_);
76+
if (version && this.version <= version) {
77+
this.log_.info('No updates needed', version, '>=', this.version);
8278
return;
8379
}
8480

85-
this.log_.info('Updating Cache to version', this.version_);
81+
this.log_.info('Updating Cache to version', this.version);
8682
this.database_.clearFiles();
8783

8884
this.log_.info('Loading external frameworks ...');
@@ -94,7 +90,7 @@ cwc.Cache.prototype.update = function(version) {
9490
this.log_.info('Loading Style Sheets ...');
9591
this.loadFiles(cwc.framework.StyleSheet);
9692

97-
this.database_.addFile('__version__', this.version_);
93+
this.database_.addFile('__version__', this.version);
9894
};
9995

10096

src/utils/database.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ cwc.utils.Database = function(name, version) {
5757
* @export
5858
*/
5959
cwc.utils.Database.prototype.open = function(config = this.config_) {
60+
let formerConfig = this.config_;
6061
let objectStoreNames = [this.defaultObjectStore_];
6162
if (config) {
6263
this.config_ = config;
@@ -65,7 +66,7 @@ cwc.utils.Database.prototype.open = function(config = this.config_) {
6566
}
6667
}
6768
return new Promise((resolve, reject) => {
68-
if (this.database_) {
69+
if (this.database_ && formerConfig === this.config_) {
6970
return resolve(this.database_);
7071
}
7172

@@ -123,8 +124,12 @@ cwc.utils.Database.prototype.addFile = function(name, content,
123124
cwc.utils.Database.prototype.clearFiles = function(
124125
group = this.defaultObjectStore_) {
125126
this.open().then(() => {
126-
this.log_.info('Clear files in group', group);
127-
this.getObjectStore_(group)['clear']();
127+
if (this.existObjectStore_(group)) {
128+
this.log_.info('Clear files in group', group);
129+
this.getObjectStore_(group)['clear']();
130+
} else {
131+
this.log_.warn('ObjectStore', group, 'does not exists!');
132+
}
128133
});
129134
};
130135

@@ -191,3 +196,14 @@ cwc.utils.Database.prototype.getObjectStoreReadOnly_ = function(
191196
group = this.defaultObjectStore_) {
192197
return this.database_['transaction'](group, 'readonly')['objectStore'](group);
193198
};
199+
200+
201+
/**
202+
* @param {string=} group
203+
* @return {boolean}
204+
* @private
205+
*/
206+
cwc.utils.Database.prototype.existObjectStore_ = function(
207+
group = this.defaultObjectStore_) {
208+
return this.database_ && this.database_['objectStoreNames'].contains(group);
209+
};

static_files/resources/tutorial/simple/blocks/tutorial-1.cwc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"type": "application/blockly+xml",
77
"size": 48,
88
"content": "<xml xmlns=\"http://www.w3.org/1999/xhtml\"></xml>",
9-
"version": 1,
9+
"version": 1
1010
},
1111
"__javascript__": {
1212
"name": "__javascript__",
1313
"type": "application/javascript",
1414
"size": 0,
1515
"content": "",
16-
"version": 1,
16+
"version": 1
1717
}
1818
},
1919
"description": "",

0 commit comments

Comments
 (0)