I see , thanks! that is a much better method to implement the idea Mark S. 在 2020年12月12日 星期六下午8:53:02 [UTC] 的信中寫道:
> I suspect your usage would break the spirit of the JS rules, since it's > using a macro to change TW content. > > But you could write a non-JS (i.e.wikitext) macro that would basically do > the same thing. If the tiddler doesn't exist, it would show a button which, > when clicked on, would create the tiddler. A button can be disguised as a > link, if that's important to you. > > > > On Saturday, December 12, 2020 at 11:29:44 AM UTC-8 Leung arvin wrote: > >> I wish to implement the following functionality, using JS macro, defining >> the macro with name M. >> >> Whenever I use a macro <<M tiddler_name : "New Tiddler">> , then it >> creates a Tiddler with title "New Tiddler". Then the macro presents this >> link [[New Tiddler]]. The point is that the macro will create the Tiddler >> for me (with some starting content , customisable in JS) if none have >> already been created. >> >> Example code would be: >> >> function run(tiddler_name){ >> - Check if wiki has tiddler with title tiddler_name >> - If not, create a tiddler of title tiddler_name and content "default >> content" >> - Return [[tiddler_name]] >> } >> >> I would like to know if this is safe. The 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 reason is that you cannott control when the macro is called; it >> may be called repeatedly as part of refresh processing. So it is important >> that macros do not have any other side effects beyond generating their >> text." >> >> So this would break the no side effect rule. However, the idempotent >> design means that subsequent calls to this macro should not have any side >> effects. >> >> Will this potentially break stuff in unknown ways? I would also like to >> know if there are other methods to achieve the same tasks in JS. >> >> -- 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/d967d530-bea7-4019-9b70-024a517c9c88n%40googlegroups.com.