1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2025-07-30 15:52:51 +00:00

Replace accumulate-palette-entries with new changecount filter

Much more direct and efficient
This commit is contained in:
Jeremy Ruston 2025-01-27 11:09:18 +00:00
parent 317e1245c8
commit 0c8aad49f9
4 changed files with 27 additions and 86 deletions

View File

@ -1,45 +0,0 @@
/*\
title: $:/core/modules/filters/accumulate-palette-entries.js
type: application/javascript
module-type: filteroperator
A temporary filter operator for accumulating palette entries into a unique signature that can be used for cache invalidation. The signature is opaque, and should not be used for anything other than cache invalidation.
Hopefully we can figure out a way to do this within TW's filter language; it might be a good way to stretch the capabilities of the language.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports["accumulate-palette-entries"] = function(source,operator,options) {
var paletteTitle = operator.operand,
wiki = options.wiki,
visitedPalettes = [];
// Recursive function to accumulate the palette entries from a single palette
function accumulatePaletteEntries(title) {
var tiddler = wiki.getTiddler(title),
results = [];
if(visitedPalettes.indexOf(title) === -1 && tiddler) {
visitedPalettes.push(title);
if(tiddler.fields["palette-import"]) {
Array.prototype.push.apply(results,accumulatePaletteEntries(tiddler.fields["palette-import"]));
}
var json = wiki.getTiddlerData(tiddler,{});
$tw.utils.each(Object.keys(json),function(key) {
results.push(key + ":" + json[key]);
});
}
return results;
}
var results = JSON.stringify(accumulatePaletteEntries(paletteTitle));
results += wiki.getTiddlerAsJson(paletteTitle);
return [results];
};
})();

View File

@ -0,0 +1,26 @@
/*\
title: $:/core/modules/filters/changecount.js
type: application/javascript
module-type: filteroperator
Filter operator for retrieving the changecount for each title in the list.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Export our filter function
*/
exports.changecount = function(source,operator,options) {
var results = [];
source(function(tiddler,title) {
results.push(options.wiki.getChangeCount(title) + "");
});
return results;
};
})();

View File

@ -1,6 +1,6 @@
title: $:/core/background-actions/AutoCompilePalette
tags: $:/tags/BackgroundAction $:/tags/StartupAction
track-filter: [accumulate-palette-entries[$:/palette]]
track-filter: [[$:/palette]] +[changecount[]]
\import [subfilter{$:/core/config/GlobalImportFilter}]
<<actions-recompile-current-palette>>

View File

@ -1,40 +0,0 @@
title: Operators/Palettes/Accumulate
description: Recursively accumulate palette definitions
type: text/vnd.tiddlywiki-multiple
tags: [[$:/tags/wiki-test-spec]]
title: Output
\import [subfilter{$:/core/config/GlobalImportFilter}]
\parsermode inline
<$text text={{{ [accumulate-palette-entries[MyPalette]] }}}/>
+
title: $:/palette
MyPalette
+
title: MyPalette
name: My Palette
description: My custom palette
tags: $:/tags/Palette
type: application/x-tiddler-dictionary
palette-import: MyOtherPalette
color-scheme: light
page-background: <<colour custom>>
custom: #f4e4d4
+
title: MyOtherPalette
name: My Other Palette
description: My other custom palette
tags: $:/tags/Palette
type: application/x-tiddler-dictionary
color-scheme: light
page-background: #d4e4f4
background: red
+
title: ExpectedResult
["page-background:#d4e4f4","background:red","page-background:&lt;&lt;colour custom&gt;&gt;","custom:#f4e4d4"]{"title":"MyPalette","name":"My Palette","description":"My custom palette","tags":"$:/tags/Palette","type":"application/x-tiddler-dictionary","palette-import":"MyOtherPalette","color-scheme":"light","text":"page-background: &lt;&lt;colour custom&gt;&gt;\ncustom: #f4e4d4"}