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...
@ -349,10 +375,10 @@ module.makeWorkspaceConfigWriter = function(keys, callback){
return function(workspace){
var that = this
keys = typeof(keys) == typeof(function(){}) ? keys.call(this) : keys
var data = keys instanceof Function ? keys.call(this) : keys
// store data...
keys.forEach(function(key){
data.forEach(function(key){
workspace[key] = JSON.parse(JSON.stringify(that.config[key]))
})
@ -368,10 +394,10 @@ module.makeWorkspaceConfigLoader = function(keys, callback){
return function(workspace){
var that = this
keys = typeof(keys) == typeof(function(){}) ? keys.call(this) : keys
var data = keys instanceof Function ? keys.call(this) : keys
// load data...
keys.forEach(function(key){
data.forEach(function(key){
// the key exists...
if(key in workspace){
that.config[key] = JSON.parse(JSON.stringify(workspace[key]))
@ -401,16 +427,12 @@ var WorkspaceActions = actions.Actions({
},
get workspace(){
return this.config.workspace
},
return this.config.workspace },
set workspace(value){
this.loadWorkspace(value)
},
this.loadWorkspace(value) },
get workspaces(){
return this.config.workspaces
},
return this.config.workspaces },
getWorkspace: ['- Workspace/',
function(){ return this.saveWorkspace(null) }],

View File

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

View File

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