refactored out args2array(..) and its derivatives...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2018-11-12 23:04:00 +03:00
parent fe389e6465
commit 299732762f
19 changed files with 47 additions and 62 deletions

View File

@ -52,7 +52,7 @@ module.Alias = core.ImageGridFeatures.Feature({
// other than the ones created by .alias(..). // other than the ones created by .alias(..).
['alias', ['alias',
function(_, alias, target){ function(_, alias, target){
var args = [].slice.call(arguments, 1) var args = [...arguments].slice(1)
var alias = args.shift() var alias = args.shift()
var target = args[args.length-1] var target = args[args.length-1]

View File

@ -1899,7 +1899,7 @@ module.CropActions = actions.Actions({
var current = this.current var current = this.current
var focus = false var focus = false
gids = arguments.length > 1 ? [].slice.call(arguments) : gids gids = arguments.length > 1 ? [...arguments] : gids
gids = gids || 'current' gids = gids || 'current'
gids = gids instanceof Array ? gids : [gids] gids = gids instanceof Array ? gids : [gids]

View File

@ -131,7 +131,7 @@ module.CLI = core.ImageGridFeatures.Feature({
push: function(){ push: function(){
var o = Object.create(this) var o = Object.create(this)
o.root = false o.root = false
o.__prefix = (this.__prefix || []).concat([].slice.call(arguments)) o.__prefix = (this.__prefix || []).concat([...arguments])
return o return o
}, },
pop: function(){ pop: function(){
@ -139,7 +139,7 @@ module.CLI = core.ImageGridFeatures.Feature({
}, },
emit: function(){ emit: function(){
console.log.apply(console, console.log.apply(console,
(this.__prefix || []).concat([].slice.call(arguments))) (this.__prefix || []).concat([...arguments]))
}, },
} }
}) })

View File

@ -1405,7 +1405,7 @@ module.Collection = core.ImageGridFeatures.Feature({
], ],
function(){ function(){
var that = this var that = this
var args = [].slice.call(arguments) var args = [...arguments]
var title = (args.length == 1 ? args[0] : args[1]) || this.collection var title = (args.length == 1 ? args[0] : args[1]) || this.collection
var collection = (this.collections || {})[title] || {} var collection = (this.collections || {})[title] || {}
@ -1435,7 +1435,7 @@ module.Collection = core.ImageGridFeatures.Feature({
}], }],
['joinCollect', ['joinCollect',
function(_, align, collection, data){ function(_, align, collection, data){
var args = [].slice.call(arguments) var args = [...arguments]
var title = (args.length == 1 ? args[0] : args[1]) || this.collection var title = (args.length == 1 ? args[0] : args[1]) || this.collection
var collection = (this.collections || {})[title] || {} var collection = (this.collections || {})[title] || {}
@ -2247,7 +2247,7 @@ var AutoCollectionsActions = actions.Actions({
NOTE: at least one tag must be supplied... NOTE: at least one tag must be supplied...
`, `,
function(title, tags){ function(title, tags){
tags = arguments.length > 2 ? [].slice.call(arguments, 1) : tags tags = arguments.length > 2 ? [...arguments].slice(1) : tags
tags = tags instanceof Array ? tags : [tags] tags = tags instanceof Array ? tags : [tags]
if(tags.length == 0){ if(tags.length == 0){
@ -2323,7 +2323,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
// passed to func with an appended title... // passed to func with an appended title...
var mixedModeCollectionAction = function(func, n, last_used_collection){ var mixedModeCollectionAction = function(func, n, last_used_collection){
return widgets.uiDialog(function(){ return widgets.uiDialog(function(){
var args = [].slice.call(arguments) var args = [...arguments]
// check if minimum number of arguments is reached... // check if minimum number of arguments is reached...
return args.length < (n || 1) ? return args.length < (n || 1) ?
// show the dialog... // show the dialog...
@ -2338,7 +2338,7 @@ var mixedModeCollectionAction = function(func, n, last_used_collection){
// are given... // are given...
var collectionGetterWrapper = function(func, n, last_used_collection){ var collectionGetterWrapper = function(func, n, last_used_collection){
return widgets.uiDialog(function(){ return widgets.uiDialog(function(){
var args = [].slice.call(arguments) var args = [...arguments]
// check if minimum number of arguments is reached... // check if minimum number of arguments is reached...
return args.length < (n || 1) return args.length < (n || 1)
// show the dialog... // show the dialog...

View File

@ -1414,7 +1414,7 @@ var JournalActions = actions.Actions({
var handler = function(action){ var handler = function(action){
return function(){ return function(){
var cur = this.current var cur = this.current
var args = util.args2array(arguments) var args = [...arguments]
var data = { var data = {
type: 'basic', type: 'basic',
@ -1696,7 +1696,7 @@ var ChangesActions = actions.Actions({
var that = this var that = this
var args = section instanceof Array ? var args = section instanceof Array ?
section section
: util.args2array(arguments) : [...arguments]
//var changes = this.changes = //var changes = this.changes =
var changes = var changes =
this.hasOwnProperty('changes') ? this.hasOwnProperty('changes') ?

View File

@ -36,9 +36,9 @@ var ExampleActions = actions.Actions({
// i.e. once defined it can't be overwritten... // i.e. once defined it can't be overwritten...
exampleAction: ['Test/Action', exampleAction: ['Test/Action',
function(){ function(){
console.log('>>>', [].slice.call(arguments)) console.log('>>>', [...arguments])
return function(){ return function(){
console.log('<<<', [].slice.call(arguments)) }}], console.log('<<<', [...arguments]) }}],
exampleActionFull: ['- Test/', exampleActionFull: ['- Test/',
core.doc`Example full action long documentation string core.doc`Example full action long documentation string
`, `,
@ -64,7 +64,7 @@ var ExampleActions = actions.Actions({
// a normal method... // a normal method...
exampleMethod: function(){ exampleMethod: function(){
console.log('example method:', [].slice.call(arguments)) console.log('example method:', [...arguments])
return 'example result' return 'example result'
}, },
@ -306,7 +306,7 @@ var ExampleUIActions = actions.Actions({
exampleActionDisabled: ['Test/$Disabled example action', exampleActionDisabled: ['Test/$Disabled example action',
{browseMode: function(){ return 'disabled' }}, {browseMode: function(){ return 'disabled' }},
function(){ function(){
console.log('Disabled action called:', [].slice.call(arguments)) }], console.log('Disabled action called:', [...arguments]) }],
// Usage Examples: // Usage Examples:
// .exampleDrawer() - show html in base drawer... // .exampleDrawer() - show html in base drawer...
@ -340,7 +340,7 @@ var ExampleUIActions = actions.Actions({
widgets.makeUIDialog(function(){ widgets.makeUIDialog(function(){
var actions = this var actions = this
console.log('>>> args:', [].slice.call(arguments)) console.log('>>> args:', [...arguments])
return browse.makeLister(null, function(path, make){ return browse.makeLister(null, function(path, make){
var that = this var that = this
@ -391,7 +391,7 @@ var ExampleUIActions = actions.Actions({
widgets.makeUIDialog(function(){ widgets.makeUIDialog(function(){
var actions = this var actions = this
console.log('>>> args:', [].slice.call(arguments)) console.log('>>> args:', [...arguments])
return browse.makeLister(null, function(path, make){ return browse.makeLister(null, function(path, make){
var that = this var that = this

View File

@ -260,7 +260,7 @@ var LocationActions = actions.Actions({
XXX introspection... XXX introspection...
`, `,
function(spec){ function(spec){
var args = [].slice.call(arguments, 1) var args = [...arguments].slice(1)
spec = spec instanceof Array ? spec : spec.split(':') spec = spec instanceof Array ? spec : spec.split(':')
var cache = this.protocols var cache = this.protocols

View File

@ -135,7 +135,7 @@ function(protocol, func){
return function(id){ return function(id){
return id.startsWith(protocol + ':') return id.startsWith(protocol + ':')
&& function(res){ && function(res){
res.set(func.apply(this, [].slice.call(arguments, 1))) }}} res.set(func.apply(this, [...arguments].slice(1))) }}}
@ -228,7 +228,7 @@ var PeerActions = actions.Actions({
// is no need to reload it... // is no need to reload it...
peerCall: ['- System/Peer/', peerCall: ['- System/Peer/',
function(id, action){ function(id, action){
var args = [].slice.call(arguments, 2) var args = [...arguments].slice(2)
return this.peerApply(id, action, args) return this.peerApply(id, action, args)
}], }],
peerApply: ['- System/Peer/', peerApply: ['- System/Peer/',

View File

@ -857,7 +857,7 @@ var StatusLogActions = actions.Actions({
}], }],
statusMessage: ['- Interface/', statusMessage: ['- Interface/',
function(){ function(){
var msg = args2array(arguments) var msg = [...arguments]
if(msg.len == 0){ if(msg.len == 0){
return return
} }

View File

@ -432,7 +432,7 @@ module.uiDialog = function(func){
// extended/overloaded... // extended/overloaded...
var makeUIDialog = var makeUIDialog =
module.makeUIDialog = function(a, b){ module.makeUIDialog = function(a, b){
var args = [].slice.call(arguments) var args = [...arguments]
// container name (optional)... // container name (optional)...
var dfl = typeof(args[0]) == typeof('str') ? var dfl = typeof(args[0]) == typeof('str') ?
@ -444,7 +444,7 @@ module.makeUIDialog = function(a, b){
var cargs = args var cargs = args
return uiDialog(function(){ return uiDialog(function(){
var args = [].slice.call(arguments) var args = [...arguments]
// see if the first arg is a container spec... // see if the first arg is a container spec...
var container = !(args[0] instanceof Array) && this.isUIContainer(args[0]) ? var container = !(args[0] instanceof Array) && this.isUIContainer(args[0]) ?

View File

@ -249,7 +249,7 @@ var DataPrototype = {
return this.getImages(gids) return this.getImages(gids)
} }
gids = arguments.length > 1 ? [].slice.call(arguments) : gids gids = arguments.length > 1 ? [...arguments] : gids
gids = gids instanceof Array ? gids : [gids] gids = gids instanceof Array ? gids : [gids]
return gids return gids
@ -1267,7 +1267,7 @@ var DataPrototype = {
// list of image gids... // list of image gids...
getImagePositions: function(gids){ getImagePositions: function(gids){
gids = arguments.length > 1 ? gids = arguments.length > 1 ?
[].slice.call(arguments) [...arguments]
: (gids || this.current) : (gids || this.current)
gids = (gids instanceof Array ? gids.slice() : [gids]) gids = (gids instanceof Array ? gids.slice() : [gids])
// sort ribbon gids to .ribbon_order // sort ribbon gids to .ribbon_order
@ -2344,7 +2344,7 @@ var DataPrototype = {
// .getImage(..) // .getImage(..)
// NOTE: if no target is given this will assume the current image. // NOTE: if no target is given this will assume the current image.
split: function(target){ split: function(target){
target = arguments.length > 1 ? [].slice.call(arguments) target = arguments.length > 1 ? [...arguments]
: target == null || target instanceof Array ? target : target == null || target instanceof Array ? target
: [target] : [target]
@ -3183,7 +3183,7 @@ var DataWithTagsPrototype = {
hasTag: function(gid, tag){ hasTag: function(gid, tag){
return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 }, return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 },
getTags: function(gids){ getTags: function(gids){
gids = arguments.length > 1 ? [].slice.call(arguments) gids = arguments.length > 1 ? [...arguments]
: gids == null || gids == 'current' ? this.getImage() : gids == null || gids == 'current' ? this.getImage()
: gids : gids
gids = gids == null ? [] : gids gids = gids == null ? [] : gids
@ -3212,7 +3212,7 @@ var DataWithTagsPrototype = {
// NOTE: if raw is set to true then this will return all the tagged // NOTE: if raw is set to true then this will return all the tagged
// gids even if they are not loaded in ribbons (i.e. cropped out)... // gids even if they are not loaded in ribbons (i.e. cropped out)...
getTaggedByAny: function(tags, raw){ getTaggedByAny: function(tags, raw){
tags = arguments.length > 1 ? [].slice.call(arguments) : tags tags = arguments.length > 1 ? [...arguments] : tags
tags = tags instanceof Array ? tags : [tags] tags = tags instanceof Array ? tags : [tags]
var res = [] var res = []
@ -3234,7 +3234,7 @@ var DataWithTagsPrototype = {
: this.getImages(res.compact()) : this.getImages(res.compact())
}, },
getTaggedByAll: function(tags, raw){ getTaggedByAll: function(tags, raw){
tags = arguments.length > 1 ? [].slice.call(arguments) : tags tags = arguments.length > 1 ? [...arguments] : tags
tags = tags instanceof Array ? tags : [tags] tags = tags instanceof Array ? tags : [tags]
if(this.tags == null){ if(this.tags == null){

View File

@ -158,9 +158,7 @@ module.denodeify =
function(func){ function(func){
var that = this var that = this
return function(){ return function(){
// XXX for some reason this does not see args2array... var args = [...arguments]
// XXX and for some reason the error is not reported...
var args = [].slice.call(arguments)
return new Promise(function(resolve, reject){ return new Promise(function(resolve, reject){
func.apply(that, args.concat([function(err, res){ func.apply(that, args.concat([function(err, res){
return err ? reject(err) : resolve(res) return err ? reject(err) : resolve(res)

View File

@ -307,13 +307,13 @@ var BaseRibbonsPrototype = {
// XXX do we need custom target support here??? // XXX do we need custom target support here???
noTransitions: function(func){ noTransitions: function(func){
this.preventTransitions() this.preventTransitions()
func.apply(this, args2array(arguments).slice(1)) func.apply(this, [...arguments].slice(1))
this.restoreTransitions(true) this.restoreTransitions(true)
return this return this
}, },
noTransitionsDeep: function(func){ noTransitionsDeep: function(func){
this.preventTransitions(null, true) this.preventTransitions(null, true)
func.apply(this, args2array(arguments).slice(1)) func.apply(this, [...arguments].slice(1))
this.restoreTransitions(true) this.restoreTransitions(true)
return this return this
}, },

View File

@ -846,7 +846,7 @@ function makeDeferredPool(size, paused){
var deferred = $.Deferred() var deferred = $.Deferred()
// add worker to queue... // add worker to queue...
this.queue.push([deferred, func, args2array(arguments).slice(1)]) this.queue.push([deferred, func, [...arguments].slice(1)])
// start work if we have not already... // start work if we have not already...
this._fill() this._fill()
@ -1029,13 +1029,6 @@ function sign(x){
} }
// convert JS arguments to Array...
function args2array(args){
//return Array.apply(null, args)
return [].slice.call(args)
}
var getAnimationFrame = (window.requestAnimationFrame var getAnimationFrame = (window.requestAnimationFrame
|| window.webkitRequestAnimationFrame || window.webkitRequestAnimationFrame
|| window.mozRequestAnimationFrame || window.mozRequestAnimationFrame

View File

@ -661,7 +661,7 @@ var KeyboardPrototype = {
var service_fields = this.service_fields var service_fields = this.service_fields
|| this.constructor.service_fields || this.constructor.service_fields
handler = arguments.length > 1 ? [].slice.call(arguments) handler = arguments.length > 1 ? [...arguments]
: handler == null ? '*' : handler == null ? '*'
: handler == '*' || handler == '?' || handler instanceof Function ? handler : handler == '*' || handler == '?' || handler instanceof Function ? handler
: handler instanceof Array ? handler : handler instanceof Array ? handler

View File

@ -158,8 +158,8 @@ var transformEditor = function(){
}, },
toString: function(){ toString: function(){
//return obj2transform(this.data, args2array(arguments)) //return obj2transform(this.data, [...arguments])
var args = args2array(arguments) var args = [...arguments]
return obj2transform(this.simplify(args), args) return obj2transform(this.simplify(args), args)
}, },
// NOTE: this will not build the alias data... // NOTE: this will not build the alias data...
@ -197,7 +197,7 @@ var transformEditor = function(){
var that = this var that = this
var attrs = arguments[0] instanceof Array ? var attrs = arguments[0] instanceof Array ?
arguments[0] arguments[0]
: args2array(arguments) : [...arguments]
var res = {} var res = {}
attrs.forEach(function(a){ attrs.forEach(function(a){
@ -373,7 +373,7 @@ var transformEditor = function(){
// i.e. this will iterate the arguments (width) while // i.e. this will iterate the arguments (width) while
// the handler(..) will iterate the aliases... // the handler(..) will iterate the aliases...
function(){ function(){
var args = args2array(arguments) var args = [...arguments]
// XXX do a full search through the alias values and merge results... // XXX do a full search through the alias values and merge results...
if(args.length == 0 && k in this.__direct){ if(args.length == 0 && k in this.__direct){
return this.__direct[k].call(this) return this.__direct[k].call(this)
@ -388,7 +388,7 @@ var transformEditor = function(){
return b return b
} }
: function(){ : function(){
var args = args2array(arguments) var args = [...arguments]
return func.call(this, k, args) return func.call(this, k, args)
} }
@ -461,7 +461,7 @@ var transformEditor = function(){
Object.keys(editor.__direct).forEach(function(k){ Object.keys(editor.__direct).forEach(function(k){
if(!(k in editor)){ if(!(k in editor)){
editor[k] = function(){ editor[k] = function(){
var args = args2array(arguments) var args = [...arguments]
editor.__direct[k].apply(this, args.length > 0 ? [args]: []) editor.__direct[k].apply(this, args.length > 0 ? [args]: [])
return editor.__direct[k].call(this) return editor.__direct[k].call(this)
} }
@ -485,7 +485,7 @@ jQuery.fn.transform = function(){
var e = $(this) var e = $(this)
var elem = e[0] var elem = e[0]
var args = args2array(arguments) var args = [...arguments]
// normalize... // normalize...
args = args.length == 0 args = args.length == 0
|| typeof(args[0]) == typeof('str') ? args || typeof(args[0]) == typeof('str') ? args
@ -532,7 +532,7 @@ jQuery.fn.transform = function(){
// shorthands... // shorthands...
jQuery.fn.scale = function(value){ jQuery.fn.scale = function(value){
if(arguments.length > 0){ if(arguments.length > 0){
return $(this).transform({scale: args2array(arguments)}) return $(this).transform({scale: [...arguments]})
} else { } else {
return $(this).transform('scale') return $(this).transform('scale')
@ -540,7 +540,7 @@ jQuery.fn.scale = function(value){
} }
jQuery.fn.rotate = function(value){ jQuery.fn.rotate = function(value){
if(arguments.length > 0){ if(arguments.length > 0){
return $(this).transform({rotate: args2array(arguments)}) return $(this).transform({rotate: [...arguments]})
} else { } else {
return $(this).transform('rotate') return $(this).transform('rotate')

View File

@ -173,12 +173,6 @@ Array.prototype.setCmp = function(other){
.sort()) } .sort()) }
var args2array =
module.args2array =
Array.fromArgs =
function(args){ return [].slice.call(args) }
Array.prototype.sortAs = function(other){ Array.prototype.sortAs = function(other){
return this.sort(function(a, b){ return this.sort(function(a, b){
var i = other.indexOf(a) var i = other.indexOf(a)

View File

@ -1871,7 +1871,7 @@ var BrowserPrototype = {
// NOTE: this will propagate up to the dialog... // NOTE: this will propagate up to the dialog...
if(elem.length > 0){ if(elem.length > 0){
var args = [].slice.call(arguments).slice(1) var args = [...arguments].slice(1)
elem.trigger({ elem.trigger({
type: arguments[0], type: arguments[0],
source: this, source: this,
@ -2579,7 +2579,7 @@ var BrowserPrototype = {
if(item_shortcut_marker){ if(item_shortcut_marker){
var _replace = function(){ var _replace = function(){
// get the last group... // get the last group...
var key = [].slice.call(arguments).slice(-3)[0] var key = [...arguments].slice(-3)[0]
!item_shortcuts[keyboard.normalizeKey(key)] !item_shortcuts[keyboard.normalizeKey(key)]
// NOTE: this is a side-effect... // NOTE: this is a side-effect...
&& that.keyboard.handler( && that.keyboard.handler(

View File

@ -44,13 +44,13 @@ function(name, defaults){
return function(){ return function(){
// register... // register...
if(arguments[0] instanceof Function){ if(arguments[0] instanceof Function){
this.dom.trigger(name, [].slice.call(arguments)) this.dom.trigger(name, [...arguments])
// trigger... // trigger...
} else { } else {
var args = (arguments.length == 0 && defaults) ? var args = (arguments.length == 0 && defaults) ?
defaults.call(this) defaults.call(this)
: [].slice.call(arguments) : [...arguments]
args = args instanceof Array ? args : [args] args = args instanceof Array ? args : [args]
this.dom.trigger(name, args) this.dom.trigger(name, args)