From 005e6f9c2342751bb43f1e93c4c8701145432eca Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 8 Dec 2015 07:42:07 +0300 Subject: [PATCH] some refactoring + bugfixes... Signed-off-by: Alex A. Naanou --- ui (gen4)/data.js | 2 +- ui (gen4)/file.js | 11 +++ ui (gen4)/images.js | 2 +- ui (gen4)/{ => lib}/object.js | 6 +- ui (gen4)/lib/tasks.js | 103 ++++++++-------------------- ui (gen4)/lib/widget/browse-walk.js | 2 +- ui (gen4)/lib/widget/browse.js | 2 +- ui (gen4)/lib/widget/drawer.js | 2 +- ui (gen4)/lib/widget/overlay.js | 2 +- ui (gen4)/lib/widget/widget.js | 2 +- ui (gen4)/ribbons.js | 2 +- 11 files changed, 52 insertions(+), 84 deletions(-) rename ui (gen4)/{ => lib}/object.js (92%) diff --git a/ui (gen4)/data.js b/ui (gen4)/data.js index 684a2f51..e391624c 100755 --- a/ui (gen4)/data.js +++ b/ui (gen4)/data.js @@ -12,7 +12,7 @@ define(function(require){ var module = {} console.log('>>> data') -var object = require('object') +var object = require('lib/object') var formats = require('formats') var sha1 = require('./ext-lib/sha1') diff --git a/ui (gen4)/file.js b/ui (gen4)/file.js index b6f6afce..0675b173 100755 --- a/ui (gen4)/file.js +++ b/ui (gen4)/file.js @@ -179,6 +179,7 @@ function loadJSON(path){ // a) error // b) append '**' (current behavior) // ...(a) seems more logical... +// XXX do a task version... var loadIndex = module.loadIndex = 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(..) // diff --git a/ui (gen4)/images.js b/ui (gen4)/images.js index 07102693..bb5b5aa2 100755 --- a/ui (gen4)/images.js +++ b/ui (gen4)/images.js @@ -11,7 +11,7 @@ console.log('>>> images') var sha1 = require('./ext-lib/sha1') -var object = require('object') +var object = require('lib/object') diff --git a/ui (gen4)/object.js b/ui (gen4)/lib/object.js similarity index 92% rename from ui (gen4)/object.js rename to ui (gen4)/lib/object.js index cedd3684..213de060 100755 --- a/ui (gen4)/object.js +++ b/ui (gen4)/lib/object.js @@ -51,7 +51,11 @@ function makeConstructor(name, a, b){ obj.__proto__ = _constructor.prototype // XXX for some reason this does not resolve from .__proto__ // 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 diff --git a/ui (gen4)/lib/tasks.js b/ui (gen4)/lib/tasks.js index 1832e40e..8c1d24ca 100755 --- a/ui (gen4)/lib/tasks.js +++ b/ui (gen4)/lib/tasks.js @@ -10,80 +10,14 @@ console.log('>>> tasks') //var DEBUG = DEBUG != null ? DEBUG : true var actions = require('lib/actions') +var object = require('lib/object') /*********************************************************************/ -/* -var Promise = require('promise') - -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(, [, ...]) -// -> -// -// 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({ +var QueueActions = +module.QueueActions = actions.Actions({ config: { 'running-pool-size': 8, // XXX at this point these is ignored... @@ -139,6 +73,7 @@ module.Queue = actions.Actions({ taskStarted: ['', function(){}], taskFailed: ['', function(){}], taskDone: ['', function(){}], + allTasksDone: ['', function(){}], // task manipulation actions... @@ -326,6 +261,15 @@ module.Queue = actions.Actions({ // XXX failed.push(elem) 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... .then(function(){ @@ -336,10 +280,16 @@ module.Queue = actions.Actions({ var done = that.__done = that.__done || [] done.push(elem) + that.taskDone(elem[0], task) // run some more... 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... @@ -353,8 +303,11 @@ module.Queue = actions.Actions({ done.push(elem) that.taskDone(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() + } } })() } @@ -383,9 +336,9 @@ module.Queue = actions.Actions({ }) - -// XXX need to make the queue usable as an object... -// XXX +var Queue = +module.Queue = +object.makeConstructor('Queue', QueueActions) diff --git a/ui (gen4)/lib/widget/browse-walk.js b/ui (gen4)/lib/widget/browse-walk.js index b31fed3e..943ee6a7 100755 --- a/ui (gen4)/lib/widget/browse-walk.js +++ b/ui (gen4)/lib/widget/browse-walk.js @@ -16,7 +16,7 @@ console.log('>>> browse-walk') //var DEBUG = DEBUG != null ? DEBUG : true -var object = require('../../object') +var object = require('../object') var browse = require('./browse') diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index dda2abb5..2d5fb763 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -22,7 +22,7 @@ console.log('>>> browse') //var promise = require('promise') var keyboard = require('../keyboard') -var object = require('../../object') +var object = require('../object') var widget = require('./widget') diff --git a/ui (gen4)/lib/widget/drawer.js b/ui (gen4)/lib/widget/drawer.js index faf8860d..d4b0b5d6 100755 --- a/ui (gen4)/lib/widget/drawer.js +++ b/ui (gen4)/lib/widget/drawer.js @@ -10,7 +10,7 @@ console.log('>>> drawer') //var DEBUG = DEBUG != null ? DEBUG : true var keyboard = require('../keyboard') -var object = require('../../object') +var object = require('../object') var widget = require('./widget') diff --git a/ui (gen4)/lib/widget/overlay.js b/ui (gen4)/lib/widget/overlay.js index b43fc425..77117289 100755 --- a/ui (gen4)/lib/widget/overlay.js +++ b/ui (gen4)/lib/widget/overlay.js @@ -10,7 +10,7 @@ console.log('>>> overlay') //var DEBUG = DEBUG != null ? DEBUG : true var keyboard = require('../keyboard') -var object = require('../../object') +var object = require('../object') var widget = require('./widget') diff --git a/ui (gen4)/lib/widget/widget.js b/ui (gen4)/lib/widget/widget.js index 48740c35..23bc978d 100755 --- a/ui (gen4)/lib/widget/widget.js +++ b/ui (gen4)/lib/widget/widget.js @@ -10,7 +10,7 @@ console.log('>>> widget') //var DEBUG = DEBUG != null ? DEBUG : true var keyboard = require('../keyboard') -var object = require('../../object') +var object = require('../object') diff --git a/ui (gen4)/ribbons.js b/ui (gen4)/ribbons.js index c1e37ac5..1d58f22b 100755 --- a/ui (gen4)/ribbons.js +++ b/ui (gen4)/ribbons.js @@ -13,7 +13,7 @@ console.log('>>> ribbons') // XXX is this correct... //require('ext-lib/jquery') -var object = require('object') +var object = require('lib/object') var data = require('data') var images = require('images')