more refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-11-20 03:51:53 +03:00
parent fed78ba0e9
commit d8141e0aab
3 changed files with 46 additions and 23 deletions

View File

@ -286,6 +286,32 @@ module.LifeCycle = ImageGridFeatures.Feature({
}) })
//---------------------------------------------------------------------
var UtilActions = actions.Actions({
mergeConfig: ['- System/',
function(config){
config = config instanceof Function ? config.call(this)
: typeof(config) == typeof('str') ? this.config[config]
: config
var that = this
Object.keys(config).forEach(function(key){
that.config[key] = config[key]
})
}],
})
var Util =
module.Util = ImageGridFeatures.Feature({
title: '',
doc: '',
tag: 'util',
actions: UtilActions,
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Introspection... // Introspection...
@ -349,10 +375,10 @@ module.makeWorkspaceConfigWriter = function(keys, callback){
return function(workspace){ return function(workspace){
var that = this var that = this
keys = typeof(keys) == typeof(function(){}) ? keys.call(this) : keys var data = keys instanceof Function ? keys.call(this) : keys
// store data... // store data...
keys.forEach(function(key){ data.forEach(function(key){
workspace[key] = JSON.parse(JSON.stringify(that.config[key])) workspace[key] = JSON.parse(JSON.stringify(that.config[key]))
}) })
@ -368,10 +394,10 @@ module.makeWorkspaceConfigLoader = function(keys, callback){
return function(workspace){ return function(workspace){
var that = this var that = this
keys = typeof(keys) == typeof(function(){}) ? keys.call(this) : keys var data = keys instanceof Function ? keys.call(this) : keys
// load data... // load data...
keys.forEach(function(key){ data.forEach(function(key){
// the key exists... // the key exists...
if(key in workspace){ if(key in workspace){
that.config[key] = JSON.parse(JSON.stringify(workspace[key])) that.config[key] = JSON.parse(JSON.stringify(workspace[key]))
@ -401,16 +427,12 @@ var WorkspaceActions = actions.Actions({
}, },
get workspace(){ get workspace(){
return this.config.workspace return this.config.workspace },
},
set workspace(value){ set workspace(value){
this.loadWorkspace(value) this.loadWorkspace(value) },
},
get workspaces(){ get workspaces(){
return this.config.workspaces return this.config.workspaces },
},
getWorkspace: ['- Workspace/', getWorkspace: ['- Workspace/',
function(){ return this.saveWorkspace(null) }], function(){ return this.saveWorkspace(null) }],

View File

@ -412,6 +412,9 @@ module.PartialRibbons = core.ImageGridFeatures.Feature({
//this.preCacheJumpTargets() //this.preCacheJumpTargets()
}], }],
], ],
}) })

View File

@ -246,15 +246,8 @@ var SingleImageActions = actions.Actions({
if(this.workspaces['single-image'] == null){ if(this.workspaces['single-image'] == null){
this.loadWorkspace('ui-chrome-hidden') this.loadWorkspace('ui-chrome-hidden')
this.mergeConfig('single-image-config-defaults')
// setup defaults... this.saveWorkspace('single-image')
var that = this
var defaults = this.config['single-image-config-defaults'] || {}
Object.keys(defaults)
.forEach(function(key){
that.config[key] = JSON.parse(JSON.stringify(defaults[key])) })
this.saveWorkspace('single-image')
} }
this.loadWorkspace('single-image') this.loadWorkspace('single-image')
@ -333,7 +326,8 @@ module.SingleImageView = core.ImageGridFeatures.Feature({
tag: 'ui-single-image', tag: 'ui-single-image',
depends: [ depends: [
'ui' 'ui',
'util',
], ],
suggested: [ suggested: [
'ui-single-image-local-storage', 'ui-single-image-local-storage',
@ -434,12 +428,16 @@ module.SingleImageView = core.ImageGridFeatures.Feature({
// Workspace... // Workspace...
// ...set ribbon focus mode to order (default) in single image mode... // ...set ribbon focus mode to order (default) in single image mode...
//
// XXX move these to ui-partial-ribbons???
['saveWorkspace', ['saveWorkspace',
core.makeWorkspaceConfigWriter( core.makeWorkspaceConfigWriter(
Object.keys(SingleImageActions.config['single-image-config-defaults']))], function(){
return Object.keys(this.config['single-image-config-defaults'] || {}) })],
['loadWorkspace', ['loadWorkspace',
core.makeWorkspaceConfigLoader( core.makeWorkspaceConfigLoader(
Object.keys(SingleImageActions.config['single-image-config-defaults']), function(){
return Object.keys(this.config['single-image-config-defaults'] || {}) },
// NOTE: considering that 'ribbon-focus-mode' is handled // NOTE: considering that 'ribbon-focus-mode' is handled
// by a toggler that can have things bound to it, // by a toggler that can have things bound to it,
// active is the way to go here... // active is the way to go here...