some refactoring + bugfixes...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2015-12-08 07:42:07 +03:00
parent 9de88ea5db
commit 005e6f9c23
11 changed files with 52 additions and 84 deletions

View File

@ -12,7 +12,7 @@ define(function(require){ var module = {}
console.log('>>> data') console.log('>>> data')
var object = require('object') var object = require('lib/object')
var formats = require('formats') var formats = require('formats')
var sha1 = require('./ext-lib/sha1') var sha1 = require('./ext-lib/sha1')

View File

@ -179,6 +179,7 @@ function loadJSON(path){
// a) error // a) error
// b) append '**' (current behavior) // b) append '**' (current behavior)
// ...(a) seems more logical... // ...(a) seems more logical...
// XXX do a task version...
var loadIndex = var loadIndex =
module.loadIndex = module.loadIndex =
function(path, index_dir, logger){ function(path, index_dir, logger){
@ -457,6 +458,16 @@ function(base, previews, index_dir, absolute_path){
} }
// XXX
var copyPreviews =
module.copyPreviews =
function(){
var q = tasks.Queue.clone()
// XXX
}
// Build a data and images objects from the json returned by loadIndex(..) // Build a data and images objects from the json returned by loadIndex(..)
// //

View File

@ -11,7 +11,7 @@ console.log('>>> images')
var sha1 = require('./ext-lib/sha1') var sha1 = require('./ext-lib/sha1')
var object = require('object') var object = require('lib/object')

View File

@ -51,7 +51,11 @@ function makeConstructor(name, a, b){
obj.__proto__ = _constructor.prototype obj.__proto__ = _constructor.prototype
// XXX for some reason this does not resolve from .__proto__ // XXX for some reason this does not resolve from .__proto__
// XXX this also is a regular attr and not a prop... // XXX this also is a regular attr and not a prop...
obj.constructor = _constructor //obj.constructor = _constructor
Object.defineProperty(obj, 'constructor', {
value: _constructor,
enumerable: false,
})
//obj.__proto__.constructor = _constructor //obj.__proto__.constructor = _constructor

View File

@ -10,80 +10,14 @@ console.log('>>> tasks')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
var actions = require('lib/actions') var actions = require('lib/actions')
var object = require('lib/object')
/*********************************************************************/ /*********************************************************************/
/* var QueueActions =
var Promise = require('promise') module.QueueActions = actions.Actions({
function PTask(fn) {
if (!(this instanceof PTask)){
return new PTask(fn)
}
Promise.call(this, fn)
}
PTask.prototype = Object.create(Promise.prototype)
PTask.prototype.constructor = PTask
PTask.prototype.spread = function (cb) {
return this.then(function (arr) {
return cb.apply(this, arr);
})
}
*/
/*********************************************************************/
// XXX experimental...
// Create a task...
//
// Task(<func>, <arg>[, ...])
// -> <task>
//
// A task is a deferred like object that runs a function returning a
// deferred and adds to it the ability to restart.
//
// Restarting is possible only of the original is rejected.
//
// Restarting will call the original function with the original set of
// arguments and reset the task.
//
// XXX this depends on that func(..) will return a deferred...
// XXX restarting will not transfer the handlers...
// ...this might be a deal breaker...
module.Task = function(func){
var args = [].slice.call(arguments)
// remove func from args...
args.splice(0, 1)
return ({
restart: function(){
// XXX jQuery compatible, need promise state check...
if(this.isRejected == null || this.isRejected()){
this.__proto__ = func.apply(null, args)
}
return this
},
}).restart()
}
/*********************************************************************/
module.TaskPrototype = {
}
/*********************************************************************/
var Queue =
module.Queue = actions.Actions({
config: { config: {
'running-pool-size': 8, 'running-pool-size': 8,
// XXX at this point these is ignored... // XXX at this point these is ignored...
@ -139,6 +73,7 @@ module.Queue = actions.Actions({
taskStarted: ['', function(){}], taskStarted: ['', function(){}],
taskFailed: ['', function(){}], taskFailed: ['', function(){}],
taskDone: ['', function(){}], taskDone: ['', function(){}],
allTasksDone: ['', function(){}],
// task manipulation actions... // task manipulation actions...
@ -326,6 +261,15 @@ module.Queue = actions.Actions({
// XXX // XXX
failed.push(elem) failed.push(elem)
that.taskFailed(elem[0], task) that.taskFailed(elem[0], task)
// run some more...
that._run()
// queue empty...
if(this.__ready && this.__ready.len == 0
&& this.__running && this.__running.len == 0){
this.allTasksDone()
}
}) })
// push to done and ._run some more... // push to done and ._run some more...
.then(function(){ .then(function(){
@ -336,10 +280,16 @@ module.Queue = actions.Actions({
var done = that.__done = that.__done || [] var done = that.__done = that.__done || []
done.push(elem) done.push(elem)
that.taskDone(elem[0], task)
// run some more... // run some more...
that._run() that._run()
that.taskDone(elem[0], task)
// queue empty...
if(this.__ready && this.__ready.len == 0
&& this.__running && this.__running.len == 0){
this.allTasksDone()
}
}) })
// other... // other...
@ -353,8 +303,11 @@ module.Queue = actions.Actions({
done.push(elem) done.push(elem)
that.taskDone(elem[0], task) that.taskDone(elem[0], task)
// run some more... // queue empty...
that._run() if(this.__ready && this.__ready.len == 0
&& this.__running && this.__running.len == 0){
this.allTasksDone()
}
} }
})() } })() }
@ -383,9 +336,9 @@ module.Queue = actions.Actions({
}) })
var Queue =
// XXX need to make the queue usable as an object... module.Queue =
// XXX object.makeConstructor('Queue', QueueActions)

View File

@ -16,7 +16,7 @@ console.log('>>> browse-walk')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
var object = require('../../object') var object = require('../object')
var browse = require('./browse') var browse = require('./browse')

View File

@ -22,7 +22,7 @@ console.log('>>> browse')
//var promise = require('promise') //var promise = require('promise')
var keyboard = require('../keyboard') var keyboard = require('../keyboard')
var object = require('../../object') var object = require('../object')
var widget = require('./widget') var widget = require('./widget')

View File

@ -10,7 +10,7 @@ console.log('>>> drawer')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
var keyboard = require('../keyboard') var keyboard = require('../keyboard')
var object = require('../../object') var object = require('../object')
var widget = require('./widget') var widget = require('./widget')

View File

@ -10,7 +10,7 @@ console.log('>>> overlay')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
var keyboard = require('../keyboard') var keyboard = require('../keyboard')
var object = require('../../object') var object = require('../object')
var widget = require('./widget') var widget = require('./widget')

View File

@ -10,7 +10,7 @@ console.log('>>> widget')
//var DEBUG = DEBUG != null ? DEBUG : true //var DEBUG = DEBUG != null ? DEBUG : true
var keyboard = require('../keyboard') var keyboard = require('../keyboard')
var object = require('../../object') var object = require('../object')

View File

@ -13,7 +13,7 @@ console.log('>>> ribbons')
// XXX is this correct... // XXX is this correct...
//require('ext-lib/jquery') //require('ext-lib/jquery')
var object = require('object') var object = require('lib/object')
var data = require('data') var data = require('data')
var images = require('images') var images = require('images')