From cb3741c8ee795d5c7b3c2fbc5299c841c269a4cc Mon Sep 17 00:00:00 2001 From: Jeremy Ruston Date: Tue, 16 Oct 2012 18:50:32 +0100 Subject: [PATCH] Refactored list macro Now does selective refreshing, improving performance in several areas. (Classic TW always refreshed lists in their entirety). A bit more to do, but the plan is that this can replace the story macro, too --- core/modules/macros/list.js | 188 +++++++++++++++++++++++++----------- 1 file changed, 134 insertions(+), 54 deletions(-) diff --git a/core/modules/macros/list.js b/core/modules/macros/list.js index df26da6ff..e985d63ce 100644 --- a/core/modules/macros/list.js +++ b/core/modules/macros/list.js @@ -12,73 +12,153 @@ List macro /*global $tw: false */ "use strict"; -var handlers = { - all: function(wiki) { - return wiki.getTiddlers("title","excludeLists"); - }, - missing: function(wiki) { - return wiki.getMissingTitles(); - }, - orphans: function(wiki) { - return wiki.getOrphanTitles(); - }, - shadowed: function(wiki) { - return wiki.getShadowTitles(); - }, - touched: function(wiki) { - // Server syncing isn't implemented yet - return []; - }, - filter: function(wiki) { - // Filters aren't implemented yet - return []; - } -}; - exports.info = { name: "list", dependentAll: true, // Tiddlers containing <> macro are dependent on every tiddler params: { - type: {byName: "default", type: "text"}, + type: {byPos: 0, type: "text"}, + filter: {byName: true, type: "filter"}, template: {byName: true, type: "tiddler"}, + templateText: {byName: true, type: "text"}, + editTemplate: {byName: true, type: "tiddler"}, + editTemplateText: {byName: true, type: "text"}, emptyMessage: {byName: true, type: "text"} } }; exports.executeMacro = function() { - var templateType = "text/x-tiddlywiki", - templateText = "<>", - template = this.params.template ? this.wiki.getTiddler(this.params.template) : null, - children = [], - t, - parents = this.parents, - attributes = {}; - if(template) { - parents = parents.slice(0); - parents.push(template.title); - templateType = template.type; - templateText = template.text; - } - var handler = handlers[this.params.type]; - handler = handler || handlers.all; - var tiddlers = handler(this.wiki,this.tiddlerTitle); + // Get the list of tiddlers object + this.getTiddlerList(); + // Create the list frame element + var attributes = {"class": ["tw-list-frame"]}; if(this.classes) { - attributes["class"] = this.classes.slice(0); + $tw.utils.pushTop(attributes["class"],this.classes); } - if(tiddlers.length === 0) { - return $tw.Tree.Text(this.params.emptyMessage || ""); - } else { - var templateTree = this.wiki.parseText(templateType,templateText).tree; - for(t=0; t t) { + for(var n=index-1; n>=t; n--) { + this.removelistElement(n); + } + } + // Refresh the node we're reusing + this.listFrame.children[t].refreshInDom(changes); + } + } + // Remove any left over elements + if(this.listFrame.children.length > this.list.length) { + for(t=this.listFrame.children.length-1; t>=this.list.length; t--) { + this.removeStoryElement(t); } - return $tw.Tree.Element("ul",attributes,children); } };