mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-04-20 09:43:13 +00:00
Introduce an improved but temporary cache invalidation method for palettes
This commit is contained in:
parent
d2bbc56c78
commit
317e1245c8
45
core/modules/filters/accumulate-palette-entries.js
Normal file
45
core/modules/filters/accumulate-palette-entries.js
Normal file
@ -0,0 +1,45 @@
|
||||
/*\
|
||||
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];
|
||||
};
|
||||
|
||||
})();
|
@ -1,6 +1,6 @@
|
||||
title: $:/core/background-actions/AutoCompilePalette
|
||||
tags: $:/tags/BackgroundAction $:/tags/StartupAction
|
||||
track-filter: [{$:/palette}indexes[]] :map[{$:/palette}getindex<currentTiddler>]
|
||||
track-filter: [accumulate-palette-entries[$:/palette]]
|
||||
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
<<actions-recompile-current-palette>>
|
||||
|
40
editions/test/tiddlers/tests/data/palettes/Accumulate.tid
Normal file
40
editions/test/tiddlers/tests/data/palettes/Accumulate.tid
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
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:<<colour custom>>","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: <<colour custom>>\ncustom: #f4e4d4"}
|
@ -1,6 +1,6 @@
|
||||
|
||||
title: Operators/Palettes/BasicLookup
|
||||
description: Compute the
|
||||
description: Basic palette lookups
|
||||
type: text/vnd.tiddlywiki-multiple
|
||||
tags: [[$:/tags/wiki-test-spec]]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user