1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-02-09 23:50:01 +00:00

Refactor user defined function operator to make debugging easier

This commit is contained in:
Jeremy Ruston 2025-02-03 13:27:02 +00:00
parent f7043f6d43
commit d770d98aff

View File

@ -17,19 +17,24 @@ Export our filter function
*/
exports.function = function(source,operator,options) {
var functionName = operator.operands[0],
params = [];
params = [],
results;
$tw.utils.each(operator.operands.slice(1),function(param) {
params.push({value: param});
});
// console.log(`Calling ${functionName} with params ${JSON.stringify(params)}`);
var variableInfo = options.widget && options.widget.getVariableInfo && options.widget.getVariableInfo(functionName,{params: params, source: source});
if(variableInfo && variableInfo.srcVariable && variableInfo.srcVariable.isFunctionDefinition) {
return variableInfo.resultList ? variableInfo.resultList : [variableInfo.text];
results = variableInfo.resultList ? variableInfo.resultList : [variableInfo.text];
}
// Return the input list if the function wasn't found
var results = [];
source(function(tiddler,title) {
results.push(title);
});
if(!results) {
results = [];
source(function(tiddler,title) {
results.push(title);
});
}
// console.log(`function ${functionName} with params ${JSON.stringify(params)} results: ${JSON.stringify(results)}`);
return results;
};