mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 00:50:28 +00:00
Remove implementation of $:/globals/
Performance with this implementation is inherently poor because of the need to perform a wiki lookup for each child widget created.
This commit is contained in:
parent
1aba8a1f65
commit
e3d13696c8
@ -40,10 +40,6 @@ Error/RetrievingSkinny: Error retrieving skinny tiddler list
|
||||
Error/SavingToTWEdit: Error saving to TWEdit
|
||||
Error/WhileSaving: Error while saving
|
||||
Error/XMLHttpRequest: XMLHttpRequest error code
|
||||
Globals/Caption: Global <<type>>: ''<<name>>''
|
||||
Globals/ListItem: ''<<name>>'' (<<type>>)
|
||||
Globals/Parameters/Caption: Parameters:
|
||||
Globals/Text/Caption: Text:
|
||||
InternalJavaScriptError/Title: Internal JavaScript Error
|
||||
InternalJavaScriptError/Hint: Well, this is embarrassing. It is recommended that you restart TiddlyWiki by refreshing your browser
|
||||
LayoutSwitcher/Description: Open the layout switcher
|
||||
|
@ -5,7 +5,6 @@ All/Caption: All
|
||||
Contents/Caption: Contents
|
||||
Drafts/Caption: Drafts
|
||||
Explorer/Caption: Explorer
|
||||
Globals/Caption: Globals
|
||||
Missing/Caption: Missing
|
||||
More/Caption: More
|
||||
Open/Caption: Open
|
||||
|
@ -386,7 +386,7 @@ Selectively refreshes the widget if needed. Returns true if the widget or any of
|
||||
*/
|
||||
TranscludeWidget.prototype.refresh = function(changedTiddlers) {
|
||||
var changedAttributes = this.computeAttributes();
|
||||
if(($tw.utils.count(changedAttributes) > 0) || (this.transcludeTitle && changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh()) || (this.transcludeVariable && changedTiddlers["$:/global/" + this.transcludeVariable])) {
|
||||
if(($tw.utils.count(changedAttributes) > 0) || (this.transcludeTitle && changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) {
|
||||
this.refreshSelf();
|
||||
return true;
|
||||
} else {
|
||||
|
@ -155,20 +155,6 @@ Widget.prototype.getVariableInfo = function(name,options) {
|
||||
}
|
||||
// If the variable doesn't exist in the parent widget then look for a macro module
|
||||
var text = this.evaluateMacroModule(name,actualParams);
|
||||
if(text === undefined) {
|
||||
// Check for a shadow variable tiddler
|
||||
var tiddler = this.wiki.getTiddler("$:/global/" + name);
|
||||
if(tiddler) {
|
||||
return processVariable({
|
||||
value: tiddler.getFieldString("text"),
|
||||
params: $tw.utils.parseParameterDefinition(tiddler.getFieldString("_parameters"),{requireParenthesis: true}),
|
||||
isMacroDefinition: tiddler.getFieldString("_is_macro") === "yes",
|
||||
isWidgetDefinition: tiddler.getFieldString("_is_widget") === "yes",
|
||||
isProcedureDefinition: tiddler.getFieldString("_is_procedure") === "yes",
|
||||
isFunctionDefinition: tiddler.getFieldString("_is_function") === "yes"
|
||||
});
|
||||
}
|
||||
}
|
||||
if(text === undefined) {
|
||||
text = options.defaultValue;
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
title: $:/core/ui/MoreSideBar/Globals
|
||||
tags: $:/tags/MoreSideBar
|
||||
caption: {{$:/language/SideBar/Globals/Caption}}
|
||||
|
||||
<$list filter="[all[tiddlers+shadows]prefix[$:/global/]sort[]]">
|
||||
<div class="tc-menu-list-item">
|
||||
<$link>
|
||||
<$let
|
||||
name={{{ [<currentTiddler>removeprefix[$:/global/]] }}}
|
||||
type={{{ [{!!_is_macro}match[yes]then[macro]] :else[{!!_is_function}match[yes]then[function]] :else[{!!_is_procedure}match[yes]then[procedure]] :else[{!!_is_widget}match[yes]then[widget]] :else[[variable]] }}}
|
||||
>
|
||||
{{$:/language/Globals/ListItem}}
|
||||
</$let>
|
||||
</$link>
|
||||
</div>
|
||||
</$list>
|
@ -1,26 +0,0 @@
|
||||
title: $:/core/ui/ViewTemplate/body/global
|
||||
|
||||
\whitespace trim
|
||||
|
||||
\procedure display-global()
|
||||
<div class="tc-global-tiddler-body">
|
||||
<div class="tc-global-tiddler-body-heading">
|
||||
<h2 class="tc-global-tiddler-body-type">
|
||||
<$let
|
||||
name={{{ [<currentTiddler>removeprefix[$:/global/]] }}}
|
||||
type={{{ [{!!_is_macro}match[yes]then[macro]] :else[{!!_is_function}match[yes]then[function]] :else[{!!_is_procedure}match[yes]then[procedure]] :else[{!!_is_widget}match[yes]then[widget]] :else[[variable]] }}}
|
||||
>
|
||||
{{$:/language/Globals/Caption}}
|
||||
</$let>
|
||||
</h2>
|
||||
<$list filter="[<currentTiddler>has[_parameters]]" variable="ignore">
|
||||
{{$:/language/Globals/Parameters/Caption}}
|
||||
<pre class="tc-global-tiddler-body-details"><code><$text text={{!!_parameters}}/></code></pre>
|
||||
</$list>
|
||||
</div>
|
||||
{{$:/language/Globals/Text/Caption}}
|
||||
<$transclude tiddler="$:/core/ui/ViewTemplate/body/code"/>
|
||||
</div>
|
||||
\end
|
||||
|
||||
<$transclude $variable="display-global" $mode="inline"/>
|
@ -1,6 +0,0 @@
|
||||
title: $:/core/ui/ViewTemplate/title/global
|
||||
|
||||
\whitespace trim
|
||||
<h2 class="tc-title" title={{$:/language/SystemTiddler/Tooltip}}>
|
||||
<span class="tc-system-title-prefix">$:/global/</span><$text text={{{ [<currentTiddler>removeprefix[$:/global/]] }}}/>
|
||||
</h2>
|
@ -1,7 +1,6 @@
|
||||
title: $:/config/ViewTemplateBodyFilters/
|
||||
tags: $:/tags/ViewTemplateBodyFilter
|
||||
|
||||
global: [prefix[$:/global/]then[$:/core/ui/ViewTemplate/body/global]]
|
||||
stylesheet: [tag[$:/tags/Stylesheet]then[$:/core/ui/ViewTemplate/body/rendered-plain-text]]
|
||||
system: [prefix[$:/boot/]] [prefix[$:/config/]] [prefix[$:/core/macros]] [prefix[$:/core/save/]] [prefix[$:/core/templates/]] [prefix[$:/core/ui/]split[/]count[]compare:number:eq[4]] [prefix[$:/info/]] [prefix[$:/language/]] [prefix[$:/languages/]] [prefix[$:/snippets/]] [prefix[$:/state/]] [prefix[$:/status/]] [prefix[$:/info/]] [prefix[$:/temp/]] +[!is[image]limit[1]then[$:/core/ui/ViewTemplate/body/code]]
|
||||
code-body: [field:code-body[yes]then[$:/core/ui/ViewTemplate/body/code]]
|
||||
|
@ -1,6 +1,5 @@
|
||||
title: $:/config/ViewTemplateTitleFilters/
|
||||
tags: $:/tags/ViewTemplateTitleFilter
|
||||
|
||||
global: [prefix[$:/global/]then[$:/core/ui/ViewTemplate/title/global]]
|
||||
system: [prefix[$:/]then[$:/core/ui/ViewTemplate/title/system]]
|
||||
default: [[$:/core/ui/ViewTemplate/title/default]]
|
||||
|
@ -1,9 +1,8 @@
|
||||
title: $:/global/tabs
|
||||
title: $:/core/macros/tabs
|
||||
tags: $:/tags/Macro
|
||||
code-body: yes
|
||||
_parameters: (tabsList,default,state:"$:/state/tab",class,template,buttonTemplate,retain,actions,explicitState)
|
||||
_is_macro: yes
|
||||
|
||||
\?define tabs-button()
|
||||
\define tabs-button()
|
||||
\whitespace trim
|
||||
<$button set=<<tabsState>> setTo=<<currentTab>> default=<<__default__>> selectedClass="tc-tab-selected" tooltip={{!!tooltip}} role="switch">
|
||||
<$tiddler tiddler=<<save-currentTiddler>>>
|
||||
@ -19,7 +18,7 @@ _is_macro: yes
|
||||
</$button>
|
||||
\end
|
||||
|
||||
\?define tabs-tab()
|
||||
\define tabs-tab()
|
||||
\whitespace trim
|
||||
<$set name="save-currentTiddler" value=<<currentTiddler>>>
|
||||
<$tiddler tiddler=<<currentTab>>>
|
||||
@ -28,14 +27,14 @@ _is_macro: yes
|
||||
</$set>
|
||||
\end
|
||||
|
||||
\?define tabs-tab-list()
|
||||
\define tabs-tab-list()
|
||||
\whitespace trim
|
||||
<$list filter=<<__tabsList__>> variable="currentTab" storyview="pop">
|
||||
<<tabs-tab>>
|
||||
</$list>
|
||||
\end
|
||||
|
||||
\?define tabs-tab-body()
|
||||
\define tabs-tab-body()
|
||||
\whitespace trim
|
||||
<$list filter=<<__tabsList__>> variable="currentTab">
|
||||
<$reveal type="match" state=<<tabsState>> text=<<currentTab>> default=<<__default__>> retain=<<__retain__>> tag="div">
|
||||
@ -46,6 +45,7 @@ _is_macro: yes
|
||||
</$list>
|
||||
\end
|
||||
|
||||
\define tabs(tabsList,default,state:"$:/state/tab",class,template,buttonTemplate,retain,actions,explicitState)
|
||||
\whitespace trim
|
||||
<$qualify title=<<__state__>> name="qualifiedState">
|
||||
<$let tabsState={{{ [<__explicitState__>minlength[1]] ~[<qualifiedState>] }}}>
|
||||
@ -60,3 +60,4 @@ _is_macro: yes
|
||||
</div>
|
||||
</$let>
|
||||
</$qualify>
|
||||
\end
|
@ -1,3 +1,3 @@
|
||||
title: $:/tags/MoreSideBar
|
||||
list: [[$:/core/ui/MoreSideBar/All]] [[$:/core/ui/MoreSideBar/Recent]] [[$:/core/ui/MoreSideBar/Tags]] [[$:/core/ui/MoreSideBar/Missing]] [[$:/core/ui/MoreSideBar/Drafts]] [[$:/core/ui/MoreSideBar/Orphans]] [[$:/core/ui/MoreSideBar/Types]] [[$:/core/ui/MoreSideBar/System]] [[$:/core/ui/MoreSideBar/Shadows]] [[$:/core/ui/MoreSideBar/Explorer]] [[$:/core/ui/MoreSideBar/Globals]] [[$:/core/ui/MoreSideBar/Plugins]]
|
||||
list: [[$:/core/ui/MoreSideBar/All]] [[$:/core/ui/MoreSideBar/Recent]] [[$:/core/ui/MoreSideBar/Tags]] [[$:/core/ui/MoreSideBar/Missing]] [[$:/core/ui/MoreSideBar/Drafts]] [[$:/core/ui/MoreSideBar/Orphans]] [[$:/core/ui/MoreSideBar/Types]] [[$:/core/ui/MoreSideBar/System]] [[$:/core/ui/MoreSideBar/Shadows]] [[$:/core/ui/MoreSideBar/Explorer]] [[$:/core/ui/MoreSideBar/Plugins]]
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
title: $:/tags/ViewTemplateBodyFilter
|
||||
list: $:/config/ViewTemplateBodyFilters/hide-body $:/config/ViewTemplateBodyFilters/global $:/config/ViewTemplateBodyFilters/code-body $:/config/ViewTemplateBodyFilters/stylesheet $:/config/ViewTemplateBodyFilters/system $:/config/ViewTemplateBodyFilters/import $:/config/ViewTemplateBodyFilters/plugin $:/config/ViewTemplateBodyFilters/default
|
||||
list: $:/config/ViewTemplateBodyFilters/hide-body $:/config/ViewTemplateBodyFilters/code-body $:/config/ViewTemplateBodyFilters/stylesheet $:/config/ViewTemplateBodyFilters/system $:/config/ViewTemplateBodyFilters/import $:/config/ViewTemplateBodyFilters/plugin $:/config/ViewTemplateBodyFilters/default
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
title: $:/tags/ViewTemplateTitleFilter
|
||||
list: $:/config/ViewTemplateTitleFilters/global $:/config/ViewTemplateTitleFilters/system $:/config/ViewTemplateTitleFilters/default
|
||||
list: $:/config/ViewTemplateTitleFilters/system $:/config/ViewTemplateTitleFilters/default
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
title: Globals/CustomWidget
|
||||
description: Global shadow variable defining a custom widget
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<$$mywidget foo="Mahogany">
|
||||
Sycamore!
|
||||
</$$mywidget>
|
||||
+
|
||||
title: $:/global/$$mywidget
|
||||
_is_widget: yes
|
||||
_parameters: (foo:"bar")
|
||||
|
||||
Koala! <$text text=<<foo>>/>, <$slot $name="ts-raw"/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Koala! Mahogany, Sycamore!</p>
|
@ -1,23 +0,0 @@
|
||||
title: Globals/CustomWidgetAlt
|
||||
description: Global shadow variable defining a custom widget, without using a _parameters field
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<$$mywidget foo="Mahogany">
|
||||
Sycamore!
|
||||
</$$mywidget>
|
||||
+
|
||||
title: $:/global/$$mywidget
|
||||
_is_widget: yes
|
||||
|
||||
\parameters (foo:"bar")
|
||||
|
||||
Koala! <$text text=<<foo>>/>, <$slot $name="ts-raw"/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Koala! Mahogany, Sycamore!</p>
|
@ -1,22 +0,0 @@
|
||||
title: Globals/Functions
|
||||
description: Global functions in shadow variables
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<$text text=<<this-is-one>>/>
|
||||
|
|
||||
<$text text=<<this-is-one 7>>/>
|
||||
+
|
||||
title: $:/global/this-is-one
|
||||
_is_function: yes
|
||||
_parameters: (foo:"2")
|
||||
|
||||
[<foo>multiply[2.5]]
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>5|17.5</p>
|
@ -1,27 +0,0 @@
|
||||
title: Globals/Procedures
|
||||
description: Global procedures in shadow variables
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<<this-is-one>>
|
||||
|
|
||||
<<this-is-one blah>>
|
||||
+
|
||||
title: $:/global/this-is-one
|
||||
|
||||
\whitespace trim
|
||||
|
||||
\procedure example()
|
||||
ONE
|
||||
\end
|
||||
|
||||
\parameters (foo:"nothing")
|
||||
<<example>>-<$text text=<<foo>>/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>ONE-nothing</p><p>|ONE-blah</p>
|
@ -1,26 +0,0 @@
|
||||
title: Globals/ProceduresWithConditionalDefinitions
|
||||
description: Global procedures with conditional definitions to allow overriding
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<<this-is-one>>|<<this-is-one blah>>~
|
||||
<$let example="TWO"><<this-is-one>>|<<this-is-one blah>></$let>
|
||||
+
|
||||
title: $:/global/this-is-one
|
||||
|
||||
\whitespace trim
|
||||
|
||||
\?procedure example()
|
||||
ONE
|
||||
\end
|
||||
|
||||
\parameters (foo:"nothing")
|
||||
<<example>>-<$text text=<<foo>>/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>ONE-nothing|ONE-blah~TWO-nothing|TWO-blah</p>
|
@ -1,31 +0,0 @@
|
||||
title: Globals/Refresh
|
||||
description: Refreshing global procedures in shadow variables
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
title: Output
|
||||
|
||||
\whitespace trim
|
||||
|
||||
<<this-is-one>>
|
||||
|
|
||||
<<this-is-one blah>>
|
||||
+
|
||||
title: $:/global/this-is-one
|
||||
|
||||
\whitespace trim
|
||||
|
||||
\procedure example()
|
||||
ONE
|
||||
\end
|
||||
|
||||
\parameters (foo:"nothing")
|
||||
<<example>>-<$text text=<<foo>>/>
|
||||
+
|
||||
title: Actions
|
||||
|
||||
<$action-setfield $tiddler="$:/global/this-is-one" $value="Jackdaw"/>
|
||||
+
|
||||
title: ExpectedResult
|
||||
|
||||
<p>Jackdaw</p><p>|Jackdaw</p>
|
@ -1,65 +0,0 @@
|
||||
title: Global Definitions
|
||||
created: 20220909111836951
|
||||
modified: 20220909111836951
|
||||
tags: Concepts Reference Variables
|
||||
|
||||
!! Introduction
|
||||
|
||||
<<.from-version "5.3.0">> Globals are [[variables|Variables]] that are available everywhere, without needing a [[<$set>|SetWidget]], [[<$vars>|SetWidget]] or [[<$let>|SetWidget]] widget.
|
||||
|
||||
!! Defining Globals
|
||||
|
||||
Previously, definitions of procedures, widgets, functions and macros were made available globally by tagging them with `$:/tags/Macro`. While this mechanism is still supported, it suffers from several disadvantages and so is not recommended for new applications. The new way to define global procedures, widgets, functions and macros is to place them in tiddlers titled with the name of the global prefixed with `$:/global/`.
|
||||
|
||||
For example, the global variable `foo` would be defined in a tiddler called `$:/global/foo`. Accessing the variable `<<foo>>` then acts as a shortcut for accessing the underlying global variable tiddler.
|
||||
|
||||
!! Special Fields
|
||||
|
||||
The following special fields are used to define the behaviour of the global:
|
||||
|
||||
* `_parameters` defines the parameters expected by procedures, widgets and functions
|
||||
* `_is_procedure`, `_is_widget`, `_is_function`, `_is_macro`: any one of these fields may be set to `yes` to indicate the type of the definition
|
||||
|
||||
<<.note """The `_parameters` field is only strictly necessary for functions and macros. Procedures and widgets can instead choose to use the <<.wlink ParametersWidget>> widget (or a pragma) within the body of the definition""">>
|
||||
|
||||
!! Viewing Globals
|
||||
|
||||
The current global definitions are listed in the sidebar in the "More" -> "Globals" tab.
|
||||
|
||||
By default, global definition tiddlers are displayed with a custom template that makes it easier to see the full definition.
|
||||
|
||||
!! Local Variables within Globals
|
||||
|
||||
Note that global definitions can include local variables that are defined before the body of the global. These local variables will not be visible externally.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
title: $:/globals/foo
|
||||
_is_procedure: yes
|
||||
_parameters: (param1:"value",param2:"value")
|
||||
|
||||
\procedure renderTitle(title)
|
||||
<div class="mytitle"><$text text=<<title>>/></div>
|
||||
\end
|
||||
|
||||
\function myfn(a)
|
||||
[[a]getvariable[]addprefix[!]]
|
||||
\end
|
||||
|
||||
<$list filter=<<param1>>>
|
||||
|
||||
<<renderTitle "first">>: <$text text=<<param2>>/>
|
||||
|
||||
<<renderTitle "second">>: <$text text=<<myfn param2>>/>
|
||||
|
||||
</$list>
|
||||
```
|
||||
|
||||
It is possible to allow the caller to override these local definitions by using the new syntax for conditional definitions. For example, here we only define the function `myfn` if the variable `myfn` is not already defined:
|
||||
|
||||
```
|
||||
\?function myfn(a)
|
||||
[[a]getvariable[]addprefix[!]]
|
||||
\end
|
||||
```
|
@ -10,8 +10,6 @@ A new variable is defined using a <<.wlink SetWidget>> widget, and is then avail
|
||||
|
||||
The <<.wlink ListWidget>> widget also sets a particular variable (<<.var currentTiddler>> by default) to each listed title in turn.
|
||||
|
||||
Variables can also be defined as [[Global Definitions]].
|
||||
|
||||
For an overview of how to use variables, see [[Variables in WikiText]].
|
||||
|
||||
Despite the term <<.word variable>>, each snippet is a constant string. The apparent variability is actually the result of the presence of multiple variables with the same name in different parts of the widget tree.
|
||||
|
@ -12,7 +12,6 @@ There are shortcuts for common scenarios that can often make it unnecessary to u
|
||||
* the [[Pragma: \parameters]]
|
||||
* the [[Pragma: \procedure]] for declaring procedure
|
||||
* the [[Pragma: \widget]] for declaring custom widgets
|
||||
* the `_parameters` field of tiddlers containing [[Global Definitions]]
|
||||
|
||||
The <<.wlink ParametersWidget>> widget must be used directly in the following situations:
|
||||
|
||||
|
@ -35,13 +35,9 @@ Macros are implemented as a special type of [[variable|Variables]] and so intern
|
||||
|
||||
The [[Pragma: \import]] or <<.wlink ImportVariablesWidget>> widget can be used to copy macro definitions from another tiddler.
|
||||
|
||||
!! Global Macro Definitions
|
||||
|
||||
Macros can be made available globally by placing them in a tiddler titled with the name of the global prefixed with `$:/global/`. See [[Global Definitions]] for details.
|
||||
|
||||
!! `$:/tags/Macro` Tag
|
||||
|
||||
For backwards compatibility, global macros can also be defined using the [[SystemTag: $:/tags/Macro]]. The new [[Global Definitions]] mechanism is [[preferred|Macro Pitfalls]] for new applications.
|
||||
Global macros can be defined using the [[SystemTag: $:/tags/Macro]].
|
||||
|
||||
The tag [[SystemTag: $:/tags/Macro/View]] is used to define macros that should only be available within the main view template and the preview panel.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user