Refactoring + mise en place store Redux

This commit is contained in:
2015-09-04 12:10:08 +02:00
parent 324c267f8a
commit 06c809a114
24 changed files with 175 additions and 91 deletions

12
js/util/debug.js Normal file
View File

@ -0,0 +1,12 @@
var debug = require('debug');
var util = require('util');
module.exports = function createLogger(namespace) {
var logger = debug('pitaya:'+namespace);
var console = global.window ? global.window.console : global.console;
logger.log = function() {
var str = util.format.apply(util, arguments);
console.log(str);
};
return logger;
};

View File

@ -1,6 +1,7 @@
var path = require('path');
var System = require('./system');
var debug = require('debug')('pitaya:desktop-apps');
var debug = require('./debug')('desktop-apps');
var Cache = require('./cache');
// Constants
var ICON_REALPATH_REGEX = /\..+$/;
@ -69,6 +70,8 @@ exports.loadDesktopFile = function(filePath) {
return System.loadINIFile(filePath);
};
var iconCache = new Cache();
/**
* Find the absolute path of a desktop icon
*
@ -77,6 +80,13 @@ exports.loadDesktopFile = function(filePath) {
*/
exports.findIcon = function(iconName, themeName, size, themeIgnore) {
var cachedIcon = iconCache.get([iconName, themeName, size]);
if(cachedIcon) {
debug('Icon %s:%s:%s found in cache !', iconName, themeName, size);
return Promise.resolve(cachedIcon);
}
themeIgnore = themeIgnore || [];
if(themeIgnore.indexOf(themeIgnore) !== -1) {
debug('Theme %s already processed, ignoring...', themeName);
@ -101,6 +111,7 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
.then(exports._selectBestIcon)
;
})
.then(_cacheIcon)
;
}
@ -122,8 +133,15 @@ exports.findIcon = function(iconName, themeName, size, themeIgnore) {
;
})
.then(_cacheIcon)
;
function _cacheIcon(iconPath) {
iconCache.set([iconName, themeName, size], iconPath);
return iconPath;
}
};
exports.findParentsThemeIcon = function(iconName, themeName, size, themeIgnore) {

View File

@ -1,3 +1,4 @@
exports.System = require('./system');
exports.DesktopApps = require('./desktop-apps');
exports.Cache = require('./cache');
exports.Debug = require('./debug');