mirror of
https://github.com/piskelapp/piskel.git
synced 2023-08-10 21:12:52 +03:00
Review comments
This commit is contained in:
parent
73aae69425
commit
7bbcbe1861
@ -145,7 +145,11 @@
|
|||||||
|
|
||||||
var pixelWidth = col * this.dpi + this.gridStrokeWidth * (col - 1);
|
var pixelWidth = col * this.dpi + this.gridStrokeWidth * (col - 1);
|
||||||
var pixelHeight = row * this.dpi + this.gridStrokeWidth * (row - 1);
|
var pixelHeight = row * this.dpi + this.gridStrokeWidth * (row - 1);
|
||||||
var canvas = pskl.CanvasUtils.createCanvas(pixelWidth, pixelHeight, ["canvas", this.className]);
|
var classes = ['canvas'];
|
||||||
|
if (this.className) {
|
||||||
|
classes.push(this.className);
|
||||||
|
}
|
||||||
|
var canvas = pskl.CanvasUtils.createCanvas(pixelWidth, pixelHeight, classes);
|
||||||
|
|
||||||
this.container.append(canvas);
|
this.container.append(canvas);
|
||||||
|
|
||||||
|
@ -21,17 +21,18 @@
|
|||||||
* value if not defined yet.
|
* value if not defined yet.
|
||||||
*/
|
*/
|
||||||
get : function (key) {
|
get : function (key) {
|
||||||
this.checKeyValidity_(key);
|
this.checkKeyValidity_(key);
|
||||||
if (key in this.cache_) {
|
if (!(key in this.cache_)) {
|
||||||
return this.cache_[key];
|
this.cache_[key] =
|
||||||
|
this.readFromLocalStorage_(key) || this.readFromDefaults_(key);
|
||||||
}
|
}
|
||||||
return this.get_(key);
|
return this.cache_[key];
|
||||||
},
|
},
|
||||||
|
|
||||||
set : function (key, value) {
|
set : function (key, value) {
|
||||||
this.checKeyValidity_(key);
|
this.checkKeyValidity_(key);
|
||||||
this.cache_[key] = value;
|
this.cache_[key] = value;
|
||||||
this.set_(key, value);
|
this.writeToLocalStorage_(key, value);
|
||||||
|
|
||||||
$.publish(Events.USER_SETTINGS_CHANGED, [key, value]);
|
$.publish(Events.USER_SETTINGS_CHANGED, [key, value]);
|
||||||
},
|
},
|
||||||
@ -39,14 +40,10 @@
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
get_ : function(key) {
|
readFromLocalStorage_ : function(key) {
|
||||||
var value = window.localStorage[key];
|
var value = window.localStorage[key];
|
||||||
if (value === undefined) {
|
if (typeof value != "undefined") {
|
||||||
value = this.KEY_TO_DEFAULT_VALUE_MAP_[key];
|
value = JSON.parse(value);
|
||||||
}
|
|
||||||
else {
|
|
||||||
var entry = JSON.parse(value);
|
|
||||||
value = entry.jsonValue;
|
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
},
|
},
|
||||||
@ -54,20 +51,26 @@
|
|||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
set_ : function(key, value) {
|
writeToLocalStorage_ : function(key, value) {
|
||||||
var entry = { 'jsonValue': value };
|
// TODO(grosbouddha): Catch storage exception here.
|
||||||
window.localStorage[key] = JSON.stringify(entry);
|
window.localStorage[key] = JSON.stringify(value);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
checKeyValidity_ : function(key) {
|
readFromDefaults_ : function (key) {
|
||||||
if(key in this.KEY_TO_DEFAULT_VALUE_MAP_) {
|
return this.KEY_TO_DEFAULT_VALUE_MAP_[key];
|
||||||
return true;
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
checkKeyValidity_ : function(key) {
|
||||||
|
if(!(key in this.KEY_TO_DEFAULT_VALUE_MAP_)) {
|
||||||
|
// TODO(grosbouddha): Define error catching strategy and throw exception from here.
|
||||||
|
console.log("UserSettings key <"+ key +"> not find in supported keys.");
|
||||||
}
|
}
|
||||||
console.log("UserSettings key <"+ key +"> not find in supported keys.");
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user