Folks,
As demonstrated in https://tiddlywiki.com/prerelease the new function, which I remember it “begins with F for filter”, we will be able to craft our own filter operators.
Personally I feel this will be a great tool for simplifying our code, especially filters.
- Here is a simple example, where I define two filters. One is a custom `.is’ operator that tests if the tiddler has a matching value in the object-type field.
- Similarly another custom filter operator tests if the done-date field has any value, so we can also ask
!.done[]
- The new filter tests if the tiddler has the same date as today
- The same can also be applied against the current tiddler.
\function .is(object-type) [object-type<object-type>]
\function .done() [has[done-date]]
\function .new() [get[created]format:date[YYYY0MM0DD]match<now YYYY0MM0DD>then[new]]
<$list filter="[.is[todo]!.done[]]">
<$link/> = {{!!object-type}}<br>
</$list>
{{{ [all[current].is[todo]then[todoitem]else[not todo]] }}}
{{{ [all[current].new[]] }}}
Some clear advantages with filter operators like this;
- You can hide the complexity in functions and make your filters easier to read
- You can create generic functions/filters you can use in different cases eg; any tiddler todo or otherwise that has[done-date] will be considered done
- Thus you could mark a “chapter tiddler” done as well.
- Or you could change this function definition to
[tag[done]]
in a different wiki, yet make use of the same list widget code.
- you can modify the operators later to add functionality without modifying every time the filter operator is used.
- Eg; refine
.done
to test done-date is today or earlier
- Eg; refine