Understanding state

72 views
Skip to first unread message

joearms

unread,
Dec 14, 2018, 1:46:53 PM12/14/18
to TiddlyWikiDev
Hello

I'm trying to understand the state mechanism. I'm beginning to get a clue so I thought I'd write it down before I forgot.

In the "tabs" example there is the following code:

```
<<tabs "SampleTabOne SampleTabTwo SampleTabThree SampleTabFour" "SampleTabOne" "$:/state/tab1">>
```

I made a tiddler called StateWatcher with the following code

```
<$list filter="[prefix[$:/state/tab1]]">
Content of <<currentTiddler>> =
<$transclude tiddler = <<currentTiddler>>
/>
</$list>

```

The first time I load the tiddler
containing the tabs the StateWatcher shows nothing. When I click on a tab the stateWatcher says there is a tiddler called

`$:/state/tab1-2537135` and this 
tiddler contains the name of the tab I just clicked on.

If I close the window containing the tabs the state tiddler is not destroyed. But it's not written to disk - so the state change is transient.

This thing with a name like ($:/state/tab1-2889173) seems to be what the documentation calls a `state tiddler` I'd have called it a `Global Variable whose value is wiki text`

I'm not sure how to create a state tiddler - so some more experimentation is in order.

Cheers

/Joe

PMario

unread,
Dec 15, 2018, 7:47:23 AM12/15/18
to TiddlyWikiDev
Hi Joe,

That <<tabs ..>> macro internally uses the <$reveal> widget. The reveal widget stores it's state in a state-tiddler, as you found out. The strange number at the end is a hash to make the state tiddler name unique. Unique state names are needed because of this:

Copy the following code into a new tiddler and save it:

<$button set="$:/state/SampleReveal1" setTo="show">Show me</$button>
<$button set="$:/state/SampleReveal1" setTo="hide">Hide me</$button>

<$reveal type="match" state="$:/state/SampleReveal1" text="show">

! This is the revealed content
And this is some text

</$reveal>

<$button set="$:/state/SampleReveal1" setTo="show">Show me</$button> <$button set="$:/state/SampleReveal1" setTo="hide">Hide me</$button> <$reveal type="match" state="$:/state/SampleReveal1" text="show"> ! This is the revealed content And this is some text </$reveal>

You can see 4 buttons, which will show and hide some text. ... BUT only 1 button is needed to expand both sections. ... that's a problem.

That's why the tabs-macro us the <<qualify >> macro to create unique names.

Click the link: list of tiddlers, that may help

-------------------------------
 
If I close the window containing the tabs the state tiddler is not destroyed. But it's not written to disk - so the state change is transient.

$:/state/ .. tiddlers are saved, if you save the wiki.
$:/state/popup/  ... are not saved.

The shadow-tiddler: $:/core/save/all  contains some code that allows us to define, what's saved, and what not.

\define saveTiddlerFilter()
[is[tiddler]] -[prefix[$:/state/popup/]] -[[$:/HistoryList]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
\end


have fun!
mario

joearms

unread,
Dec 15, 2018, 1:21:08 PM12/15/18
to TiddlyWikiDev
Thanks Mario,

Yes this is fun. Golly -- using global state variables for communication between tiddlers -- now where
have I seen that before? 

Cheers

/Joe
Reply all
Reply to author
Forward
0 new messages