List indexes from a dictionary tiddler (data tiddler)

151 views
Skip to first unread message

Mohammad

unread,
Aug 21, 2018, 11:00:16 AM8/21/18
to tiddl...@googlegroups.com


I have a dictionary tiddler as below (My Alert Class Dictionary)

primary:x
secondary
:x
info
:x
success
:x
warning
:x
danger
:x
light
:x
dark
:x


I used the idea by Mark S to list my classes except warning and light, so I used the below snippet, but it doesn't work?


<$list filter="[[My Alert Class Dictionary]indexes[]addprefix[bg-] -index[bg-warning bg-light]]" variable="alert-type">
<<alert-type>><br>
</$list>


Q2.
 Why the above list widget sorts indexes in output while I have not used sort[title]?


-Mohammad

Mark S.

unread,
Aug 21, 2018, 11:45:39 AM8/21/18
to TiddlyWiki
I'm not sure what bg-warn and bg-light are, since they're not in your dictionary.

You can only do boolean subtract on an entire filter run -- not inside a run.

So this might work for the first part:

[[My Alert Class Dictionary]indexes[]addprefix[alert-]]

If you just wanted to remove warn and light, then maybe this:

[[My Alert Class Dictionary]indexes[]!prefix[warn]!prefix[light]addprefix[alert-]]

Whenever a TW filter has a title list, it compresses it (eliminates duplicates), so I imagine that it may also incidentally sort the results. I haven't looked at the code, but if it was me I would just use javascript's ability to eliminate duplicates, then pull out the unique values. That might imply that sorting would be dependent on which browser you used, since different javascript engines might have internal differences.

-- Mark

On Tuesday, August 21, 2018 at 8:00:16 AM UTC-7, Mohammad wrote:


I have a dictionary tiddler as below (My Alert Class Dictionary)

primary:x
secondary
:x
info
:x
success
:x
warning
:x
danger
:x
light
:x
dark
:x


I used the idea by Mark S to list my classes except warning and light, so I used the below snippet, but it doesn't work?


<$list filter="[[My Alert Class Dictionary]indexes[]addprefix[alert-] -index[bg-warning bg-light]]" variable="alert-type">
<<alert-type>><br>
</$list>


Mohammad

unread,
Aug 21, 2018, 11:57:27 AM8/21/18
to TiddlyWiki
Thank you Mark!
I edited my question! yes the correct code was
<$list filter="[[My Alert Class Dictionary]indexes[]addprefix[bg-] -index[bg-warning bg-light]]" variable="alert-type">
<<alert-type>><br>
</$list>

No I learned I can remove those indexes (light and warning) before adding the prefix bg-

I use chrome and for me the results by indexes operator is sorted! not good for what i want to do!

Mohammad

FrD

unread,
Aug 21, 2018, 12:20:13 PM8/21/18
to TiddlyWiki
Hi Mohammad,

Here is the main function in 

$:/core/modules/filters/indexes.js :


exports.indexes = function(source,operator,options) {
       
var results = [];
        source
(function(tiddler,title) {
               
var data = options.wiki.getTiddlerDataCached(title);
               
if(data) {
                        $tw
.utils.pushTop(results,Object.keys(data));
               
}
       
});
       
results.sort();
       
return results;
};

It indeed sorts the results !


Regards

FrD

Mohammad

unread,
Aug 21, 2018, 12:32:51 PM8/21/18
to tiddl...@googlegroups.com
Many thanks FrD. I am not good at JavaScript!

So, I understood the core indexes.js returned the result sorted! I don't now what is the philosophy behind but it has been restricted this way!
we have the sort[title] and if one needs the result sorted it can be used.

Mohammad

PMario

unread,
Aug 21, 2018, 1:34:00 PM8/21/18
to TiddlyWiki
Hi,

See: https://github.com/Jermolene/TiddlyWiki5/issues/3407, which contains some more info.

-m

Mark S.

unread,
Aug 21, 2018, 1:46:02 PM8/21/18
to TiddlyWiki
In other words, you could delete results.sort and it might work ... but there's no guarantee that it will work everywhere for all time.

Instead of a data dictionary, perhaps a series of tiddlers with a sort field would work better.

-- Mark

Mohammad

unread,
Aug 21, 2018, 2:04:44 PM8/21/18
to TiddlyWiki
Thank you Mario and Mark!
Yes, as Jeremy explained, seems for now there is no solution!
I will use tiddlers instead of dictionary!

Mohammad

PMario

unread,
Aug 21, 2018, 2:57:50 PM8/21/18
to TiddlyWiki
On Tuesday, August 21, 2018 at 7:46:02 PM UTC+2, Mark S. wrote:
In other words, you could delete results.sort and it might work

No. It will break the core if you delete it.
 
... but there's no guarantee that it will work everywhere for all time.
Instead of a data dictionary, perhaps a series of tiddlers with a sort field would work better.

The .sort() function is there to create a consistent behaviour for all browsers, so users can rely on the behaviour of the core. Nothing more.

-m

Mark S.

unread,
Aug 21, 2018, 3:51:08 PM8/21/18
to TiddlyWiki


On Tuesday, August 21, 2018 at 11:57:50 AM UTC-7, PMario wrote:

No. It will break the core if you delete it.
 


Had to try that ... seems to work even after deleted. But there may be some feature  of which I am not aware that isn't working correctly.

-- Mark
Message has been deleted

PMario

unread,
Aug 22, 2018, 4:30:58 PM8/22/18
to TiddlyWiki
OK ... I should have been more specific.

If the line is removed, the software is unpredictable if used with different browsers. ...---> I consider this behaviour as "broken" ... It will produce very subtle differences for different users. Which will result in problems that are close to impossible to be found. ---> Which will result in a lot of time wasted for maintenance.

-m

Reply all
Reply to author
Forward
0 new messages