/*\title: $:/macros/danielo515/get_unique_values.jstype: application/javascriptmodule-type: macro
This macro returns the list of values that exists only on tiddler A.It expects a list of \n separated values on each tiddler.
\*/(function(){
/*jslint node: true, browser: true */ /*global $tw: false */ "use strict";
/* Information about this macro */
exports.name = "getunique";
exports.params = [ {name: "A"}, {name: "B"} ];
/* Run the macro */ exports.run = function(A,B){ var a=($tw.wiki.getTiddlerText(A) ||""), b=($tw.wiki.getTiddlerText(B) ||""), a_values= a.split('\n'), b_values= b.split('\n'), result = []; a_values.forEach(function(a_value){ if(b_values.indexOf(a_value) === -1) result.push(a_value); }); console.log(result.length," unique values remains"); return "```\n" + result.join('\n') + "\n```"; };
})();--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/dc66884b-c46a-4664-bbe3-0ae8dd3fcc4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
\define unique-a() <<getunique "$:/temp/col-a" "$:/temp/col-b">>\define unique-b() <<getunique "$:/temp/col-b" "$:/temp/col-a">>
<$button>Get unique values on A<$action-setfield $tiddler="$:/status/compare-result" text=<<unique-a>>/><$action-navigate $to="$:/status/compare-result" $scroll="true"/></$button><$button>Get unique values on B<$action-setfield $tiddler="$:/status/compare-result" text=<<unique-b>>/><$action-navigate $to="$:/status/compare-result"/></$button>
<$edit-text tiddler="$:/temp/col-a" size=20 default="" minHeight="80px" placeholder="A - column" autoHeight="no"/><$edit-text tiddler="$:/temp/col-b" size=20 default="" minHeight="50px" placeholder="B - column" autoHeight="no"/>I want to build a batch text processing tool on top of TW5. The first tool I have "implemented" is a column compare one. It is a macro that gets the text on two tiddlers and give you the unique values in one side of the comparison. The problem with using a macro is that it is evaluated on every keystroke, navigation event and so on. This is extremely slow and unefficent. Which kind of element should I use to make this more usable? A widget? if so, how? I would like to process just once and then show the result.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/dc66884b-c46a-4664-bbe3-0ae8dd3fcc4f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
A reasonable approach might be to have a daemon (ie startup module) that performs the calculations in response to a message, and deposits the results in a tiddler.
Sure I remember! Just ignore stuff you already know ;) Just wanted to
add my thoughts to Jeremy's comment.
Or your creative mind comes up with a better idea. As it is often the
case, many brilieant solutions are not discovered at first sight :)
Good night
The problem? The same as allways, on every keystroke the macro is re-evaluated. I did not expected this because it is part of a widget parameter (the action widget) and I though it will be only evaluated when the widget "requires" it. Maybe an option to do this would be useful, to do not evaluate macros until they are required as parameter when the widget is executed.
--
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To post to this group, send email to tiddl...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/320a75dc-9832-41a8-ae2d-3d6b10633dd5%40googlegroups.com.
- at which TW version do we started to use event.paramObject notation for messages? I think in 5.1.4, but I'm not sure
- It is the same as the old param holding the object, right? I see this much cleaner.
- $tw.wiki.setText function is useful, but the way you want to call it could be odd. For example, you want to change just the text field, making use of the default values that this function tooks you have to $tw.wiki.setText("title",null,null,"new value"). Since the function is called setText I would expect it to change it only the text field. But instead it is able to change any field and any index of the given tiddler. Since this is very powerful I think it should be spliced into two functions. setText (only for text field) and setField (for any field)
Since I moved the macro call to a different tiddler it is only updated when I change that tiddler content. Because I do this from a button it looks like it is only reacting to "button press" events. If I edit the content of one of the "temp" tiddlers from an edit-widget it is not being re-evaluated on every key press.
Since this is exactly what I wanted I expected the opposite.