mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
added caching api to core...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
66aea36685
commit
9c9553bb16
@ -270,7 +270,9 @@ function(func){
|
||||
var IntrospectionActions = actions.Actions({
|
||||
// user-callable actions...
|
||||
get useractions(){
|
||||
return this.actions.filter(this.isUserCallable.bind(this)) },
|
||||
return this.cache('useractions', function(){
|
||||
return this.actions.filter(this.isUserCallable.bind(this)) }) },
|
||||
//return this.actions.filter(this.isUserCallable.bind(this)) },
|
||||
|
||||
// check if action is callable by user...
|
||||
isUserCallable: ['- System/',
|
||||
@ -294,6 +296,9 @@ module.Introspection = ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
|
||||
tag: 'introspection',
|
||||
depends: [
|
||||
'cache'
|
||||
],
|
||||
|
||||
actions: IntrospectionActions,
|
||||
})
|
||||
@ -551,6 +556,71 @@ module.Serialization = ImageGridFeatures.Feature({
|
||||
})
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// XXX should this be in actions.js???
|
||||
// XXX should we invalidate the cache automatically???
|
||||
var CacheActions = actions.Actions({
|
||||
config: {
|
||||
// Enable/disable caching...
|
||||
'cache': true,
|
||||
|
||||
// Control pre-caching...
|
||||
//
|
||||
// This can be:
|
||||
// true - pre-caching enabled
|
||||
// 0 - same as true
|
||||
// number - delay pre-caching by number milliseconds
|
||||
// false - pre-caching disabled
|
||||
'pre-cache': 200,
|
||||
},
|
||||
|
||||
// XXX should these be actions???
|
||||
cache: function(title, lister){
|
||||
if(!this.config.cache){
|
||||
return lister.call(this)
|
||||
}
|
||||
var cache = this.__cache = this.__cache || {}
|
||||
var l = cache[title] = cache[title] || lister.call(this)
|
||||
return l
|
||||
},
|
||||
// XXX is this too broad??
|
||||
preCache: function(){
|
||||
if(this.config.cache){
|
||||
for(k in this){ this[k] } } },
|
||||
clearCache: function(title){
|
||||
if(title){
|
||||
delete (this.__cache|| {})[title]
|
||||
|
||||
} else {
|
||||
delete this.__cache
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
var Cache =
|
||||
module.Cache = ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
doc: '',
|
||||
|
||||
tag: 'cache',
|
||||
|
||||
actions: CacheActions,
|
||||
|
||||
handlers: [
|
||||
['start',
|
||||
function(){
|
||||
var t = this.config['pre-cache']
|
||||
t == 0 || t === true ?
|
||||
this.preCache()
|
||||
: t > 0 ?
|
||||
setTimeout((function(){ this.preCache() }).bind(this), t)
|
||||
: false
|
||||
}],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
var UtilActions = actions.Actions({
|
||||
|
||||
@ -181,7 +181,9 @@ var PeerActions = actions.Actions({
|
||||
// XXX need more control...
|
||||
// - get proxies to specific peer...
|
||||
get peeractions(){
|
||||
return this.getPeerActions() },
|
||||
this.cache('peeractions', function(){
|
||||
return this.getPeerActions() }) },
|
||||
//return this.getPeerActions() },
|
||||
|
||||
getPeerActions: ['- System/Peer/',
|
||||
function(id){
|
||||
|
||||
@ -588,11 +588,17 @@ var DialogsActions = actions.Actions({
|
||||
|
||||
// introspection...
|
||||
get uiContainers(){
|
||||
return this.actions.filter(this.isUIContainer.bind(this)) },
|
||||
return this.cache('uiContainers', function(){
|
||||
return this.actions.filter(this.isUIContainer.bind(this)) }) },
|
||||
//return this.actions.filter(this.isUIContainer.bind(this)) },
|
||||
get uiDialogs(){
|
||||
return this.actions.filter(this.isUIDialog.bind(this)) },
|
||||
return this.cache('uiDialogs', function(){
|
||||
return this.actions.filter(this.isUIDialog.bind(this)) }) },
|
||||
//return this.actions.filter(this.isUIDialog.bind(this)) },
|
||||
get uiElements(){
|
||||
return this.actions.filter(this.isUIElement.bind(this)) },
|
||||
return this.cache('uiElements', function(){
|
||||
return this.actions.filter(this.isUIElement.bind(this)) }) },
|
||||
//return this.actions.filter(this.isUIElement.bind(this)) },
|
||||
|
||||
// XXX this knows about action priority and shortcut marker...
|
||||
// XXX should these be more like .getDoc(..) and support lists of actions???
|
||||
@ -875,6 +881,7 @@ module.Dialogs = core.ImageGridFeatures.Feature({
|
||||
|
||||
tag: 'ui-dialogs',
|
||||
depends: [
|
||||
'cache',
|
||||
'ui',
|
||||
],
|
||||
|
||||
@ -1978,7 +1985,7 @@ module.ContextActionMenu = core.ImageGridFeatures.Feature({
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
// XXX mac seems not to have the utf gear icon...
|
||||
// mac seems not to have the utf gear icon...
|
||||
var SETTINGS_ICON =
|
||||
typeof(navigator) == 'undefined' ? 'settings'
|
||||
: navigator.platform == 'Win32' ? '⛭'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user