Thank you!
However, it doesn’t work, and I fail to see how this is not a worse design than my “hack”.
First of all, if TiddlyWiki was implemented in e.g. Typescript, with typed function arguments, I don’t think that filterTiddlers() would receive an object from the class Widget (or any subclass), like so:
exports.filterTiddlers = function(filterString: string, widget: Widget, source: ???)
I’m no TW expert, but this would seem like unnecessarily tight coupling.
AFAIK, the Widget class requires a parse tree node, a “document” and many other things. There is, in fact, a $tw.fakeDocument that I guess is there just to work around this tight coupling.
It seems ridiculous to have to use $tw.fakeDocument and a fake parse tree node just to pass a variable to compileFilter() – and I just proved that you don’t have to.
Your solution is kind of a workaround to the problem, where I could pass the this instance of the class CommandPaletteWidget and set my temporary variable in that object – but to me, that is abusing the class. What if another method wanted to use the “query” variable for another purpose? I have no idea.
I hope that the signature of filterTiddlers would look something like this:
exports.filterTiddlers = function(filterString: string, widget: IVariableSource, source: ???)
Where IVariableSource is an interface that only contains getVariable(name: string, options: ???). Of course, the Widget base class would implement this interface. Then you could pass a widget, but it would be obvious that you don’t have to go through that many hoops and create a mess of your code.
So… What did I miss, and what other solutions are prettier? Maybe @Maurycy has some input?
The whole widget is here: TW-commandpalette/plugins/souk21/commandpalette/widgets_commandpalettewidget.js at master · Souk21/TW-commandpalette · GitHub – and my suggested changes are here: Search improvements (variation) by cdaven · Pull Request #20 · Souk21/TW-commandpalette · GitHub (in the searchStepBuilder() method).