Simple tiddler refresh with trigger

Folks, Particularly devs;

I recently found some get and set session storage macros and was given set and get cookies JS macros , and I also made my own get and set window.name / window target in this topic.

However these are not widgets per say and do not trigger a refresh or change anything in a tiddler.

However I would like to cause the current tiddler to refresh.

  • I tried including an action to set a field or navigate to the current tiddler but it is still not refreshing, ie re-running one of these javascript macros to retrieve an updated value

Is there a way within tiddlywiki as it stands or if necessary a supporting action widget that could cause the tiddler, or wiki wide refresh to occur without editing the current tiddler reloading the whole wiki?

I am also finding these js macros/action widgets not working in other wikis and cant find out why.

  • Install, save, reload, check module-type set to macro.
  • Could it be different to http* or File://?

Any guidance appreciated.

Post script - I am trying top bundle all these macros into a utility package

Bump;

I have come across this once again. I am looking for an action, perhaps in a button used on an open tiddler, that on click causes the refreshing, or rendering of the content.

A extended feature would be if we could get it to refresh every minute or second it while open in the story river.

  • There are cases where
    • I only want the current tiddler re-rendered
    • and others where the whole refresh to take place to propagate this change elsewhere (if Necessary)

Note here I am trying to give rise to a refresh not inhibit it or throttle, as I see in other examples.

Why?

  • Because my tiddler contains some tests sensitive to a current time stamp.

Do you mean something like this?

2 Likes

Refresh “whatever” on timer.

Thanks @Charlie_Veniot I will research further later. I will also try your approach, but something similar I tried was notworking.

My key first desire is a viewTemplate button that refreshes the current tiddler.

That’s the easiest way to go. In which case, ignore my second post and just give the example in my first post a go.

Bump,

This is a case where my JavaScript and TiddlyWiki skills are insufficient to do this myself, however some of you may find this trivial. That is why I posted here.

  • or is it?

I raise this once again as it should, in my view be a core feature, in tiddlywiki, it is all about refreshing the DOM when we make changes. We should have a mechanism, such as an action widget, we can add to a button that triggers a refresh of the current or named tiddler “as if it had just changed”, without having to change it.

  • The worst case is to trigger a complete wiki refresh (but without reloading the tab)

For example;

  • I have a side bar tab that includes a button to display and set window.name on the current browser tab.
  • When I click the button it sets the window name.
  • However the display of the new window.name does not happen because nothing causes a refresh of the tiddler viewed in the sidebar, because it has not changed.
    • What has changed is a value outside tiddlywiki
    • The sidebar tab just sits there “looking stupid” and is not updated with the new value.

Related;

  • We can use WidgetMessage: tm-browser-refresh however this is overkill and will reload the whole tab, and warn if the wiki is dirty.
  • We can/may be able to trigger a refresh by making a change to a tiddler however what if this is a shadow?

An effective work around documented on tiddlywiki wiki may be sufficient.

It occurs to me that the content of a $list or $let widget gets refreshed when the output of the list or the definition of the variable changes. I wonder if you could use this to force a refresh by wrapping all your desired content in a $let/$list that transludes a value set by your button?

I thought that’s what I was showcasing in my first reply ?

1 Like

Sorry, @Charlie_Veniot, you’re quite right. I didn’t read back to the beginning of the thread.

I have a work around along these lines, which is to change a tiddler that will trigger the current tiddler to refresh.

  • However this Topic is asking for a permanent solution not collected work arounds, however thanks for the enthusiasm and examples.

For example in my current case the sidebar tiddler that has the change window name button, accesses the $:/config/window.name tiddler, adding the following to the button,

<$action-setfield $tiddler="$:/config/window.name" $field=refresh $value=<<now YYYY0MM0DD0hh0mm0ss0XXX>> $timestamp=no/>

This results in the refresh;

  • It is similar to @Charlie_Veniot’s solution
  • It leaves the tiddlers created and modified alone

However

The above demands changing a tiddler and/or having insight as to a tiddler “out there”, that when changed will cause the desired refresh.

The point is TiddlyWiki identifies what to refresh and does so already.

I want a simple action widget where we tell it what to refresh eg;

message="tm-refresh-tiddler" $param="tiddlername"

The reverse of all the features to “defer refresh”.

  • This could complement those such as disable refresh unless a specific refresh is requested
    • By a Button
    • Action off an existing button or action eg Done
    • Through other methods like a timed or on load action.

Examples may include big list tiddlers to only refresh when asked (click button) to to improve performance.

When changes occur, the rendering is updated by calling the “refresh” method of the root widget. The refresh method determines whether the widget needs to be updated to reflect the incoming changes, and then recursively calls into the refresh methods of each child widget.

I now see there may need to be a complimentary feature that allows us to turn off refresh on specific tiddlers.

