From bd4b16387bd51eeccb3cd62c46925c04afe2292b Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sat, 1 Sep 2018 20:01:22 +0300 Subject: [PATCH] minor update... Signed-off-by: Alex A. Naanou --- actions.js | 36 ++++++++++++++++++++++++++++++++++++ package.json | 2 +- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/actions.js b/actions.js index afce1d9..d71ecb7 100755 --- a/actions.js +++ b/actions.js @@ -593,6 +593,36 @@ function(txt){ // XXX is this correct?? // NOTE: by default an action will return 'this', i.e. the action set // object the action was called from. +// NOTE: if func.nmae is set to '' it will be reset to the +// action name by Action(..). This is a means for extending functions +// to get the specific action name. +// Example: +// var getActionName = function(func){ +// var f = function(...args){ +// return func(f.name, ...args) } +// // this will force Actions(..) to set a name on f +// Object.defineProperty(f, 'name', { value: '' }) +// return f +// } +// +// ... +// +// someAction: [ +// getActionName(function(name, ...args){ +// console.log('Action name:', name) +// })], +// someOtherAction: [ +// function(name, ...args){ +// // there is no way to know the action name from within +// // and action... +// }], +// +// But note that the .name is set in definition time and not in +// call time, so renaming the action in runtime will have no effect +// on what it will log... +// Also note that using Object.defineProperty(..) is required as +// chrome ignores changes to function's .name in other cases... +// // // XXX add more metadata/docs: // .section @@ -646,6 +676,12 @@ function Action(name, doc, ldoc, attrs, func){ meth.func = func + if(func.name == ''){ + Object.defineProperty(func, 'name', { + value: name, + }) + } + // make introspection be a bit better... meth.toString = func.toString.bind(func) diff --git a/package.json b/package.json index 9ca8416..6a82e61 100755 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-actions", - "version": "3.20.0", + "version": "3.20.1", "description": "", "main": "actions.js", "scripts": {