mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
added queue handler actions + refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
2a75ed6530
commit
71b9b444cb
@ -2519,6 +2519,7 @@ function(func){
|
||||
// automate this...
|
||||
// ...would also be nice to automate this via a chunk iterator so
|
||||
// as not to block...
|
||||
// XXX handle errors... (???)
|
||||
var queuedAction =
|
||||
module.queuedAction =
|
||||
function(name, func){
|
||||
@ -2529,7 +2530,6 @@ function(name, func){
|
||||
return object.mixin(
|
||||
Queued(function(...args){
|
||||
var that = this
|
||||
// XXX handle errors... (???)
|
||||
return new Promise(function(resolve, reject){
|
||||
that.queue(name, opts || {})
|
||||
.push(function(){
|
||||
@ -2543,6 +2543,32 @@ function(name, func){
|
||||
}) }
|
||||
|
||||
|
||||
var queueHandler =
|
||||
module.queueHandler =
|
||||
function(name, func){
|
||||
var args = [...arguments]
|
||||
func = args.pop()
|
||||
var [name, opts] = args
|
||||
|
||||
return object.mixin(
|
||||
Queued(function(items, ...args){
|
||||
var that = this
|
||||
return new Promise(function(resolve, reject){
|
||||
var q = that.queue(name,
|
||||
Object.assign(
|
||||
{},
|
||||
opts || {},
|
||||
{ handler: function(item){
|
||||
return func.call(that, item, ...args) } }))
|
||||
q.push(...(items instanceof Array ? items : [items]))
|
||||
q.then(resolve, reject) }) }),
|
||||
{
|
||||
toString: function(){
|
||||
return `core.queueHandler('${name}',\n\t${
|
||||
object.normalizeIndent( '\t'+ func.toString() ) })` },
|
||||
}) }
|
||||
|
||||
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
||||
|
||||
@ -279,6 +279,13 @@ var ExampleActions = actions.Actions({
|
||||
for(var i=0; i<count; i++){
|
||||
this.exampleQueuedAction(timeout) } }],
|
||||
|
||||
exampleQueueHandlerAction: ['- Test/',
|
||||
core.queueHandler('exampleQueueHandlerAction', {quiet: true},
|
||||
function(item, ...args){
|
||||
console.log('Queue handler action!!', item, ...args)
|
||||
return new Promise(function(resolve){
|
||||
setTimeout(resolve, 100) }) })],
|
||||
|
||||
//
|
||||
// NOTE: action name and task name should be the same to avoid
|
||||
// confusion...
|
||||
|
||||
@ -25,8 +25,6 @@ if(typeof(process) != 'undefined'){
|
||||
|
||||
var util = require('lib/util')
|
||||
var toggler = require('lib/toggler')
|
||||
// XXX do we need this???
|
||||
var tasks = require('lib/tasks')
|
||||
var keyboard = require('lib/keyboard')
|
||||
|
||||
var actions = require('lib/actions')
|
||||
@ -101,8 +99,6 @@ module.Metadata = core.ImageGridFeatures.Feature({
|
||||
var MetadataReaderActions = actions.Actions({
|
||||
// NOTE: this will read both stat and metadata...
|
||||
//
|
||||
// XXX add support to taskqueue...
|
||||
// XXX should this process multiple images???
|
||||
// XXX also check the metadata/ folder (???)
|
||||
// XXX this uses .markChanged(..) form filesystem.FileSystemWriter
|
||||
// feature, but technically does not depend on it...
|
||||
@ -119,7 +115,7 @@ var MetadataReaderActions = actions.Actions({
|
||||
|
||||
NOTE: also see: .cacheMetadata(..)
|
||||
`,
|
||||
core.queuedAction('readMetadata', function(image, force){
|
||||
core.queueHandler('Read image metadata', function(image, force){
|
||||
var that = this
|
||||
|
||||
var gid = this.data.getImage(image)
|
||||
@ -180,14 +176,8 @@ var MetadataReaderActions = actions.Actions({
|
||||
&& that.markChanged('images', [gid]) }
|
||||
|
||||
resolve(data) }) }) }) })],
|
||||
|
||||
readAllMetadata: ['File/Read all metadata',
|
||||
function(){
|
||||
var that = this
|
||||
//var logger = this.logger && this.logger.push('Read metadata')
|
||||
return this.images.keys()
|
||||
.mapChunks(7, function(gid){
|
||||
return that.readMetadata(gid) }) }],
|
||||
'readMetadata: images.gids ...'],
|
||||
|
||||
// XXX take image Metadata and write it to target...
|
||||
writeMetadata: ['- Image/Set metadata data',
|
||||
|
||||
@ -588,6 +588,7 @@ var SharpActions = actions.Actions({
|
||||
Promise.reject('aborted')
|
||||
: res.flat() }) })],
|
||||
|
||||
// XXX will this be better off as a queueHandler(..) ???
|
||||
// XXX add support for offloading the processing to a thread/worker...
|
||||
__cache_metadata_reading: null,
|
||||
cacheMetadata: ['- Sharp|Image/',
|
||||
|
||||
@ -368,6 +368,9 @@ module.ImagesPrototype = {
|
||||
get length(){
|
||||
return this.keys().length },
|
||||
|
||||
get gids(){
|
||||
return this.keys() },
|
||||
|
||||
// Generic iterators...
|
||||
//
|
||||
// function format:
|
||||
@ -376,62 +379,31 @@ module.ImagesPrototype = {
|
||||
// reduce function format:
|
||||
// function(value1, value2, key, index, object)
|
||||
//
|
||||
//
|
||||
// this will be set to the value...
|
||||
//
|
||||
// XXX are these slower than doing it manualy via Object.keys(..)
|
||||
// XXX use .keys()
|
||||
forEach: function(func){
|
||||
var i = 0
|
||||
for(var key in this){
|
||||
// reject non images...
|
||||
// XXX make this cleaner...
|
||||
if(key == 'length'
|
||||
|| key == 'version'
|
||||
|| this[key] instanceof Function){
|
||||
continue }
|
||||
func.call(this[key], key, this[key], i++, this) }
|
||||
return this },
|
||||
filter: function(func){
|
||||
var that = this
|
||||
var res = new this.constructor()
|
||||
var i = 0
|
||||
for(var key in this){
|
||||
// reject non images...
|
||||
// XXX make this cleaner...
|
||||
if(key == 'length'
|
||||
|| key == 'version'
|
||||
|| this[key] instanceof Function){
|
||||
continue }
|
||||
if(func.call(this[key], key, this[key], i++, this)){
|
||||
res[key] = this[key] } }
|
||||
this.forEach(function(key, i){
|
||||
if(func.call(that[key], key, that[key], i++, that)){
|
||||
res[key] = that[key] } })
|
||||
return res },
|
||||
// NOTE: .map(..) and .reduce(..) will not return Images objects...
|
||||
map: function(func){
|
||||
//var res = this.constructor()
|
||||
var res = []
|
||||
var i = 0
|
||||
for(var key in this){
|
||||
// reject non images...
|
||||
// XXX make this cleaner...
|
||||
if(key == 'length'
|
||||
|| key == 'version'
|
||||
|| this[key] instanceof Function){
|
||||
continue }
|
||||
//res[key] = func.call(this[key], key, this[key], i++, this)
|
||||
res.push(func.call(this[key], key, this[key], i++, this)) }
|
||||
return res },
|
||||
var that = this
|
||||
return this.gids
|
||||
.map(function(key, i){
|
||||
return that[key] instanceof Function ?
|
||||
[]
|
||||
: [func.call(that[key], key, that[key], i++, that)] })
|
||||
.flat() },
|
||||
reduce: function(func, initial){
|
||||
var that = this
|
||||
var res = initial
|
||||
var i = 0
|
||||
for(var key in this){
|
||||
// reject non images...
|
||||
// XXX make this cleaner...
|
||||
if(key == 'length'
|
||||
|| key == 'version'
|
||||
|| this[key] instanceof Function){
|
||||
continue }
|
||||
res = func.call(this[key], res, this[key], key, i++, this) }
|
||||
this.forEach(function(key, i){
|
||||
res = func.call(that[key], res, that[key], key, i++, that) })
|
||||
return res },
|
||||
forEach: function(func){
|
||||
this.map(func)
|
||||
return this },
|
||||
|
||||
// make images iterable...
|
||||
[Symbol.iterator]: function*(){
|
||||
@ -440,12 +412,12 @@ module.ImagesPrototype = {
|
||||
// XXX make this cleaner...
|
||||
if(key == 'length'
|
||||
|| key == 'version'
|
||||
|| key == 'gids'
|
||||
|| this[key] instanceof Function){
|
||||
continue }
|
||||
yield [key, this[key]] } },
|
||||
iter: function*(){
|
||||
for(e of this){
|
||||
yield e } },
|
||||
yield* this },
|
||||
|
||||
keys: function(){
|
||||
var keys = Object.keys(this)
|
||||
|
||||
6
Viewer/package-lock.json
generated
6
Viewer/package-lock.json
generated
@ -1110,9 +1110,9 @@
|
||||
"integrity": "sha512-9kZM80Js9/eTwXN9VXwLDC1wDJ7gIAdYU9GIzb5KJmNcLAMaW+zhgFrwFFMrcSfggUuadgnqSrS41E4XLe8JZw=="
|
||||
},
|
||||
"ig-types": {
|
||||
"version": "5.0.29",
|
||||
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.29.tgz",
|
||||
"integrity": "sha512-fEHd9qpOz994Meu1dT3cO3N8bwlA6XR7CD608nwM92rjwWSMQcTv5jTULz63eXH1/3otsU4bgWnsjKGDD8zLVw==",
|
||||
"version": "5.0.30",
|
||||
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.30.tgz",
|
||||
"integrity": "sha512-qiE99PB96iEYeygRQTaB1CnJR+1AAAQ/qMmXBKVsbIroAQPveRVXptJIEcPGu6t8AdshibcaLkmLvcEHjMbN0A==",
|
||||
"requires": {
|
||||
"ig-object": "^5.4.12",
|
||||
"object-run": "^1.0.1"
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
"ig-argv": "^2.15.0",
|
||||
"ig-features": "^3.4.2",
|
||||
"ig-object": "^5.4.12",
|
||||
"ig-types": "^5.0.29",
|
||||
"ig-types": "^5.0.30",
|
||||
"moment": "^2.29.1",
|
||||
"object-run": "^1.0.1",
|
||||
"requirejs": "^2.3.6",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user