From 299732762fd4b7ac2a2bf1586eaef3395cd50e1c Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 12 Nov 2018 23:04:00 +0300 Subject: [PATCH] refactored out args2array(..) and its derivatives... Signed-off-by: Alex A. Naanou --- ui (gen4)/features/alias.js | 2 +- ui (gen4)/features/base.js | 2 +- ui (gen4)/features/cli.js | 4 ++-- ui (gen4)/features/collections.js | 10 +++++----- ui (gen4)/features/core.js | 4 ++-- ui (gen4)/features/examples.js | 12 ++++++------ ui (gen4)/features/location.js | 2 +- ui (gen4)/features/peer.js | 4 ++-- ui (gen4)/features/ui-status.js | 2 +- ui (gen4)/features/ui-widgets.js | 4 ++-- ui (gen4)/imagegrid/data.js | 12 ++++++------ ui (gen4)/imagegrid/file.js | 4 +--- ui (gen4)/imagegrid/ribbons.js | 4 ++-- ui (gen4)/lib/jli.js | 9 +-------- ui (gen4)/lib/keyboard.js | 2 +- ui (gen4)/lib/transform.js | 18 +++++++++--------- ui (gen4)/lib/util.js | 6 ------ ui (gen4)/lib/widget/browse.js | 4 ++-- ui (gen4)/lib/widget/widget.js | 4 ++-- 19 files changed, 47 insertions(+), 62 deletions(-) diff --git a/ui (gen4)/features/alias.js b/ui (gen4)/features/alias.js index 64ca5cef..5a385c8b 100755 --- a/ui (gen4)/features/alias.js +++ b/ui (gen4)/features/alias.js @@ -52,7 +52,7 @@ module.Alias = core.ImageGridFeatures.Feature({ // other than the ones created by .alias(..). ['alias', function(_, alias, target){ - var args = [].slice.call(arguments, 1) + var args = [...arguments].slice(1) var alias = args.shift() var target = args[args.length-1] diff --git a/ui (gen4)/features/base.js b/ui (gen4)/features/base.js index 8b70b391..f46b66a4 100755 --- a/ui (gen4)/features/base.js +++ b/ui (gen4)/features/base.js @@ -1899,7 +1899,7 @@ module.CropActions = actions.Actions({ var current = this.current var focus = false - gids = arguments.length > 1 ? [].slice.call(arguments) : gids + gids = arguments.length > 1 ? [...arguments] : gids gids = gids || 'current' gids = gids instanceof Array ? gids : [gids] diff --git a/ui (gen4)/features/cli.js b/ui (gen4)/features/cli.js index a05f6681..2b21efd6 100755 --- a/ui (gen4)/features/cli.js +++ b/ui (gen4)/features/cli.js @@ -131,7 +131,7 @@ module.CLI = core.ImageGridFeatures.Feature({ push: function(){ var o = Object.create(this) o.root = false - o.__prefix = (this.__prefix || []).concat([].slice.call(arguments)) + o.__prefix = (this.__prefix || []).concat([...arguments]) return o }, pop: function(){ @@ -139,7 +139,7 @@ module.CLI = core.ImageGridFeatures.Feature({ }, emit: function(){ console.log.apply(console, - (this.__prefix || []).concat([].slice.call(arguments))) + (this.__prefix || []).concat([...arguments])) }, } }) diff --git a/ui (gen4)/features/collections.js b/ui (gen4)/features/collections.js index db1ee31f..b621476c 100755 --- a/ui (gen4)/features/collections.js +++ b/ui (gen4)/features/collections.js @@ -1405,7 +1405,7 @@ module.Collection = core.ImageGridFeatures.Feature({ ], function(){ var that = this - var args = [].slice.call(arguments) + var args = [...arguments] var title = (args.length == 1 ? args[0] : args[1]) || this.collection var collection = (this.collections || {})[title] || {} @@ -1435,7 +1435,7 @@ module.Collection = core.ImageGridFeatures.Feature({ }], ['joinCollect', function(_, align, collection, data){ - var args = [].slice.call(arguments) + var args = [...arguments] var title = (args.length == 1 ? args[0] : args[1]) || this.collection var collection = (this.collections || {})[title] || {} @@ -2247,7 +2247,7 @@ var AutoCollectionsActions = actions.Actions({ NOTE: at least one tag must be supplied... `, 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] if(tags.length == 0){ @@ -2323,7 +2323,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({ // passed to func with an appended title... var mixedModeCollectionAction = function(func, n, last_used_collection){ return widgets.uiDialog(function(){ - var args = [].slice.call(arguments) + var args = [...arguments] // check if minimum number of arguments is reached... return args.length < (n || 1) ? // show the dialog... @@ -2338,7 +2338,7 @@ var mixedModeCollectionAction = function(func, n, last_used_collection){ // are given... var collectionGetterWrapper = function(func, n, last_used_collection){ return widgets.uiDialog(function(){ - var args = [].slice.call(arguments) + var args = [...arguments] // check if minimum number of arguments is reached... return args.length < (n || 1) // show the dialog... diff --git a/ui (gen4)/features/core.js b/ui (gen4)/features/core.js index f4852287..4bc44197 100755 --- a/ui (gen4)/features/core.js +++ b/ui (gen4)/features/core.js @@ -1414,7 +1414,7 @@ var JournalActions = actions.Actions({ var handler = function(action){ return function(){ var cur = this.current - var args = util.args2array(arguments) + var args = [...arguments] var data = { type: 'basic', @@ -1696,7 +1696,7 @@ var ChangesActions = actions.Actions({ var that = this var args = section instanceof Array ? section - : util.args2array(arguments) + : [...arguments] //var changes = this.changes = var changes = this.hasOwnProperty('changes') ? diff --git a/ui (gen4)/features/examples.js b/ui (gen4)/features/examples.js index 840c8808..9c0c7605 100755 --- a/ui (gen4)/features/examples.js +++ b/ui (gen4)/features/examples.js @@ -36,9 +36,9 @@ var ExampleActions = actions.Actions({ // i.e. once defined it can't be overwritten... exampleAction: ['Test/Action', function(){ - console.log('>>>', [].slice.call(arguments)) + console.log('>>>', [...arguments]) return function(){ - console.log('<<<', [].slice.call(arguments)) }}], + console.log('<<<', [...arguments]) }}], exampleActionFull: ['- Test/', core.doc`Example full action long documentation string `, @@ -64,7 +64,7 @@ var ExampleActions = actions.Actions({ // a normal method... exampleMethod: function(){ - console.log('example method:', [].slice.call(arguments)) + console.log('example method:', [...arguments]) return 'example result' }, @@ -306,7 +306,7 @@ var ExampleUIActions = actions.Actions({ exampleActionDisabled: ['Test/$Disabled example action', {browseMode: function(){ return 'disabled' }}, function(){ - console.log('Disabled action called:', [].slice.call(arguments)) }], + console.log('Disabled action called:', [...arguments]) }], // Usage Examples: // .exampleDrawer() - show html in base drawer... @@ -340,7 +340,7 @@ var ExampleUIActions = actions.Actions({ widgets.makeUIDialog(function(){ var actions = this - console.log('>>> args:', [].slice.call(arguments)) + console.log('>>> args:', [...arguments]) return browse.makeLister(null, function(path, make){ var that = this @@ -391,7 +391,7 @@ var ExampleUIActions = actions.Actions({ widgets.makeUIDialog(function(){ var actions = this - console.log('>>> args:', [].slice.call(arguments)) + console.log('>>> args:', [...arguments]) return browse.makeLister(null, function(path, make){ var that = this diff --git a/ui (gen4)/features/location.js b/ui (gen4)/features/location.js index 30597acf..a6c9e3a1 100755 --- a/ui (gen4)/features/location.js +++ b/ui (gen4)/features/location.js @@ -260,7 +260,7 @@ var LocationActions = actions.Actions({ XXX introspection... `, function(spec){ - var args = [].slice.call(arguments, 1) + var args = [...arguments].slice(1) spec = spec instanceof Array ? spec : spec.split(':') var cache = this.protocols diff --git a/ui (gen4)/features/peer.js b/ui (gen4)/features/peer.js index 133f72de..718de547 100755 --- a/ui (gen4)/features/peer.js +++ b/ui (gen4)/features/peer.js @@ -135,7 +135,7 @@ function(protocol, func){ return function(id){ return id.startsWith(protocol + ':') && 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... peerCall: ['- System/Peer/', function(id, action){ - var args = [].slice.call(arguments, 2) + var args = [...arguments].slice(2) return this.peerApply(id, action, args) }], peerApply: ['- System/Peer/', diff --git a/ui (gen4)/features/ui-status.js b/ui (gen4)/features/ui-status.js index 066b0596..4fbbe764 100755 --- a/ui (gen4)/features/ui-status.js +++ b/ui (gen4)/features/ui-status.js @@ -857,7 +857,7 @@ var StatusLogActions = actions.Actions({ }], statusMessage: ['- Interface/', function(){ - var msg = args2array(arguments) + var msg = [...arguments] if(msg.len == 0){ return } diff --git a/ui (gen4)/features/ui-widgets.js b/ui (gen4)/features/ui-widgets.js index 2ba0f1fe..0d5f3c17 100755 --- a/ui (gen4)/features/ui-widgets.js +++ b/ui (gen4)/features/ui-widgets.js @@ -432,7 +432,7 @@ module.uiDialog = function(func){ // extended/overloaded... var makeUIDialog = module.makeUIDialog = function(a, b){ - var args = [].slice.call(arguments) + var args = [...arguments] // container name (optional)... var dfl = typeof(args[0]) == typeof('str') ? @@ -444,7 +444,7 @@ module.makeUIDialog = function(a, b){ var cargs = args return uiDialog(function(){ - var args = [].slice.call(arguments) + var args = [...arguments] // see if the first arg is a container spec... var container = !(args[0] instanceof Array) && this.isUIContainer(args[0]) ? diff --git a/ui (gen4)/imagegrid/data.js b/ui (gen4)/imagegrid/data.js index 018a29fd..39fdca52 100755 --- a/ui (gen4)/imagegrid/data.js +++ b/ui (gen4)/imagegrid/data.js @@ -249,7 +249,7 @@ var DataPrototype = { return this.getImages(gids) } - gids = arguments.length > 1 ? [].slice.call(arguments) : gids + gids = arguments.length > 1 ? [...arguments] : gids gids = gids instanceof Array ? gids : [gids] return gids @@ -1267,7 +1267,7 @@ var DataPrototype = { // list of image gids... getImagePositions: function(gids){ gids = arguments.length > 1 ? - [].slice.call(arguments) + [...arguments] : (gids || this.current) gids = (gids instanceof Array ? gids.slice() : [gids]) // sort ribbon gids to .ribbon_order @@ -2344,7 +2344,7 @@ var DataPrototype = { // .getImage(..) // NOTE: if no target is given this will assume the current image. split: function(target){ - target = arguments.length > 1 ? [].slice.call(arguments) + target = arguments.length > 1 ? [...arguments] : target == null || target instanceof Array ? target : [target] @@ -3183,7 +3183,7 @@ var DataWithTagsPrototype = { hasTag: function(gid, tag){ return ((this.tags || {})[tag] || []).indexOf(this.getImage(gid)) >= 0 }, getTags: function(gids){ - gids = arguments.length > 1 ? [].slice.call(arguments) + gids = arguments.length > 1 ? [...arguments] : gids == null || gids == 'current' ? this.getImage() : 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 // gids even if they are not loaded in ribbons (i.e. cropped out)... getTaggedByAny: function(tags, raw){ - tags = arguments.length > 1 ? [].slice.call(arguments) : tags + tags = arguments.length > 1 ? [...arguments] : tags tags = tags instanceof Array ? tags : [tags] var res = [] @@ -3234,7 +3234,7 @@ var DataWithTagsPrototype = { : this.getImages(res.compact()) }, getTaggedByAll: function(tags, raw){ - tags = arguments.length > 1 ? [].slice.call(arguments) : tags + tags = arguments.length > 1 ? [...arguments] : tags tags = tags instanceof Array ? tags : [tags] if(this.tags == null){ diff --git a/ui (gen4)/imagegrid/file.js b/ui (gen4)/imagegrid/file.js index f9474bb7..edcc5b77 100755 --- a/ui (gen4)/imagegrid/file.js +++ b/ui (gen4)/imagegrid/file.js @@ -158,9 +158,7 @@ module.denodeify = function(func){ var that = this return function(){ - // XXX for some reason this does not see args2array... - // XXX and for some reason the error is not reported... - var args = [].slice.call(arguments) + var args = [...arguments] return new Promise(function(resolve, reject){ func.apply(that, args.concat([function(err, res){ return err ? reject(err) : resolve(res) diff --git a/ui (gen4)/imagegrid/ribbons.js b/ui (gen4)/imagegrid/ribbons.js index 259d432a..61a149f6 100755 --- a/ui (gen4)/imagegrid/ribbons.js +++ b/ui (gen4)/imagegrid/ribbons.js @@ -307,13 +307,13 @@ var BaseRibbonsPrototype = { // XXX do we need custom target support here??? noTransitions: function(func){ this.preventTransitions() - func.apply(this, args2array(arguments).slice(1)) + func.apply(this, [...arguments].slice(1)) this.restoreTransitions(true) return this }, noTransitionsDeep: function(func){ this.preventTransitions(null, true) - func.apply(this, args2array(arguments).slice(1)) + func.apply(this, [...arguments].slice(1)) this.restoreTransitions(true) return this }, diff --git a/ui (gen4)/lib/jli.js b/ui (gen4)/lib/jli.js index c11e07e3..206388fb 100755 --- a/ui (gen4)/lib/jli.js +++ b/ui (gen4)/lib/jli.js @@ -846,7 +846,7 @@ function makeDeferredPool(size, paused){ var deferred = $.Deferred() // 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... 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 || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame diff --git a/ui (gen4)/lib/keyboard.js b/ui (gen4)/lib/keyboard.js index d4236eb4..dc49e3a8 100755 --- a/ui (gen4)/lib/keyboard.js +++ b/ui (gen4)/lib/keyboard.js @@ -661,7 +661,7 @@ var KeyboardPrototype = { var service_fields = this.service_fields || this.constructor.service_fields - handler = arguments.length > 1 ? [].slice.call(arguments) + handler = arguments.length > 1 ? [...arguments] : handler == null ? '*' : handler == '*' || handler == '?' || handler instanceof Function ? handler : handler instanceof Array ? handler diff --git a/ui (gen4)/lib/transform.js b/ui (gen4)/lib/transform.js index 6d40ac66..2b9c0108 100755 --- a/ui (gen4)/lib/transform.js +++ b/ui (gen4)/lib/transform.js @@ -158,8 +158,8 @@ var transformEditor = function(){ }, toString: function(){ - //return obj2transform(this.data, args2array(arguments)) - var args = args2array(arguments) + //return obj2transform(this.data, [...arguments]) + var args = [...arguments] return obj2transform(this.simplify(args), args) }, // NOTE: this will not build the alias data... @@ -197,7 +197,7 @@ var transformEditor = function(){ var that = this var attrs = arguments[0] instanceof Array ? arguments[0] - : args2array(arguments) + : [...arguments] var res = {} attrs.forEach(function(a){ @@ -373,7 +373,7 @@ var transformEditor = function(){ // i.e. this will iterate the arguments (width) while // the handler(..) will iterate the aliases... function(){ - var args = args2array(arguments) + var args = [...arguments] // XXX do a full search through the alias values and merge results... if(args.length == 0 && k in this.__direct){ return this.__direct[k].call(this) @@ -388,7 +388,7 @@ var transformEditor = function(){ return b } : function(){ - var args = args2array(arguments) + var args = [...arguments] return func.call(this, k, args) } @@ -461,7 +461,7 @@ var transformEditor = function(){ Object.keys(editor.__direct).forEach(function(k){ if(!(k in editor)){ editor[k] = function(){ - var args = args2array(arguments) + var args = [...arguments] editor.__direct[k].apply(this, args.length > 0 ? [args]: []) return editor.__direct[k].call(this) } @@ -485,7 +485,7 @@ jQuery.fn.transform = function(){ var e = $(this) var elem = e[0] - var args = args2array(arguments) + var args = [...arguments] // normalize... args = args.length == 0 || typeof(args[0]) == typeof('str') ? args @@ -532,7 +532,7 @@ jQuery.fn.transform = function(){ // shorthands... jQuery.fn.scale = function(value){ if(arguments.length > 0){ - return $(this).transform({scale: args2array(arguments)}) + return $(this).transform({scale: [...arguments]}) } else { return $(this).transform('scale') @@ -540,7 +540,7 @@ jQuery.fn.scale = function(value){ } jQuery.fn.rotate = function(value){ if(arguments.length > 0){ - return $(this).transform({rotate: args2array(arguments)}) + return $(this).transform({rotate: [...arguments]}) } else { return $(this).transform('rotate') diff --git a/ui (gen4)/lib/util.js b/ui (gen4)/lib/util.js index ba23e387..c6fc47dd 100755 --- a/ui (gen4)/lib/util.js +++ b/ui (gen4)/lib/util.js @@ -173,12 +173,6 @@ Array.prototype.setCmp = function(other){ .sort()) } -var args2array = -module.args2array = -Array.fromArgs = - function(args){ return [].slice.call(args) } - - Array.prototype.sortAs = function(other){ return this.sort(function(a, b){ var i = other.indexOf(a) diff --git a/ui (gen4)/lib/widget/browse.js b/ui (gen4)/lib/widget/browse.js index 5970d602..e0508a06 100755 --- a/ui (gen4)/lib/widget/browse.js +++ b/ui (gen4)/lib/widget/browse.js @@ -1871,7 +1871,7 @@ var BrowserPrototype = { // NOTE: this will propagate up to the dialog... if(elem.length > 0){ - var args = [].slice.call(arguments).slice(1) + var args = [...arguments].slice(1) elem.trigger({ type: arguments[0], source: this, @@ -2579,7 +2579,7 @@ var BrowserPrototype = { if(item_shortcut_marker){ var _replace = function(){ // get the last group... - var key = [].slice.call(arguments).slice(-3)[0] + var key = [...arguments].slice(-3)[0] !item_shortcuts[keyboard.normalizeKey(key)] // NOTE: this is a side-effect... && that.keyboard.handler( diff --git a/ui (gen4)/lib/widget/widget.js b/ui (gen4)/lib/widget/widget.js index 5e0c637a..05a2743d 100755 --- a/ui (gen4)/lib/widget/widget.js +++ b/ui (gen4)/lib/widget/widget.js @@ -44,13 +44,13 @@ function(name, defaults){ return function(){ // register... if(arguments[0] instanceof Function){ - this.dom.trigger(name, [].slice.call(arguments)) + this.dom.trigger(name, [...arguments]) // trigger... } else { var args = (arguments.length == 0 && defaults) ? defaults.call(this) - : [].slice.call(arguments) + : [...arguments] args = args instanceof Array ? args : [args] this.dom.trigger(name, args)