some refactoring...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-03-08 20:05:49 +03:00
parent 1c29da7ee7
commit 59dc0d01c5
2 changed files with 35 additions and 24 deletions

View File

@ -563,14 +563,17 @@ var FileSystemLoaderActions = actions.Actions({
// load the data... // load the data...
.then(function(imgs){ .then(function(imgs){
that.loadOrRecover({ that.loadOrRecover({
images: imgs, images: imgs,
data: data.Data.fromArray(imgs.keys()), data: data.Data.fromArray(imgs.keys()),
location: { location: {
path: path, path: path,
method: 'loadImages', method: 'loadImages',
} }
}) })
.then(function(){
delete that.changes
})
}) })
}], }],

View File

@ -54,31 +54,39 @@ var RecoverActions = actions.Actions({
// parent actions at this point... // parent actions at this point...
loadOrRecover: ['- Location/', loadOrRecover: ['- Location/',
function(data){ function(data){
// this is the critical section, after this point we var that = this
// are doing the actual loading.... return new Promise(function(resolve, reject){
try { // this is the critical section, after this point we
// are doing the actual loading....
try {
this.load(data) that.load(data)
// something bad happened, clear and handle it... resolve(data)
} catch(err){
this.clear()
console.error(err) // something bad happened, clear and handle it...
} catch(err){
that.clear()
// recover to last location... console.error(err)
if(this.__recover){
this.recover()
// fail... // recover to last location...
} else { if(that.__recover){
// clear the recovery data... that.recover()
delete this.__recover
reject('recovered')
// fail... // fail...
throw err } else {
// clear the recovery data...
delete that.__recover
// fail...
//throw err
reject(err)
}
} }
} })
}], }],
// Recover from load error... // Recover from load error...