TW5: (JS) macros vs widgets

60 views
Skip to first unread message

Sebastian Ovide

unread,
Jul 17, 2019, 2:37:11 PM7/17/19
to TiddlyWikiDev
Hi All,

I'm pretty new to TiddlyWiki as a plugin dev (I've used it a while as a simpler user). 

I'm a bit confused about when to build (JS) macros vs widgets. Is there any rule of thumb ? 

thanks

PMario

unread,
Jul 17, 2019, 4:18:31 PM7/17/19
to TiddlyWikiDev
Hi,

TW macros are relatively simple. eg:

\define test(parm1) this is param1 $param1$

Where param1 is a "text substitution".  Javascript macros have a more low level access to $tw. functions, but they are just "text substitutions".

widgets have much more possibilities in their livecycle. eg. init(), execute(), render(), refresh() and a lot more.

Macros have to be parsed every time they are executed, widgets only refresh elements / children that really changed.

This is not 100% correct, but it should give you a hint.

-m

Sebastian Ovide

unread,
Jul 17, 2019, 5:05:44 PM7/17/19
to TiddlyWikiDev
Hi Mario

thanks for that.

For example, I'm doing a simple macro that will create a graph (just a simple SVG text) based on existing tiddlers. I can render the SVG and also retrieve the tiddlers using  $tw.wiki.forEachTiddler. The problem is that the macro is called only when the page is loaded and when the tiddler that contains the macro changes, but not when any other tiddler change. That means that the SVG doesn't get updated unless that I close and open the tiddler containing it..

In this case, would you write a widget instead ?

thanks again

PMario

unread,
Jul 18, 2019, 1:48:32 AM7/18/19
to TiddlyWikiDev
Hi,
That's exactly the point. Widgets do get the refresh event, if any tiddler changes. Macros are refreshed, when rendered.
-m
Reply all
Reply to author
Forward
0 new messages