-
Hello, I've a "JavaScript Macro" that do a heavy calculation (inside and outside TW5) and the final calculation result is at least 3 level "deep" JSON object. For Ex., I'll pass a single parameter (TopicID) and the return Object in the form of ( --hasMulti--> Books, Course, Tutorials, ... --eachHasMulti--> Authors, Websites, YouTube Channels, .... --eachHasMulti--> Attributes). Now, my question is: I'm thinking to return this information to WikiText as a single value string variable (after converting the JSON to a string), is this a good idea? or there are other best practices? Or, Do I need to break that Macro to a several Macros? each will "repeat" the "exact" same "heavy" calculations BUT return a simple "List"? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
At the moment there is no easy way to access multi-level JSON objects in wikitext. If you need to work with filters afterwards you have to reduce your structure to a "single level" JSON which basically is a The wikitext term is "data tiddler". If it's possible to use data-tiddlers it would be the easiest way to work with filters, since you can work with indexes. So the best way would be to create a structure, that uses tiddler-fields, where the field names are the If you could be a bit more specific about "heavy calculations" it would be easier to see, what's probably needed, of if there is a structure that would more naturally fit to the TW filter syntax. |
Beta Was this translation helpful? Give feedback.
-
Yes, that's correct. ... Macros don't export a |
Beta Was this translation helpful? Give feedback.
-
no
There is a JSON-mangler plugin, which pretty much does what you want. .. BUT it's broken since 5.2.x ... |
Beta Was this translation helpful? Give feedback.
-
It's actually not that hard to create widgets. Have a look at https://github.com/Jermolene/TiddlyWiki5/blob/master/core/modules/widgets/action-createtiddler.js which is probably very close to what you need to write into a new tiddler. action-widgets usually need to be triggered by the |
Beta Was this translation helpful? Give feedback.
-
Hi @msameen99 one approach that we use in the core is to use a custom widget message to trigger the JS function, and have it return the data as a structure of interlinked tiddlers. Very roughly, you'd have a startup module with code like this: exports.startup = function() {
// Listen for widget messages to control loading the plugin library
$tw.rootWidget.addEventListener("tm-my-message",function(event) {
var paramObject = event.paramObject || {};
var tiddlers = myMagicFunction(paramObject.firstParameter,paramObject.secondParameter);
$tw.wiki.addTiddlers(tiddlers);
}
}; Depending on the precise scenario, it may make sense to have one of the parameters specifying the root tiddler tiddler title for the results. |
Beta Was this translation helpful? Give feedback.
no
There is a JSON-mangler plugin, which pretty much does what you want. .. BUT it's broken since 5.2.x ...