fixed .clone(..) + some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-08-27 22:17:47 +03:00
parent 6b15446bcc
commit 4d169b91b4
4 changed files with 66 additions and 17 deletions

View File

@ -235,18 +235,14 @@ actions.Actions({
// NOTE: for complete isolation it is best to completely copy the // NOTE: for complete isolation it is best to completely copy the
// .config... // .config...
clone: ['- File/', clone: ['- File/',
function(full){ function(full){ return function(res){
var res = actions.MetaActions.clone.call(this, full)
if(this.data){ if(this.data){
res.data = this.data.clone() res.data = this.data.clone()
} }
if(this.images){ if(this.images){
res.images = this.images.clone() res.images = this.images.clone()
} }
} }],
return res
}],
dataFromURLs: ['- File/', dataFromURLs: ['- File/',
function(lst, base){ function(lst, base){
@ -613,6 +609,7 @@ core.ImageGridFeatures.Feature({
tag: 'base', tag: 'base',
depends: [ depends: [
'serialization',
], ],
suggested: [ suggested: [
'edit', 'edit',

View File

@ -464,8 +464,6 @@ var CollectionActions = actions.Actions({
.removeEmptyRibbons() .removeEmptyRibbons()
}], }],
// manage serialization and loading...
//
// NOTE: this will handle collection title and data only, the rest // NOTE: this will handle collection title and data only, the rest
// is copied in as-is. // is copied in as-is.
// It is the responsibility of the extending features to transform // It is the responsibility of the extending features to transform
@ -577,10 +575,6 @@ var CollectionActions = actions.Actions({
}) })
} }
} }], } }],
// XXX
clone: [function(){
// XXX
}],
clear: [function(){ clear: [function(){
this.collection this.collection
&& this.collectionUnloaded('*') && this.collectionUnloaded('*')
@ -588,6 +582,35 @@ var CollectionActions = actions.Actions({
delete this.__collection_order delete this.__collection_order
delete this.location.collection delete this.location.collection
}], }],
clone: [function(full){
return function(res){
if(this.collections){
var cur = this.collections
if(this.collection){
res.location.collection = this.collection
}
collections = res.collections = {}
this.collection_order
.forEach(function(title){
var c = collections[title] = {
title: title,
}
if(cur[title].data){
c.data = cur[title].data.clone()
}
if(cur[title].crop_stack){
c.crop_stack = cur[title].crop_stack
.map(function(d){ return d.clone() })
}
})
}
} }],
}) })

View File

@ -17,6 +17,8 @@
* - introspection * - introspection
* - lifecycle * - lifecycle
* base life-cycle events (start/stop/..) * base life-cycle events (start/stop/..)
* - serialization
* base methods to handle loading, serialization and cloning...
* - util * - util
* - journal * - journal
* action journaling and undo/redo functionality * action journaling and undo/redo functionality
@ -537,6 +539,29 @@ module.LifeCycle = ImageGridFeatures.Feature({
}) })
//---------------------------------------------------------------------
var SerializationActions = actions.Actions({
clone: ['- System/',
function(full){ return actions.MetaActions.clone.call(this, full) }],
json: ['- System/',
function(){ return {} }],
load: ['- System/',
function(){ }],
clear: ['- Sustem/',
function(){ }],
})
var Serialization =
module.Serialization = ImageGridFeatures.Feature({
title: '',
tag: 'serialization',
actions: SerializationActions,
})
//--------------------------------------------------------------------- //---------------------------------------------------------------------
var UtilActions = actions.Actions({ var UtilActions = actions.Actions({
@ -554,7 +579,6 @@ var UtilActions = actions.Actions({
}], }],
}) })
var Util = var Util =
module.Util = ImageGridFeatures.Feature({ module.Util = ImageGridFeatures.Feature({
title: '', title: '',
@ -798,6 +822,9 @@ module.Journal = ImageGridFeatures.Feature({
title: 'Action Journal', title: 'Action Journal',
tag: 'journal', tag: 'journal',
depends: [
'serialization',
],
actions: JournalActions, actions: JournalActions,
@ -933,7 +960,9 @@ module.Changes = ImageGridFeatures.Feature({
doc: '', doc: '',
tag: 'changes', tag: 'changes',
depends: [ ], depends: [
'serialization',
],
actions: ChangesActions, actions: ChangesActions,
}) })

View File

@ -345,12 +345,12 @@ var LocationActions = actions.Actions({
// .location too... // .location too...
this.__location = data.location this.__location = data.location
}}], }}],
clone: [ clone: [function(){
function(res){ return function(res){
if(this.location){ if(this.location){
res.__location = JSON.parse(JSON.stringify(this.__location)) res.__location = JSON.parse(JSON.stringify(this.__location))
} }
}], }}],
clear: [function(){ clear: [function(){
this.clearLoaction() }], this.clearLoaction() }],
}) })