updated core.js' style...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-02-14 17:00:10 +03:00
parent a9f6e8f9a5
commit 8f39d3bbc3

View File

@ -107,9 +107,7 @@ module.ImageGridMetaActions = {
&& (args[0] == '?' || args[0] == '??')){ && (args[0] == '?' || args[0] == '??')){
return { return {
result: handlers.slice(-1)[0].pre.apply(this, args), result: handlers.slice(-1)[0].pre.apply(this, args),
} } } }),
}
}),
} }
var ImageGrid = var ImageGrid =
@ -196,7 +194,6 @@ if(typeof(window) != 'undefined'){
var makeConfigToggler = var makeConfigToggler =
module.makeConfigToggler = module.makeConfigToggler =
function(attr, states, a, b){ function(attr, states, a, b){
states = states || [false, true] states = states || [false, true]
var pre = a var pre = a
// XXX is this a good default??? // XXX is this a good default???
@ -223,11 +220,8 @@ function(attr, states, a, b){
} else { } else {
cfg[a[a.length-1]] = action cfg[a[a.length-1]] = action
this.config[a[0]] = this.config[a[0]] this.config[a[0]] = this.config[a[0]] } },
} states, pre, post) }
},
states, pre, post)
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -371,8 +365,7 @@ var IntrospectionActions = actions.Actions({
// check for loops... // check for loops...
if(m && visited[m] != null){ if(m && visited[m] != null){
m = null m = null
break break }
}
visited.push(m) visited.push(m)
} while(typeof(m) == typeof('str')) } while(typeof(m) == typeof('str'))
@ -761,8 +754,7 @@ var LifeCycleActions = actions.Actions({
DEBUG || nw.App.quit() DEBUG || nw.App.quit()
//this.close(true) //this.close(true)
} } }
}
nw.Window.get().on('close', this.__nw_stop_handler) nw.Window.get().on('close', this.__nw_stop_handler)
@ -798,12 +790,12 @@ var LifeCycleActions = actions.Actions({
this.config['declare-ready-timeout'] > 0 this.config['declare-ready-timeout'] > 0
&& !this.__ready_announce_timeout && !this.__ready_announce_timeout
&& (this.__ready_announce_timeout = && (this.__ready_announce_timeout =
setTimeout(function(){ setTimeout(
function(){
// cleanup... // cleanup...
delete this.__ready_announce_timeout delete this.__ready_announce_timeout
if((this.__ready_announce_requests || new Set()).size == 0){ if((this.__ready_announce_requests || new Set()).size == 0){
delete this.__ready_announce_requests delete this.__ready_announce_requests }
}
// force start... // force start...
if(!this.isReady()){ if(!this.isReady()){
// report... // report...
@ -819,9 +811,8 @@ var LifeCycleActions = actions.Actions({
// cleanup... // cleanup...
delete this.__ready_announce_requested delete this.__ready_announce_requested
delete this.__ready_announce_requests delete this.__ready_announce_requests } }.bind(this),
} this.config['declare-ready-timeout']))
}.bind(this), this.config['declare-ready-timeout']))
// trigger the started event... // trigger the started event...
this.started() }], this.started() }],
@ -913,8 +904,8 @@ var LifeCycleActions = actions.Actions({
this.__ready_announce_requests || new Set()) this.__ready_announce_requests || new Set())
&& this.__ready_announce_requests.add(message) && this.__ready_announce_requests.add(message)
return (this.__ready_announce_requested = (this.__ready_announce_requested || 0) + 1) return (this.__ready_announce_requested =
}], (this.__ready_announce_requested || 0) + 1) }],
// XXX revise args... // XXX revise args...
// XXX should this be here??? // XXX should this be here???
@ -1585,16 +1576,16 @@ var TimersActions = actions.Actions({
// run... // run...
func instanceof Function ? func instanceof Function ?
func.call(this) func.call(this)
: this.call(func) : this.call(func) }.bind(this),
}.bind(this), ms || 0) }],
ms || 0)
}],
clearTimeout: ['- System/', clearTimeout: ['- System/',
function(id){ function(id){
var timeouts = this.__timeouts = this.__timeouts || {} var timeouts =
this.__timeouts =
this.__timeouts
|| {}
clearTimeout(timeouts[id]) clearTimeout(timeouts[id])
delete timeouts[id] delete timeouts[id] }],
}],
setInterval: ['- System/', setInterval: ['- System/',
function(id, func, ms){ function(id, func, ms){
@ -1606,14 +1597,12 @@ var TimersActions = actions.Actions({
intervals[id] = setInterval( intervals[id] = setInterval(
(func instanceof Function ? func : function(){ this.call(func) }) (func instanceof Function ? func : function(){ this.call(func) })
.bind(this), .bind(this),
ms || 0) ms || 0) }],
}],
clearInterval: ['- System/', clearInterval: ['- System/',
function(id){ function(id){
var intervals = this.__intervals = this.__intervals || {} var intervals = this.__intervals = this.__intervals || {}
clearInterval(intervals[id]) clearInterval(intervals[id])
delete intervals[id] delete intervals[id] }],
}],
setPersistentInterval: ['- System/', setPersistentInterval: ['- System/',
doc` doc`
@ -1639,12 +1628,10 @@ var TimersActions = actions.Actions({
// checks... // checks...
if(!ms || !action){ if(!ms || !action){
console.error('Persistent interval: both action and ms must be set.') console.error('Persistent interval: both action and ms must be set.')
return return }
}
if(typeof(action) != typeof('str')){ if(typeof(action) != typeof('str')){
console.error('Persistent interval: handler must be a string.') console.error('Persistent interval: handler must be a string.')
return return }
}
id in intervals id in intervals
&& clearInterval(intervals[id]) && clearInterval(intervals[id])
@ -1656,9 +1643,9 @@ var TimersActions = actions.Actions({
} }
intervals[id] = setInterval( intervals[id] = setInterval(
function(){ this.call(action) }.bind(this), function(){
ms || 0) this.call(action) }.bind(this),
}], ms || 0) }],
clearPersistentInterval: ['- System/', clearPersistentInterval: ['- System/',
function(id, stop_only){ function(id, stop_only){
var intervals = var intervals =
@ -1667,9 +1654,7 @@ var TimersActions = actions.Actions({
clearInterval(intervals[id]) clearInterval(intervals[id])
delete intervals[id] delete intervals[id]
if(!stop_only){ if(!stop_only){
delete this.config['persistent-intervals'][id] delete this.config['persistent-intervals'][id] } }],
}
}],
// XXX revise name (???) // XXX revise name (???)
// XXX do we need actions other than start/stop ??? // XXX do we need actions other than start/stop ???
persistentIntervals: ['- System/', persistentIntervals: ['- System/',
@ -1696,8 +1681,7 @@ var TimersActions = actions.Actions({
ids.forEach(function(id){ ids.forEach(function(id){
this.clearPersistentInterval(id, true) }.bind(this)) this.clearPersistentInterval(id, true) }.bind(this))
// unknown action... // unknown action...
: console.error('persistentIntervals: unknown action:', action) : console.error('persistentIntervals: unknown action:', action) }],
}],
// Events... // Events...
// //
@ -1815,13 +1799,12 @@ var TimersActions = actions.Actions({
var tag = (args[0] instanceof Function var tag = (args[0] instanceof Function
|| this[args[0]] instanceof Function) ? || this[args[0]] instanceof Function) ?
args[0] args[0]
: args.shift() : args.shift() }
}
// sanity check: when debouncing a function a tag is required... // sanity check: when debouncing a function a tag is required...
if(tag instanceof Function){ if(tag instanceof Function){
throw new TypeError('debounce: when passing a function a tag is required.') throw new TypeError(
} 'debounce: when passing a function a tag is required.') }
var action = args.shift() var action = args.shift()
var attr = '__debounce_'+ tag var attr = '__debounce_'+ tag
@ -1841,15 +1824,12 @@ var TimersActions = actions.Actions({
// on the keyboard and triggering key repeat... // on the keyboard and triggering key repeat...
&& retriggered < (options.timeout || 200) / 200){ && retriggered < (options.timeout || 200) / 200){
var func = this[attr] = this[attr] || debounce(options, action) var func = this[attr] = this[attr] || debounce(options, action)
func.call(this, ...args) func.call(this, ...args) } },
}
},
}) })
var func = this[attr] = this[attr] || debounce(options, action) var func = this[attr] = this[attr] || debounce(options, action)
return func.call(this, ...args) return func.call(this, ...args) }],
}],
}) })
var Timers = var Timers =
@ -1876,8 +1856,7 @@ module.Timers = ImageGridFeatures.Feature({
Object.keys(this.__timeouts || {}) Object.keys(this.__timeouts || {})
.forEach(function(id){ this.clearTimeout(id) }.bind(this)) .forEach(function(id){ this.clearTimeout(id) }.bind(this))
this.persistentIntervals('stop') this.persistentIntervals('stop') }],
}],
// fixed timer actions... // fixed timer actions...
// XXX not sure about these... // XXX not sure about these...
@ -1890,8 +1869,7 @@ module.Timers = ImageGridFeatures.Feature({
.setInterval('every5Minutes', 'every5Minutes', m*5) .setInterval('every5Minutes', 'every5Minutes', m*5)
.setInterval('every10Minutes', 'every10Minutes', m*10) .setInterval('every10Minutes', 'every10Minutes', m*10)
.setInterval('every30Minutes', 'every30Minutes', m*30) .setInterval('every30Minutes', 'every30Minutes', m*30)
.setInterval('everyHour', 'everyHour', m*60) .setInterval('everyHour', 'everyHour', m*60) }],
}],
], ],
}) })
@ -2447,9 +2425,7 @@ module.makeWorkspaceConfigWriter = function(keys, callback){
workspace[key] = JSON.parse(JSON.stringify(that.config[key])) workspace[key] = JSON.parse(JSON.stringify(that.config[key]))
}) })
callback && callback.call(this, workspace) callback && callback.call(this, workspace) } }
}
}
// XXX should this delete a prop if it's not in the loading workspace??? // XXX should this delete a prop if it's not in the loading workspace???
// XXX only replace a prop if it has changed??? // XXX only replace a prop if it has changed???
@ -2470,14 +2446,10 @@ module.makeWorkspaceConfigLoader = function(keys, callback){
// no key set... // no key set...
// XXX is this the right way to go??? // XXX is this the right way to go???
} else { } else {
delete that.config[key] delete that.config[key] } })
}
})
callback callback
&& callback.call(this, workspace) && callback.call(this, workspace) } }
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2514,17 +2486,15 @@ var WorkspaceActions = actions.Actions({
saveWorkspace: ['Workspace/Save Workspace', saveWorkspace: ['Workspace/Save Workspace',
function(name){ function(name){
if(!this.config.hasOwnProperty('workspaces')){ if(!this.config.hasOwnProperty('workspaces')){
this.config['workspaces'] = JSON.parse(JSON.stringify(this.config['workspaces'])) this.config['workspaces'] =
} JSON.parse(JSON.stringify(this.config['workspaces'])) }
var res = {} var res = {}
if(name !== null){ if(name !== null){
this.config['workspaces'][name || this.config.workspace] = res this.config['workspaces'][name || this.config.workspace] = res }
}
return res return res }],
}],
// NOTE: merging the state data is the responsibility of the feature // NOTE: merging the state data is the responsibility of the feature
// ...this is done so as not to restrict the feature to one // ...this is done so as not to restrict the feature to one
// specific way to do stuff... // specific way to do stuff...
@ -2540,9 +2510,7 @@ var WorkspaceActions = actions.Actions({
// we got the workspace object... // we got the workspace object...
} else { } else {
return name return name } }],
}
}],
// NOTE: this will not save the current workspace... // NOTE: this will not save the current workspace...
toggleWorkspace: ['Workspace/workspace', toggleWorkspace: ['Workspace/workspace',
@ -2559,23 +2527,19 @@ var WorkspaceActions = actions.Actions({
this.saveWorkspace() this.saveWorkspace()
if(stack.slice(-1)[0] == name){ if(stack.slice(-1)[0] == name){
return return }
}
this.workspace != name && this.loadWorkspace(name) this.workspace != name && this.loadWorkspace(name)
stack.push(name) stack.push(name) }],
}],
popWorkspace: ['- Workspace/', popWorkspace: ['- Workspace/',
function(){ function(){
var stack = this.__workspace_stack var stack = this.__workspace_stack
if(!stack || stack.length == 0){ if(!stack || stack.length == 0){
return return }
}
this.saveWorkspace() this.saveWorkspace()
this.loadWorkspace(stack.pop()) this.loadWorkspace(stack.pop()) }],
}],
}) })