Hey @saqimtiaz, thanks for the $refresh
widget. I took a crack at improving it in a way that it would (alternatively) allow for an arbitrary filter to control refreshing, not just a subfilter with the list of changed tiddlers as input. A bit like the way that $action-listops
works. This way it’s maybe a bit more straightforward to couple refreshing to the existence of some state tiddler. Towards that goal I also added a parameter that inverts the logic and refreshes when the filter evaluates to an empty result.
$ _yaisog_modules_widgets_conditional-refresh.js.json (2.4 KB)
Attribute | Description |
---|---|
subfilter | An optional subfilter expression, which takes the list of changed tiddlers as input. The content of the widget refreshes only if the subfilter produces any output. |
filter | An optional filter expression. The content of the widget only refreshes if the filter produces any output. |
invertFilter | Optionally set to “yes” to make the widget refresh if the filter does not produce any output. Does not apply to the subfilter parameter. |
For dependence on a single state tiddler $:/state/toggle-refresh
to not exist, use:
<$conditional-refresh filter="[[$:/state/toggle-refresh]!is[tiddler]]">
<$log message="Freshly refreshed." />
</$conditional-refresh>
To display the log message only when no state tiddler with the prefix $:/state/refresh/
exists, you could use
<$conditional-refresh filter="[prefix[$:/state/refresh/]]" invertFilter="yes">
<$log message="Freshly refreshed." />
</$conditional-refresh>
The !prefix[]
syntax wouldn’t work here, as it would return a large number of tiddlers.
A beautiful application of this widget will be (I hope) to pause refreshes for the invisible tiddlers in the zoomin storyview, instead of folding / unfolding them, to make the UI more responsive. All I need to do (I think) is include $conditional-refresh
in the ViewTemplate and tie it via the filter
parameter to the current-tiddler
field of $:/HistoryList.
Folding has the disadvantage that the tiddlers need to be rendered anew when they are shown again, which would be slower than refreshing, so switching between tiddlers should become somewhat faster.
Have a nice day
Yaisog
PS: Your code won’t allow to use variables like <currentTiddler>
in the subfilter expression. I think you need to change this line:
filteredChanges = this.wiki.filterTiddlers(this.filter,null,this.wiki.makeTiddlerIterator(changedTiddlerTitles));
and replace null
with this
. That made it work for me.