Ticket #587 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

refactor filterTiddlers() to support plugin-defined enhancements

Reported by: EricShulman Owned by: JeremyRuston
Priority: minor Milestone: 2.4
Component: core Version:
Severity: medium Keywords:
Cc:

Description

In order to permit use-case specific plugin-defined tag filtering logic without having to replace the entire TiddlyWiki.prototype.filterTiddlers() function definition, please refactor the following code in the TiddlyWiki.prototype.filterTiddlers() function:

switch(match[2]) {
	case "tag":
		this.forEachTiddler(function(title,tiddler) {
			if(tiddler.isTagged(match[3]))
				results.pushUnique(tiddler);
		});
		break;

by moving it to a separate function, like this:

TiddlyWiki.prototype.matchTags(tagexpression) {
	var results=[];
	this.forEachTiddler(function(title,tiddler) {
		if(tiddler.isTagged(tagexpression))
			results.push(tiddler);
	});
	return results;
}

then, the filterTiddlers() code would be simplified to:

switch(match[2]) {
        case "tag":
                var matched=this.matchTags(match[3]);
		for (var m=0; m<matched.length; m++)
			results.pushUnique(matched[m]);
		break;

for additional discussion, see  http://groups.google.com/group/TiddlyWikiDev/browse_frm/thread/611a7f2b5ff29dfc

Change History

  Changed 4 years ago by MartinBudden

  • owner changed from JeremyRuston to MartinBudden
  • priority changed from undefined to minor
  • status changed from new to assigned
  • severity changed from undefined to medium
  • milestone set to 2.4

  Changed 4 years ago by MartinBudden

  • owner MartinBudden deleted
  • status changed from assigned to new

  Changed 4 years ago by MartinBudden

  • owner set to JeremyRuston

in reply to: ↑ description   Changed 4 years ago by EricShulman

after discussion with Jeremy and Martin, the best refactoring would be to use the existing core function, store.getTaggedTiddlers() instead of creating a new store.matchTags() function. Thus, the only change needed to the core is to use the following in filterTiddlers()

switch(match[2]) {
        case "tag":
                var matched=this.getTaggedTiddlers(match[3]);
		for (var m=0; m<matched.length; m++)
			results.pushUnique(matched[m]);
		break;

Note: In anticipation of the above change, I have updated TiddlyTools' MatchTagsPlugin? to hijack getTaggedTiddlers() instead of definining store.matchTags().

  Changed 4 years ago by JeremyRuston

  • status changed from new to closed
  • resolution set to fixed

Fixed in changeset:4614

Note: See TracTickets for help on using tickets.