cleanup in actions + added .dump() action...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-11-17 04:24:07 +03:00
parent ce3d13ea9e
commit 4a6d7dcc56
2 changed files with 18 additions and 15 deletions

View File

@ -181,6 +181,7 @@ if(typeof(args2array) != 'function'){
// .section // .section
// .category // .category
// ... // ...
// XXX might be a good idea to add an option to return the full results...
var Action = var Action =
module.Action = module.Action =
function Action(name, doc, ldoc, func){ function Action(name, doc, ldoc, func){
@ -228,30 +229,27 @@ function Action(name, doc, ldoc, func){
handlers = handlers handlers = handlers
.map(function(h){ return h.apply(that, args) }) .map(function(h){ return h.apply(that, args) })
// XXX use the last return as result...
var res = handlers.slice(-1)[0]
// NOTE: this action will get included and called by the code // NOTE: this action will get included and called by the code
// above and below, so no need to explicitly call func... // above and below, so no need to explicitly call func...
// call handlers -- post phase... // call handlers -- post phase...
// NOTE: post handlers need to get called last run pre first run post... // NOTE: post handlers need to get called last run pre first run post...
handlers.reverse().forEach(function(h, i){ var results = handlers.reverse().map(function(h, i){
// function... // function...
if(h instanceof Function){ if(h instanceof Function){
var r = h.apply(that, args) return h.apply(that, args)
res = i == 0 ? r : res
// deferred... // deferred...
} else if(h != null && h.resolve instanceof Function){ } else if(h != null && h.resolve instanceof Function){
h.resolve() return h.resolve()
res = i == 0 ? h : res
} }
return h
}) })
// XXX is this the right way to go? // XXX might be a good idea to add an option to return the full
return res !== undefined ? res : this // results...
//return this return results[0] !== undefined ? results[0] : this
} }
meth.__proto__ = this.__proto__ meth.__proto__ = this.__proto__

View File

@ -216,12 +216,17 @@ actions.Actions({
// XXX experimental... // XXX experimental...
// ...the bad thing about this is that we can not extend this, // ...the bad thing about this is that we can not extend this,
// adding new items to the resulting structure... // adding new items to the resulting structure...
// XXX is this the correct way to go???
// ...can we save simple attribute values???
dump: ['Dump state as JSOM object', dump: ['Dump state as JSOM object',
function(){ function(){
return { var res = {}
data: this.data.dumpJSON(), for(var k in this){
images: this.images != null ? this.images.dumpJSON() : null if(this[k] != null && this[k].dumpJSON != null){
res[k] = this[k].dumpJSON()
} }
}
return res
}], }],