I think there may be a hybrid solution here.

I am thinking a custom widget to which we pass a tiddlername, current tiddler by default, that implements an invisible list or reveal that is sensitive to change in something.

  • This is how a refresh occurs
  • this sounds familiar somewhere there is an action refresh on change of tiddler.
  • Perhaps a last refresh time?

Now simply add this custom widget in a tiddler you want to be refreshed when something in particular changes.

  • In the body call and action make a change to an external element that triggers the widget in the current tiddler to refresh.
  • Perhaps import this custom widget?

This is very reminiscent of @saqimtiaz’s $refresh widget, available here: Saq's Sandbox — Experimental doodads.

1 Like

His widget seems to reduce refresh, restricting it to a smaller set of items. I want the reverse, I want a tiddler to refresh when it would not have, based on a change in another tiddler.

  • There are clues in other comments but I am struggling to make a simple working solution.

At the moment I have a standard tiddler title tiddlername and a related tiddler $:/meta/tiddlername I would like a way to “hard code” in tiddlername a method that causes it to refresh on screen, and in sidebar tabs, if the modified field of $:/meta/tiddlername changes.

An arbitrarily chosen, dependent tiddler.

Maybe but dependency may include on an external factor. For example I have a button that sets a browser tab property, the window.name using actionset-windowname in a button, and I have a filter operator that returns the window name. eg {{{ [window.name[]] }}} This does not refresh when the window name changes.

Other elements do refresh but not this filter

i think if you do this, let should refresh its children. I did not test the code.

<$let x={{otherTiddler}}>

<!-- your code comes here ->>

</$let>

May be <$let x={{otherTiddler!!title}}> is also OK

-m

@pmario I have not forgotten your answer here.

I did manage to fix this as I introduced additional features to my code thus causing a refresh to occur anyway. However I am keen to find and document a robust way to do this. A Code Pattern including the action to set the “refresh trigger” etyc…, we can share, so if you have any thoughts please share.

If I consider your example it could reference a standard tiddler eg; $:/temp/trigger-refresh, and perhaps a global macro to define this as <<refresh-trigger>>.

With an action prepared to set this tiddler text to now.

Then we can use;

<$let last-refresh=<<refresh-trigger>> >

<!-- your code comes here will refresh when $:/temp/trigger-refresh changes -->

</$let>

with this defined;

\define refresh-trigger-action() <$action-setfield $tiddler="$:/temp/trigger-refresh" $value=<<now YYYY0MM0DD0hh0mm0ss0XXX>>/>

Noting use <<refresh-trigger-action>> or set $:/temp/trigger-refresh to force refresh between the last-refresh let statement.

  • Perhaps we could make a custom widget that uses genesis on the let widgets yo do this;
<$refresh.section>

<!-- your code comes here will refresh when $:/temp/trigger-refresh changes -->

</$refresh.section>

And optionaly a button for manual refesh of such a section?

I think you need to clarify how that {{{ window.title[] }}} filter works.

In the “metaphysics” of TW, there is no “refresh a tiddler”.

The $tw.wiki object in your browser has a “tiddlerStore”. This is a collection of Immutable Javascript Objects. This means we do never fetch a tiddler object and change something on it. We fetch an object, make a copy, change the copy, and replace the original tiddler in the sotre with the new copy AS A WHOLE.

This happens any time you write to any tiddler/field using the UI (edit mode OR buttons that update fields, etc).

Separately, we have a collection of Widgets and a DOM. THESE things refresh, and are done using a complex set of logic to only “selectively refresh certain branches of the widget tree”. This prevents the whole DOM (i.e. what the browser renders to the screen) from refreshing every time a tiddler is written to the store, which would be EXPENSIVE.

If a chunk of your DOM is not refreshing as you need it to, then a widget’s (or a filter’s) javascript needs to be looked at. OR the wiki-text structure surrounding that widget-node’s wikitext needs to be looked at.

Actually I think you mean window.name[], this is an operator of my own definition, a filter operator that returns the current browser tab/window.name, I have a matching action set windowname, both written in javascript. I am triggering this in a button, and/or a startup action.

Because neither touch the tiddler in which it is coded, in this case a sidebar tab, a change in the window name, from the action, is not reflected, ie the window.name[] operator does not retrieve the changed value, and display it.

  • Ideally I would simply have an action I could include with the trigger to refresh the tiddler it is in eg <<thisTiddler>>.
  • Otherwise I am just trying to find a helpful code pattern for people to refresh a nominated tiddler if needed. This thread includes some examples of this.
    • There could be cases in the future where I don’t want to change the tiddler to cause it to refresh eg a shadow, in a plugin.

I need to find some example code where the refresh does not occur as desired on which we can test and design an appropriate solution.