One macro reading and writing to a tiddler: how do we go about it ?

58 views
Skip to first unread message

Charlie Veniot

unread,
May 26, 2021, 9:10:16 PM5/26/21
to TiddlyWiki
G'day all,

I've working on one large "actions" macro that uses a tiddler as storage of values in a multi-stage processing of data, expanding and contracting data (data transformation), iterating incrementally towards a final destination.

I've noted, and it makes sense to me, that as a macro writes to a tiddler (i.e. setting field values), the same macro can't read in those values.

I've also noted that after a macro writes to a tiddler, the macro can access fields from the same tiddler after a <$action-confirm> prompt.

Is there an alternative that does not involve user interaction that can, within one macro, commit writes to a tiddler such that the macro can subsequently read the tiddler ?

I guess I'm asking for some sort of "action-commit-edits" widget.

Not quite sure what to look for, and: please be gentle!  This is foreign territory for me, and I might need a bit of a vocabulary lesson and for-dumb-dumbs education about whatever related mechanisms need understanding.

Thanks much, and cheers !

Cheers !

TW Tones

unread,
May 27, 2021, 12:15:54 AM5/27/21
to TiddlyWiki
Charlie,

I have asked for similar in the past but learned this is the consequence of tiddlywikis model and we just need to work around it. 

Your commit really takes place at the end of the trigger that initiates it.

here is a quick dump of thoughts, on an other wise complex topic. I hope it helps. Please ask more or share a usable demo.

They key way is to structure your design to generate and store the values in variables and use those inside the same macro, even if you are writing your macros to store these values externally later. 

In some ways you can make a solution that generates a result to review, then a separate click commits it to a tiddler. The same macro can first determine if the previous step has already occurred and use the information there in to proceed.

Whilst this may all at first seem unnecessarily complex, do remember this comes about because of TiddlyWiki unique approach and features, a key one being always interactive and self refreshing. In some ways it does not support reiterative batch processes, but there is possibly always another way to achieve it.

The closest I have come to in what you are asking for is a button creating a tiddler containing a macro definition that is tagged as a macro and becomes available as a global variable once written, which is used in a subsequent step.

Another, may be to trigger an action on navigate to a tiddler, then the first step the user takes with a button click is actually the second step which is to commit the change and reevaluate.

Another technique I have used is restartable solutions - ie first time it commits every thing, second time it only finds changes and commits only the changes, The second commit is what you may call update or refresh. But until then what you see is the final result (so far).

Regards
Tones 

Eric Shulman

unread,
May 27, 2021, 1:26:29 AM5/27/21
to TiddlyWiki
On Wednesday, May 26, 2021 at 6:10:16 PM UTC-7 cj.v...@gmail.com wrote:
Is there an alternative that does not involve user interaction that can, within one macro, commit writes to a tiddler such that the macro can subsequently read the tiddler ?

There is a "trick" that will, for some use-cases, allow you to achieve the results you want.

Let's assume you are triggering the actions via a $button widget.  There are two ways to define the $button actions 
1) In the body of the $button widget
2) using the actions= parameter of the $button widget.

The trick is to use both methods.  Action in the $button body are performed first.  Then, after those actions are completed, the action=... parameter is processed.

Thus,
\define part1()
<$action-setfield foo="something" />
\end

\define part2()
<$list filter="[{!!foo}match[something]]">
   <$action-setfield bar="somethingelse" />
</$list>
\end

<$button actions=<<part2>>> click me <<part1>> </$button>

Unfortunately, this technique can't be generalized to more than two separate sets of actions, but even so, it is still quite useful for solving a number of sticky problems.

enjoy,
-e

Charlie Veniot

unread,
May 27, 2021, 9:33:47 AM5/27/21
to TiddlyWiki
Thanks !

tenor.gif
Reply all
Reply to author
Forward
0 new messages