Dynamic changes to JS macros

I might be missing the obvious - as not the brightest bulb on the tree.

When developing, I generally change the ControlPanel to favor development ‘mode’. And let’s say I make a minor change to a JavaScript macro, var blah = true; to a var blah = false;

Seems I have to check I haven’t added any ‘unwanted’ tiddlers in the wiki, reset any ControlPanel stuff back to how I would like the wiki to initially display to the user, save the snapshot, then reload the TiddlyWiki to have the change take effect.

Not that big of a deal - but is there an easier way, or plugin; to make dynamic changes to JavaScript macros?

The need to save and reload is a key tiddlywiki browser security issue. Otherwise you could inject executable code into serverhosted wikis. The danger would be if you accidently published a wiki with this disabled.

Have a look at bookmarklets which can execute javascript over a tab or the tiddlywiki thus no reload needed however its not a direct mapping between the way you code bookmarklets and tiddlywiki nodules. Perhaps a special bookmarklet that could execute a tiddlywiki modual?

You could make a button to save and reload with a click or shortcut to simplify your workflow.

1 Like

Thanks @TW_Tones for the reply.

I suspected that security issues are at play.

Is just kinda sad, TiddlyWiki is awesome when it comes to dynamically refreshing everything when a change is made, add a tag to a tiddler - that tiddler automatically shows up in the lists of that tag. Tag a tiddler to show in the sidebar - poof! shows up in the sidebar. Widgets refresh automatically. \defines change dynamically, etc.

I do understand that if I am using a server based TiddlyWiki, where auto uploading changes to the cloud; that server has to deal with possible malware interception/injections. But for single file TiddlyWikis which are confined to the local machine on which it is running - seems a little ‘over’ secure.

@poc2go if you see substantial value for this in private wiki sites perhaps you could raise this in the developer category or on github to get some more thinking and the feasibility towards this end.

I imagin a specialy configured browser, special sand boxed environment or hacked tiddlywiki may get you there.

However I have some possible tricks I can think of. Before I try and suggest them could you try and explain what you really want, what value willl it have and to what end?

In this particular case it’s not primarily about security, but more about how javascript modules are initialized and the whole system is started in a generic and maintainable way.

TW has a “startup” mechanism, where the modules are started.

First all js-modules are loaded into memory → Then all modules are “started” in a particular (configurable) order.

If you change and save any tiddler that contains js-code, the storage system doesn’t know, that it is code. It’s just a tiddler, that happens to have code in it. …

That’s a good thing, because it’s simple. The saving mechanism only needs to know how to work with tiddlers. That’s it.

The “startup” mechanism has to figure out, that the tiddler content is “special” and initializes and executes it in the right context.

That’s the main reason, why plugins that contain js-code need a browser reload.

It probably would be possible to save and activate js-macros without a restart. BUT this would mean the js-macro handling would need to be handled by different code than the rest of the system. Which would make the system in general more complex and more difficult to maintain. There is more to loose, than to win.

4 Likes

Have a look at the Innerwiki plugin, this allows you to generate wiki inside an iframe which can be based on all or select tiddlers in the current wiki. As it is loaded in the iframe the new javacript code will be active in the innerwiki and you can test it “in memory”. When you are happy with the result in the innerwiki you can save and reload it or step back and save and reload the outer wiki.