mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +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...
|
// automate this...
|
||||||
// ...would also be nice to automate this via a chunk iterator so
|
// ...would also be nice to automate this via a chunk iterator so
|
||||||
// as not to block...
|
// as not to block...
|
||||||
|
// XXX handle errors... (???)
|
||||||
var queuedAction =
|
var queuedAction =
|
||||||
module.queuedAction =
|
module.queuedAction =
|
||||||
function(name, func){
|
function(name, func){
|
||||||
@ -2529,7 +2530,6 @@ function(name, func){
|
|||||||
return object.mixin(
|
return object.mixin(
|
||||||
Queued(function(...args){
|
Queued(function(...args){
|
||||||
var that = this
|
var that = this
|
||||||
// XXX handle errors... (???)
|
|
||||||
return new Promise(function(resolve, reject){
|
return new Promise(function(resolve, reject){
|
||||||
that.queue(name, opts || {})
|
that.queue(name, opts || {})
|
||||||
.push(function(){
|
.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++){
|
for(var i=0; i<count; i++){
|
||||||
this.exampleQueuedAction(timeout) } }],
|
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
|
// NOTE: action name and task name should be the same to avoid
|
||||||
// confusion...
|
// confusion...
|
||||||
|
|||||||
@ -25,8 +25,6 @@ if(typeof(process) != 'undefined'){
|
|||||||
|
|
||||||
var util = require('lib/util')
|
var util = require('lib/util')
|
||||||
var toggler = require('lib/toggler')
|
var toggler = require('lib/toggler')
|
||||||
// XXX do we need this???
|
|
||||||
var tasks = require('lib/tasks')
|
|
||||||
var keyboard = require('lib/keyboard')
|
var keyboard = require('lib/keyboard')
|
||||||
|
|
||||||
var actions = require('lib/actions')
|
var actions = require('lib/actions')
|
||||||
@ -101,8 +99,6 @@ module.Metadata = core.ImageGridFeatures.Feature({
|
|||||||
var MetadataReaderActions = actions.Actions({
|
var MetadataReaderActions = actions.Actions({
|
||||||
// NOTE: this will read both stat and metadata...
|
// 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 also check the metadata/ folder (???)
|
||||||
// XXX this uses .markChanged(..) form filesystem.FileSystemWriter
|
// XXX this uses .markChanged(..) form filesystem.FileSystemWriter
|
||||||
// feature, but technically does not depend on it...
|
// feature, but technically does not depend on it...
|
||||||
@ -119,7 +115,7 @@ var MetadataReaderActions = actions.Actions({
|
|||||||
|
|
||||||
NOTE: also see: .cacheMetadata(..)
|
NOTE: also see: .cacheMetadata(..)
|
||||||
`,
|
`,
|
||||||
core.queuedAction('readMetadata', function(image, force){
|
core.queueHandler('Read image metadata', function(image, force){
|
||||||
var that = this
|
var that = this
|
||||||
|
|
||||||
var gid = this.data.getImage(image)
|
var gid = this.data.getImage(image)
|
||||||
@ -180,14 +176,8 @@ var MetadataReaderActions = actions.Actions({
|
|||||||
&& that.markChanged('images', [gid]) }
|
&& that.markChanged('images', [gid]) }
|
||||||
|
|
||||||
resolve(data) }) }) }) })],
|
resolve(data) }) }) }) })],
|
||||||
|
|
||||||
readAllMetadata: ['File/Read all metadata',
|
readAllMetadata: ['File/Read all metadata',
|
||||||
function(){
|
'readMetadata: images.gids ...'],
|
||||||
var that = this
|
|
||||||
//var logger = this.logger && this.logger.push('Read metadata')
|
|
||||||
return this.images.keys()
|
|
||||||
.mapChunks(7, function(gid){
|
|
||||||
return that.readMetadata(gid) }) }],
|
|
||||||
|
|
||||||
// XXX take image Metadata and write it to target...
|
// XXX take image Metadata and write it to target...
|
||||||
writeMetadata: ['- Image/Set metadata data',
|
writeMetadata: ['- Image/Set metadata data',
|
||||||
|
|||||||
@ -588,6 +588,7 @@ var SharpActions = actions.Actions({
|
|||||||
Promise.reject('aborted')
|
Promise.reject('aborted')
|
||||||
: res.flat() }) })],
|
: res.flat() }) })],
|
||||||
|
|
||||||
|
// XXX will this be better off as a queueHandler(..) ???
|
||||||
// XXX add support for offloading the processing to a thread/worker...
|
// XXX add support for offloading the processing to a thread/worker...
|
||||||
__cache_metadata_reading: null,
|
__cache_metadata_reading: null,
|
||||||
cacheMetadata: ['- Sharp|Image/',
|
cacheMetadata: ['- Sharp|Image/',
|
||||||
|
|||||||
@ -368,6 +368,9 @@ module.ImagesPrototype = {
|
|||||||
get length(){
|
get length(){
|
||||||
return this.keys().length },
|
return this.keys().length },
|
||||||
|
|
||||||
|
get gids(){
|
||||||
|
return this.keys() },
|
||||||
|
|
||||||
// Generic iterators...
|
// Generic iterators...
|
||||||
//
|
//
|
||||||
// function format:
|
// function format:
|
||||||
@ -376,62 +379,31 @@ module.ImagesPrototype = {
|
|||||||
// reduce function format:
|
// reduce function format:
|
||||||
// function(value1, value2, key, index, object)
|
// 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){
|
filter: function(func){
|
||||||
|
var that = this
|
||||||
var res = new this.constructor()
|
var res = new this.constructor()
|
||||||
var i = 0
|
this.forEach(function(key, i){
|
||||||
for(var key in this){
|
if(func.call(that[key], key, that[key], i++, that)){
|
||||||
// reject non images...
|
res[key] = that[key] } })
|
||||||
// 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] } }
|
|
||||||
return res },
|
return res },
|
||||||
// NOTE: .map(..) and .reduce(..) will not return Images objects...
|
// NOTE: .map(..) and .reduce(..) will not return Images objects...
|
||||||
map: function(func){
|
map: function(func){
|
||||||
//var res = this.constructor()
|
var that = this
|
||||||
var res = []
|
return this.gids
|
||||||
var i = 0
|
.map(function(key, i){
|
||||||
for(var key in this){
|
return that[key] instanceof Function ?
|
||||||
// reject non images...
|
[]
|
||||||
// XXX make this cleaner...
|
: [func.call(that[key], key, that[key], i++, that)] })
|
||||||
if(key == 'length'
|
.flat() },
|
||||||
|| 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 },
|
|
||||||
reduce: function(func, initial){
|
reduce: function(func, initial){
|
||||||
|
var that = this
|
||||||
var res = initial
|
var res = initial
|
||||||
var i = 0
|
this.forEach(function(key, i){
|
||||||
for(var key in this){
|
res = func.call(that[key], res, that[key], key, i++, that) })
|
||||||
// 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) }
|
|
||||||
return res },
|
return res },
|
||||||
|
forEach: function(func){
|
||||||
|
this.map(func)
|
||||||
|
return this },
|
||||||
|
|
||||||
// make images iterable...
|
// make images iterable...
|
||||||
[Symbol.iterator]: function*(){
|
[Symbol.iterator]: function*(){
|
||||||
@ -440,12 +412,12 @@ module.ImagesPrototype = {
|
|||||||
// XXX make this cleaner...
|
// XXX make this cleaner...
|
||||||
if(key == 'length'
|
if(key == 'length'
|
||||||
|| key == 'version'
|
|| key == 'version'
|
||||||
|
|| key == 'gids'
|
||||||
|| this[key] instanceof Function){
|
|| this[key] instanceof Function){
|
||||||
continue }
|
continue }
|
||||||
yield [key, this[key]] } },
|
yield [key, this[key]] } },
|
||||||
iter: function*(){
|
iter: function*(){
|
||||||
for(e of this){
|
yield* this },
|
||||||
yield e } },
|
|
||||||
|
|
||||||
keys: function(){
|
keys: function(){
|
||||||
var keys = Object.keys(this)
|
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=="
|
"integrity": "sha512-9kZM80Js9/eTwXN9VXwLDC1wDJ7gIAdYU9GIzb5KJmNcLAMaW+zhgFrwFFMrcSfggUuadgnqSrS41E4XLe8JZw=="
|
||||||
},
|
},
|
||||||
"ig-types": {
|
"ig-types": {
|
||||||
"version": "5.0.29",
|
"version": "5.0.30",
|
||||||
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.29.tgz",
|
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.30.tgz",
|
||||||
"integrity": "sha512-fEHd9qpOz994Meu1dT3cO3N8bwlA6XR7CD608nwM92rjwWSMQcTv5jTULz63eXH1/3otsU4bgWnsjKGDD8zLVw==",
|
"integrity": "sha512-qiE99PB96iEYeygRQTaB1CnJR+1AAAQ/qMmXBKVsbIroAQPveRVXptJIEcPGu6t8AdshibcaLkmLvcEHjMbN0A==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ig-object": "^5.4.12",
|
"ig-object": "^5.4.12",
|
||||||
"object-run": "^1.0.1"
|
"object-run": "^1.0.1"
|
||||||
|
|||||||
@ -32,7 +32,7 @@
|
|||||||
"ig-argv": "^2.15.0",
|
"ig-argv": "^2.15.0",
|
||||||
"ig-features": "^3.4.2",
|
"ig-features": "^3.4.2",
|
||||||
"ig-object": "^5.4.12",
|
"ig-object": "^5.4.12",
|
||||||
"ig-types": "^5.0.29",
|
"ig-types": "^5.0.30",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"object-run": "^1.0.1",
|
"object-run": "^1.0.1",
|
||||||
"requirejs": "^2.3.6",
|
"requirejs": "^2.3.6",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user