1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 10:07:19 +00:00

Revert "Transclude widget: refresh selectively when needed (#5736)"

This reverts commit 2e695801b1.
This commit is contained in:
jeremy@jermolene.com 2021-06-02 19:14:05 +01:00
parent 2e695801b1
commit 4f9dd50382
3 changed files with 21 additions and 167 deletions

View File

@ -60,8 +60,6 @@ TranscludeWidget.prototype.execute = function() {
subTiddler: this.transcludeSubTiddler subTiddler: this.transcludeSubTiddler
}), }),
parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children; parseTreeNodes = parser ? parser.tree : this.parseTreeNode.children;
this.sourceText = parser ? parser.source : null;
this.parserType = parser? parser.type : null;
// Set context variables for recursion detection // Set context variables for recursion detection
var recursionMarker = this.makeRecursionMarker(); var recursionMarker = this.makeRecursionMarker();
if(this.recursionMarker === "yes") { if(this.recursionMarker === "yes") {
@ -100,17 +98,12 @@ TranscludeWidget.prototype.makeRecursionMarker = function() {
return output.join(""); return output.join("");
}; };
TranscludeWidget.prototype.parserNeedsRefresh = function() {
var parserInfo = this.wiki.getTextReferenceParserInfo(this.transcludeTitle,this.transcludeField,this.transcludeIndex,{subTiddler:this.transcludeSubTiddler});
return (this.sourceText === undefined || parserInfo.sourceText !== this.sourceText || parserInfo.parserType !== this.parserType)
};
/* /*
Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering
*/ */
TranscludeWidget.prototype.refresh = function(changedTiddlers) { TranscludeWidget.prototype.refresh = function(changedTiddlers) {
var changedAttributes = this.computeAttributes(); var changedAttributes = this.computeAttributes();
if(($tw.utils.count(changedAttributes) > 0) || (changedTiddlers[this.transcludeTitle] && this.parserNeedsRefresh())) { if(changedAttributes.tiddler || changedAttributes.field || changedAttributes.index || changedTiddlers[this.transcludeTitle]) {
this.refreshSelf(); this.refreshSelf();
return true; return true;
} else { } else {

View File

@ -937,57 +937,41 @@ exports.parseTiddler = function(title,options) {
}; };
exports.parseTextReference = function(title,field,index,options) { exports.parseTextReference = function(title,field,index,options) {
var tiddler, var tiddler,text;
text, if(options.subTiddler) {
parserInfo; tiddler = this.getSubTiddler(title,options.subTiddler);
if(!options.subTiddler) { } else {
tiddler = this.getTiddler(title); tiddler = this.getTiddler(title);
if(field === "text" || (!field && !index)) { if(field === "text" || (!field && !index)) {
this.getTiddlerText(title); // Force the tiddler to be lazily loaded this.getTiddlerText(title); // Force the tiddler to be lazily loaded
return this.parseTiddler(title,options); return this.parseTiddler(title,options);
} }
}
parserInfo = this.getTextReferenceParserInfo(title,field,index,options);
if(parserInfo.sourceText !== null) {
return this.parseText(parserInfo.parserType,parserInfo.sourceText,options);
} else {
return null;
}
};
exports.getTextReferenceParserInfo = function(title,field,index,options) {
var tiddler,
parserInfo = {
sourceText : null,
parserType : "text/vnd.tiddlywiki"
};
if(options.subTiddler) {
tiddler = this.getSubTiddler(title,options.subTiddler);
} else {
tiddler = this.getTiddler(title);
} }
if(field === "text" || (!field && !index)) { if(field === "text" || (!field && !index)) {
if(tiddler && tiddler.fields) { if(tiddler && tiddler.fields) {
parserInfo.sourceText = tiddler.fields.text || ""; return this.parseText(tiddler.fields.type,tiddler.fields.text,options);
if(tiddler.fields.type) { } else {
parserInfo.parserType = tiddler.fields.type; return null;
}
} }
} else if(field) { } else if(field) {
if(field === "title") { if(field === "title") {
parserInfo.sourceText = title; text = title;
} else if(tiddler && tiddler.fields) { } else {
parserInfo.sourceText = tiddler.fields[field] ? tiddler.fields[field].toString() : null; if(!tiddler || !tiddler.hasField(field)) {
return null;
}
text = tiddler.fields[field];
} }
return this.parseText("text/vnd.tiddlywiki",text.toString(),options);
} else if(index) { } else if(index) {
this.getTiddlerText(title); // Force the tiddler to be lazily loaded this.getTiddlerText(title); // Force the tiddler to be lazily loaded
parserInfo.sourceText = this.extractTiddlerDataItem(tiddler,index,null); text = this.extractTiddlerDataItem(tiddler,index,undefined);
if(text === undefined) {
return null;
}
return this.parseText("text/vnd.tiddlywiki",text,options);
} }
if(parserInfo.sourceText === null) { };
parserInfo.parserType = null;
}
return parserInfo;
}
/* /*
Make a widget tree for a parse tree Make a widget tree for a parse tree

View File

@ -1,123 +0,0 @@
/*\
title: test-parsetextreference.js
type: application/javascript
tags: [[$:/tags/test-spec]]
Tests for source attribute in parser returned from wiki.parseTextReference
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
describe("Wiki.parseTextReference tests", function() {
// Create a wiki
var wiki = new $tw.Wiki();
wiki.addTiddler({
title: "TiddlerOne",
text: "The quick brown fox in $:/TiddlerTwo",
tags: ["one"],
authors: "Joe Bloggs",
modifier: "JoeBloggs",
modified: "201304152222"});
wiki.addTiddler({
title: "$:/TiddlerTwo",
tags: ["two"],
authors: "[[John Doe]]",
modifier: "John",
modified: "201304152211"});
wiki.addTiddler({
title: "Tiddler Three",
text: '{"oct":31,"nov":30,"dec":31}',
tags: ["one","two"],
type: "application/json",
modifier: "John",
modified: "201304162202"});
wiki.addTiddler({
title: "TiddlerFour",
text: "The quick brown fox in $:/TiddlerTwo",
tags: ["one"],
type: "text/vnd.tiddlywiki",
authors: "Joe Bloggs",
modifier: "JoeBloggs",
modified: "201304152222"});
// Add a plugin containing some shadow tiddlers
var shadowTiddlers = {
tiddlers: {
"$:/TiddlerFive": {
title: "$:/TiddlerFive",
text: "Everything in federation",
tags: ["two"]
},
"TiddlerSix": {
title: "TiddlerSix",
text: "Missing inaction from TiddlerOne",
filter: "[[one]] [[a a]] [subfilter{hasList!!list}]",
tags: []
},
"TiddlerSeventh": {
title: "TiddlerSeventh",
text: "",
list: "TiddlerOne [[Tiddler Three]] [[a fourth tiddler]] MissingTiddler",
tags: ["one"]
},
"Tiddler8": {
title: "Tiddler8",
text: "Tidd",
tags: ["one"],
"test-field": "JoeBloggs"
}
}
};
wiki.addTiddler({
title: "$:/ShadowPlugin",
text: JSON.stringify(shadowTiddlers),
"plugin-type": "plugin",
type: "application/json"});
wiki.addTiddler({
title: "TiddlerNine",
text: "this is plain text",
type: "text/plain"
});
// Define a parsing shortcut for souce attribute of parser returned by wiki.parseTextReference
var parseAndGetSource = function(title,field,index,subTiddler) {
var parser = wiki.parseTextReference(title,field,index,{subTiddler: subTiddler});
return parser ? parser.source : null;
};
it("should parse text references and return correct source attribute", function(){
// Existing tiddler with a text field, no field argument specified
expect(parseAndGetSource("TiddlerOne")).toEqual("The quick brown fox in $:/TiddlerTwo");
// Existing tiddler with a text field, field argument specified as text
expect(parseAndGetSource("TiddlerOne","text")).toEqual("The quick brown fox in $:/TiddlerTwo");
// Existing tiddler with no text field
expect(parseAndGetSource("$:/TiddlerTwo")).toEqual("");
// Existing tiddler, field argument specified as authors
expect(parseAndGetSource("TiddlerOne","authors")).toEqual("Joe Bloggs");
// Non-existent tiddler, no field argument
expect(parseAndGetSource("MissingTiddler")).toEqual(null);
// Non-existent tiddler, field argument
expect(parseAndGetSource("MissingTiddler","missing-field")).toEqual(null);
// Non-existent tiddler, index specified
expect(parseAndGetSource("MissingTiddler",null,"missing-index")).toEqual(null);
// Existing tiddler with non existent field
expect(parseAndGetSource("TiddlerOne","missing-field")).toEqual(null);
// Data tiddler with index specified
expect(parseAndGetSource("Tiddler Three",null,"oct")).toEqual("31");
// Existing tiddler with a text field, type set to vnd.tiddlywiki
expect(parseAndGetSource("TiddlerFour")).toEqual("The quick brown fox in $:/TiddlerTwo");
// Existing subtiddler of a plugin
expect(parseAndGetSource("$:/ShadowPlugin","text",null,"Tiddler8")).toEqual("Tidd");
// Non-existent subtiddler of a plugin
expect(parseAndGetSource("$:/ShadowPlugin","text",null,"MyMissingTiddler")).toEqual(null);
// Plain text tiddler
expect(parseAndGetSource("TiddlerNine")).toEqual(undefined);
});
});
})();