Refactoring store
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
exports.desktopApps = require('./desktop-apps');
|
||||
exports.profile = require('./profile');
|
||||
exports.processOpts = require('./process-opts');
|
||||
exports.theme = require('./theme');
|
||||
|
@ -14,6 +14,12 @@ module.exports = function(oldProfile, action) {
|
||||
case actions.edit.ADD_PROFILE_ITEM:
|
||||
return addProfileItem(oldProfile, action.newItem, action.targetItem);
|
||||
|
||||
case actions.edit.UPDATE_PROFILE_ITEM:
|
||||
return updateProfileItem(oldProfile, action.item, action.key, action.value);
|
||||
|
||||
case actions.edit.SELECT_PROFILE_ITEM:
|
||||
return selectProfileItem(oldProfile, action.item);
|
||||
|
||||
default:
|
||||
return oldProfile || null;
|
||||
|
||||
@ -21,6 +27,19 @@ module.exports = function(oldProfile, action) {
|
||||
|
||||
};
|
||||
|
||||
function selectProfileItem(oldProfile, item) {
|
||||
var newProfile = _.cloneDeep(oldProfile);
|
||||
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
function updateProfileItem(oldProfile, targetItem, key, value) {
|
||||
var newProfile = _.cloneDeep(oldProfile);
|
||||
var result = treeFind(newProfile, targetItem);
|
||||
result.item[key] = value;
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
|
||||
function moveProfileItem(oldProfile, movedItem, targetItem) {
|
||||
|
||||
@ -50,6 +69,29 @@ function addProfileItem(oldProfile, newItem, targetItem) {
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
// Tree manipulation helpers
|
||||
|
||||
function treeWalk(branch, func) {
|
||||
|
||||
var items = branch.items;
|
||||
|
||||
if(!items) return;
|
||||
|
||||
for( var i = 0, item = items[i]; (item = items[i]); i++ ) {
|
||||
|
||||
var breakHere = func(item, parent);
|
||||
|
||||
if(breakHere) return breakHere;
|
||||
|
||||
if(item.items) {
|
||||
breakHere = treeWalk(item, func);
|
||||
if(breakHere) return breakHere;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function treeFind(branch, obj) {
|
||||
|
||||
var items = branch.items;
|
||||
|
14
js/store/reducers/theme.js
Normal file
14
js/store/reducers/theme.js
Normal file
@ -0,0 +1,14 @@
|
||||
var actions = require('../actions');
|
||||
|
||||
module.exports = function(currentTheme, action) {
|
||||
|
||||
switch(action.type) {
|
||||
|
||||
case actions.edit.USE_ICON_THEME:
|
||||
return action.theme;
|
||||
|
||||
default:
|
||||
return currentTheme || null;
|
||||
}
|
||||
|
||||
};
|
Reference in New Issue
Block a user