Need help to create a javascript library & invoke this.wiki.xxxx() from it

22 views
Skip to first unread message

vpl.p...@gmail.com

unread,
Oct 27, 2021, 4:14:54 AM10/27/21
to TiddlyWikiDev
Hi guys,

I need a bit of help to understand how to access  getTiddler  method from a javascript library

When I develop macro (module-type) I use this.wiki. filterTiddlers  (...) methods and all works fine when I invoke this macro from a tiddler script

But I would like to develop a javascript library that is intended to be used by different macros. This library will need to access a Data Tiddler (as a DB "backend")

So I created a javascript code and set its module-type to library
The code is the following

(function(){
class Hero {
    constructor(name, level) {
var stats_tiddler_title = "Stats_report"; // a backend tiddler that contains the stats reports (as field value)
var stats_tiddler_filter = "[["+stats_tiddler_title+"]]";
var stats_tiddlers = this.wiki.filterTiddlers(stats_tiddler_filter);
        this.name = name;
        this.level = level;
console.log("   Class created. Value:"+this.level);
    }
getName() {
console.log("   getName !!!!!. Name:"+this.name);
}
}
exports.Hero = Hero;

})();

From my macro javascript I tried to call this library 

var Hero = require('$:/plugins/vpl/vpl_test_class.js').Hero;
const hero1 = new Hero('Varg', 1);

But I get the error
Uncaught TypeError: Cannot read properties of undefined (reading 'filterTiddlers')

I'm blocked .... Can someone help & guide me on the proper way to do that ?

Thanks very much for your help

Regards

Joshua Fontany

unread,
Apr 27, 2022, 11:16:31 AM4/27/22
to TiddlyWikiDev
Much more activity at https://talk.tiddlywiki.org/. Try over there. :)
Reply all
Reply to author
Forward
0 new messages