the sub-context experiment finally working... still thinking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-12-07 01:12:15 +03:00
parent 16ecebb1c0
commit 0ead526ea9
2 changed files with 56 additions and 10 deletions

View File

@ -934,11 +934,11 @@ var ExampleUIActions = actions.Actions({
return that.features.features.length }) return that.features.features.length })
make.field('A', 'B') make.field('A', 'B')
make.field.field('C', 'D') //make.field.field('C', 'D')
make.field.field.field('E', 'F') //make.field.field.field('E', 'F')
make.field.field.field.field('G', 'H') make.field.field.field.field('G', 'H')
//make.field.Toggle('Toggle', 'on') make.field.Toggle('Toggle', 'on')
}, { }, {
cls: 'table-view', cls: 'table-view',

View File

@ -960,15 +960,62 @@ module.Dialogs = core.ImageGridFeatures.Feature({
// XXX EXPERIMENTAL... // XXX EXPERIMENTAL...
// //
// .makeContext(name[, obj]) // Make a nested context...
// .makeContext(name, func[, obj]) //
// Make a nested context object...
// .makeSubContext(name[, obj])
// -> context
//
// Make a nested context function...
// .makeSubContext(name, func[, obj])
// -> context
//
//
// The context inherits from .items / make(..)
//
// If the context is callable it will be called in the context of make(..)
//
// If the context is constructed recursively it will return self
// //
// //
// XXX BUGGY...
// XXX move this to browse??? // XXX move this to browse???
// ...there seems to be no way to make this generic... // ...there seems to be no way to make this generic...
browse.items.makeContext = function(name, obj){ browse.items.makeSubContext = function(name, obj){
} // arse args...
var args = [...arguments].slice(1)
var func = args[0] instanceof Function ?
args.shift()
: null
obj = args.shift()
var n = '__'+ name
Object.defineProperty(this, name, {
get: function(){
var that = this
if(!this.hasOwnProperty(n)){
// build the context object...
var nested =
func ?
// NOTE: we always call func(..) in the root context...
function(){
return func.call(that, ...arguments) }
: this instanceof Function ?
function(){
return root.call(this, ...arguments) }
: {}
nested.__proto__ = this
// mixin parent/obj...
Object.assign(nested,
this[n] || obj || {})
// NOTE: this will prevent constructing a nested context
// (see test above)...
this[n] = nested[n] = nested
}
return this[n] },
})
return this[name] }
@ -994,7 +1041,7 @@ browse.items.makeContext = function(name, obj){
// ...and should we break the make(..) convention of passing an arg // ...and should we break the make(..) convention of passing an arg
// array for multiple .text blocks, i.e. make([title, value], ...)?? // array for multiple .text blocks, i.e. make([title, value], ...)??
//browse.items.Field = //browse.items.Field =
browse.items.makeContext('field', browse.items.makeSubContext('field',
function(title, value, options){ function(title, value, options){
options = options || {} options = options || {}
Object.assign( Object.assign(
@ -1148,7 +1195,6 @@ function(spec, callback){
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
var EditorActions = actions.Actions({ var EditorActions = actions.Actions({