mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-17 08:41:40 +00:00
still working to simplify the action architecture...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9ed14ba3b8
commit
b9e25f0c03
@ -17,20 +17,36 @@ data = require('data')
|
|||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
|
// attr can be:
|
||||||
|
// "name" - attribute name
|
||||||
|
// "name, name, ..."
|
||||||
|
// - string containign coma separated attribute names
|
||||||
|
// list - list of attribute names
|
||||||
|
//
|
||||||
// XXX add a callback here...
|
// XXX add a callback here...
|
||||||
function proxy(attr, name){
|
function proxy(attr, name){
|
||||||
|
// we can proxy multiple attrs...
|
||||||
|
attr = typeof(attr) == typeof('str')
|
||||||
|
? attr.split(',').map(function(e){ return e.trim() })
|
||||||
|
: attr
|
||||||
return function(){
|
return function(){
|
||||||
attr = this[attr]
|
var that = this
|
||||||
attr[name].apply(attr, arguments)
|
var args = arguments
|
||||||
|
attr.forEach(function(a){
|
||||||
|
a = that[a]
|
||||||
|
a[name].apply(a, args)
|
||||||
|
})
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function proxyMethods(obj, map){
|
function proxyMethods(obj, map){
|
||||||
var txt = ''
|
var txt = ''
|
||||||
|
map = map == null ? obj : map
|
||||||
|
|
||||||
for(var attr in map){
|
for(var attr in map){
|
||||||
var methods = map[attr]
|
var methods = map[attr]
|
||||||
|
methods = typeof(methods) == typeof('str') ? {attr: methods} : methods
|
||||||
for(var name in methods){
|
for(var name in methods){
|
||||||
var txt = methods[name]
|
var txt = methods[name]
|
||||||
if(txt == null){
|
if(txt == null){
|
||||||
@ -45,6 +61,7 @@ function proxyMethods(obj, map){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
/*********************************************************************/
|
||||||
|
|
||||||
// This will:
|
// This will:
|
||||||
@ -63,45 +80,59 @@ var ClientPrototype = {
|
|||||||
// .data
|
// .data
|
||||||
//
|
//
|
||||||
|
|
||||||
|
// direct proxy methods...
|
||||||
|
focusImage: 'Focus image',
|
||||||
|
focusRibbon: 'Focus ribbon',
|
||||||
|
|
||||||
|
firstImage: 'Focus first image in current ribbon',
|
||||||
|
lastImage: 'Focus last image in current ribbon',
|
||||||
|
|
||||||
// XXX client-specific API...
|
// XXX client-specific API...
|
||||||
// XXX
|
// XXX
|
||||||
}
|
}
|
||||||
|
// XXX this is temporary...
|
||||||
// setup the proxy methods...
|
// ...this will messup actual methods...
|
||||||
var ClientPrototype = proxyMethods(
|
proxyMethods(ClientPrototype)
|
||||||
ClientPrototype,
|
|
||||||
{
|
|
||||||
data: {
|
|
||||||
focusImage: 'Focus image',
|
|
||||||
focusRibbon: 'Focus ribbon',
|
|
||||||
|
|
||||||
firstImage: 'Focus first image in current ribbon',
|
|
||||||
lastImage: 'Focus last image in current ribbon',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************/
|
// XXX auto apply this...
|
||||||
|
function chainSelfAttrMethods(cls, attr, meth){
|
||||||
|
return function(){
|
||||||
var Client =
|
// NOTE: this is super, python-style but without multiple
|
||||||
module.Client =
|
// inheritance...
|
||||||
function Client(){
|
// ...that last part makes this more of a code reuse
|
||||||
// in case this is called as a function (without new)...
|
// than a programming tool...
|
||||||
if(this.constructor.name != 'Client'){
|
cls.__proto__[meth].apply(this, arguments)
|
||||||
return new Client()
|
// call the encapsulated method...
|
||||||
}
|
this[attr][meth].apply(this[attr], arguments)
|
||||||
|
return this
|
||||||
// XXX setup initial state...
|
}),
|
||||||
|
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
Client.__proto__ = ClientClassPrototype
|
|
||||||
Client.prototype = ClientPrototype
|
|
||||||
Client.prototype.constructor = Client
|
|
||||||
|
|
||||||
|
|
||||||
|
var ViewerPrototype = {
|
||||||
|
// this expects the folowing attrs:
|
||||||
|
//
|
||||||
|
// .ribbons
|
||||||
|
//
|
||||||
|
|
||||||
|
focusImage: doc('Focus image',
|
||||||
|
chainSelfAttrMethods(ViewerPrototype, 'ribbons', 'focusImage')),
|
||||||
|
focusRibbon: doc('Focus ribbon',
|
||||||
|
chainSelfAttrMethods(ViewerPrototype, 'ribbons', 'focusRibbon')),
|
||||||
|
|
||||||
|
}
|
||||||
|
ViewerPrototype.__proto__ = ClientPrototype
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var Client =
|
||||||
|
module.Client = Object.create(ClientPrototype)
|
||||||
|
|
||||||
|
var Viewer =
|
||||||
|
module.Viewer = Object.create(ViewerPrototype)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user