[tw5] Re: Javascript non-macros

2021-12-16 Thread Louis Davout
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 & 
https://anthonymuscio.github.io/#Standard%20Nomenclature have been helpful 
but it is eluding my understanding. Despite javascript's own quirks, at 
least it makes sense to me.

On Thursday, December 16, 2021 at 11:00:07 AM UTC-5 PMario wrote:

> On Thursday, December 16, 2021 at 4:24:14 PM UTC+1 davou...@gmail.com 
> wrote:
>
>> 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
>
>

-- 
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/fba0883c-5824-437f-8db4-c2735049932dn%40googlegroups.com.


[tw5] Re: Javascript non-macros

2021-12-16 Thread PMario
On Thursday, December 16, 2021 at 4:24:14 PM UTC+1 davou...@gmail.com wrote:

> 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

-- 
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.