Questions about TW Source Code

Just a general thread for questions which pop up as I attempt to understand TW’s inner workings.

What is this bit of dollar sign magic? How is this require() resolved?


var widget = require("$:/core/modules/widgets/widget.js")

TW implements its own require function, which works in the browser and for TW Node.js client server configurations. It does understand the TW “syntax” for system tiddlers.

In TW a tiddler prefixed $:/ is a system tiddler which by default is hidden from lists in the UI.

Is the TW “file system” explained somewhere?

$:/temp or $:/config make some sense but what about $:/status.

And, in general what does the path seperated hierarchy mean or imply? Why do it, what’s the functional implication of structuring titles this way in general?

As I wrote in the first reply. $:/ is the indicator for system tiddlers

The rest of the tiddler title we call a namespace. Namespaces can easily be listed with eg: [prefix[$:/temp/]]

Tiddlers prefixed $:/temp/ are not saved and have no effect on the TW dirty-indicator.

Tiddlers prefixed $:/state/ are saved but do not influence the dirty-indicator

$:/config/ tiddlers contain internal configuration data for default values. Most of the $:/ControlPanel settings are prefixed with $:/config.

Also See: Naming of System Tiddlers and StateMechanism

1 Like

TW has 2 (3) types of tiddlers.

  1. Content tiddlers that have been modified by the user
  2. Shadow tiddlers that are delivered as plugins
  3. Modified shadow tiddlers, which become system tiddlers because they are prefixed $:/

The TW core is a plugin named: $:/core
At startup first the TW core and then the plugin tiddlers are extracted and initialized. They are stored into an internal memory we call “Shadow tiddlers”.

This memory is immutable, but can be overwritten. eg: If you open the link Animation Duration in the Control Panel and try to edit it, you get a warning.

You are about to edit a ShadowTiddler. …

It is perfectly fine to do so because ControlPanel settings are meant to be changed.
If they are changed shadow tiddlers become “normal” “system tiddlers”. They are saved and the next time you start your wiki they will be restored.

The advantage of shadow tiddlers is. If you delete the $:/config/AnimationDuration tiddler. The shadow tiddler will take over again

That’s a key feature of TW. The user has full control over every aspect of the UI, but there will always be a sensible default value, which can be re-activated again.

3 Likes

Thanks for the answer and the helpful link I somehow missed. What is “$:/status”?

I think that’s a typo. But it is like that since 11 years.

It’s not exactly a typo, more an early convention that didn’t gain adoption elsewhere in the core. The idea was that the $:/status/* namespace was for tiddlers that were intended to be written by the system and only read by users. For example, changing $:/status/UserName isn’t sufficient to change the username throughout the system when using the client server configuration, it only changes the username visible to the user interface.

As it turned out we haven’t encountered very many configuration tiddlers of this type and so the prefix has fallen into disuse.