[tw5] Javascript non-macros

The dev documentation states “Macros are just used to return a chunk of wikitext for further processing. They should not make modifications to tiddlers in the wiki store.”

Is there such a thing as a Javascript non-macro? Is there a hook point where I can have my own js code that can modify tiddlers? Basically I want to be able to set field values from js. As I’d much rather use js than the conglomerate that is wikitext, widgets, filters, and macros.

Thanks.

The dev documentation states “Macros are just used to return a chunk of wikitext for further processing. They should not make modifications to tiddlers in the wiki store.”

The main reason, why macros shouldn’t have side effects is, that they don’t have a .refresh() function of their own. They are refreshed by “parent” widgets.

So if you want to implement your own functionality, that survives a page refresh you need to create widgets.

Is there a hook point where I can have my own js code that can modify tiddlers?

Widgets.

Basically I want to be able to set field values from js. As I’d much rather use js than the conglomerate that is wikitext, widgets, filters, and macros.

It depends on what you really want to do. If you just want to change some fields you are probably a 100 times faster to get stuff done if you use the existing wikitext functionality.

If you just want to see how the TW internals work you could have a closer look how widgets work.

In TW everything is driven by the “refresh” mechanism, which is automatically triggered as soon as you change a tiddler content in the store.

Changes to the tiddler store are usually driven by user interaction with “buttons” and “action widgets”. … So user actions change the tiddler content, which in turn automatically updates the UI. …

The internal tiddler store is immutable. So changing tiddlers is only possible writing a completely new tiddler. Overwriting a tiddler is done in the following way. – read tiddler content – modify the content – write tiddler with the same or a new title. Once the store is updated a “change” event is fired by the core. All widgets that depend on the tiddler content that has been changed, trigger their .refresh() function, which may write new HTML output to the DOM.

… So it really depends, what you want to do. … If you could be more specific about your usecase, I could probably point you in the right direction in the core code.

-mario

1 Like

Thanks, I will look at creating custom widgets.

If what I want to do is simple, such as set a field to a constant value, yea sure I can do that. But once something involves complex logic I often get stymied. It seems every time I gain an insight into how TW works, I discover it doesn’t work as I thought. At this point I have become incredibly frustrated. I find the syntax inconsistent with too many exceptions plus when and how to “hook together” different code types (macros, widgets, etc). https://groktiddlywiki.com & Tones GitWiki — For Designers from TW Tones (AKA TonyM) have been helpful but it is eluding my understanding. Despite javascript’s own quirks, at least it makes sense to me.