On Thursday, December 16, 2021 at 4:24:14 PM UTC+1 davou...@gmail.com wrote:
> The dev documentation > <https://tiddlywiki.com/dev/static/JavaScript%2520Macros.html> 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 -- You received this message because you are subscribed to the Google Groups "TiddlyWiki" group. To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/fde88708-ca30-43bc-b99d-28c5280ce7e2n%40googlegroups.com.