Lately, the $set widget has been intruding on my peace

58 views
Skip to first unread message

S. S.

unread,
Apr 12, 2019, 1:57:37 AM4/12/19
to tiddl...@googlegroups.com

Recently there was a long and interesting discussion on the $set widget which led to me making the funky (at least I think it's funky!) : Set Widget Tester for attribute precedence
That tiddler allows you to see how most every attribute combination available in the $set widget will behave against other attributes.

Today I came across a little change in the $:/core/ui/PageTemplate tiddler made the other day which made me wonder ...

The orginal code was:
$set name="currentTiddler" value={{$:/language}}>

<$set name="languageTitle" value={{!!name}}>

<$set name="currentTiddler" value="">


The comment for changing this to the new code below is:
We no longer need to mess around with the currentTiddler variable to be able to access to the "name" field of the current language

<$set name="languageTitle" value={{{ [{$:/language}get[name]] }}}>

The above is of course quite elegant and concise.
Just as a matter of interest, I was wondering why this wasn't written as either of the below:

<$set name="languageTitle" tiddler={{$:/language}} field="name">

<$set name="languageTitle" filter="[{$:/language}get[name]]">

All said, I don't know why, but I quite like the ability to accomplish the same result in 4 different ways. Maybe its because the $set widget can be used so effectively for IF THEN ELSE situations once one knows the precedence order of its attributes.

Cheers.

Edit: minor spelling correction

Jeremy Ruston

unread,
Apr 12, 2019, 3:39:10 AM4/12/19
to tiddl...@googlegroups.com
Hi SS

Recently there was a long and interesting discussion on the $set widget which led to me making the funky (at least I think it's funky!) : Set Widget Tester for attribute precedence
That tiddler allows you to see how most every attribute combination available in the $set widget will behave against other attributes.

Cool!

Today I came across a little change in the $:/core/ui/PageTemplate tiddler made the other day which made me wonder …
...
The above is of course quite elegant and concise.
Just as a matter of interest, I was wondering why this wasn't written as either of the below:

<$set name="languageTitle" tiddler={{$:/language}} field="name">

<$set name="languageTitle" filter="[{$:/language}get[name]]">

All said, I don't know why, but I quite like the ability to accomplish the same result in 4 different ways. Maybe its because the $set widget can be used so effectively for IF THEN ELSE situations once one known the precedence order of its attributes.

Interesting observation. We have indeed got multiple ways to achieve the same thing, the result of TW5’s iterative gestation. I tend to prefer the triple curly brace transcluded filtered attribute syntax because it’s the most general purpose mechanism: we can use it with any widget, or with plain DIVs.

The historical context for all of this is that at the beginning filters were not particularly powerful, and largely restricted to creating lists in e.g. the list widget. As things have progressed, it’s become clear that the filter language is a critical nexus of flexibility in the design, and we’ve significantly extended the language so that it is much more generic and powerful. In retrospect, several of the more widgets and mechanisms wouldn’t have been needed if we’d had the more powerful filter operations earlier. (For instance, the view widget, and some of the variants of the set widget we’re discussing here).

Best wishes

Jeremy.




Cheers.

--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at https://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/e96c338e-fb4c-4796-8092-b8f6337f52f9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

PMario

unread,
Apr 12, 2019, 6:12:23 AM4/12/19
to TiddlyWiki
Hi,

A very good catch. ... AND since the PageTemplate is used all the time there may be a tiny speed boost ;)

<$set name="languageTitle" value={{{ [{$:/language}get[name]] }}}>

creates this widget tree, which is 1 step away from the html output.

{
    "type": "widget",
    "children": [
        {
            "type": "set",
            "attributes": {
                "name": "languageTitle",
                "value": "en-GB"
            }
        }
    ]
}

Which is only 1 "command" and everything is already "evaluated". Every other possibility you listed will create 2 commands. The original version will create this widget tree.

{
    "type": "widget",
    "children": [
        {
            "type": "element",
            "tag": "p",
            "children": [
                {
                    "type": "text",
                    "text": "$set name=\"currentTiddler\" value="
                },
                {
                    "type": "tiddler",
                    "attributes": {
                        "tiddler": "$:/language"
                    },
                    "children": [
                        {
                            "type": "transclude",
                            "attributes": {
                                "tiddler": "$:/language"
                            },
                            "children": [
                                {
                                    "type": "link",
                                    "attributes": {
                                        "to": "$:/languages/en-GB"
                                    },
                                    "children": [
                                        {
                                            "type": "text",
                                            "text": "$:/languages/en-GB"
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "text",
                    "text": ">\n"
                },
                {
                    "type": "set",
                    "attributes": {
                        "name": "languageTitle",
                        "value": ""
                    },
                    "children": [
                        {
                            "type": "text",
                            "text": "\n"
                        },
                        {
                            "type": "set",
                            "attributes": {
                                "name": "currentTiddler",
                                "value": ""
                            },
                            "children": [
                                {
                                    "type": "text",
                                    "text": "\n"
                                }
                            ]
                        }
                    ]
                },
                {
                    "type": "text",
                    "text": "</$set>"
                }
            ]
        }
    ]
}

have fun!
mario
PS: @Jeremy, ... we should change this, it seems to be much cleener!



PMario

unread,
Apr 12, 2019, 6:30:06 AM4/12/19
to TiddlyWiki
Hi,

I did a short search for the pattern and found 2 more tiddlers that may be optimized. core/ui/StyleSheet.tid and core/templates/single.tiddler.window.tid

-m
Reply all
Reply to author
Forward
0 new messages