exports.startup = function() { exports.platforms = ["node"]; $tw.wiki.addEventListener("change",function(changes) { if($tw.utils.hop(changes,"updatebookmarks")) { runPinboardPlugin(); } });
runPinboardPlugin(); } On Wednesday, March 22, 2017 at 4:07:29 PM UTC+1, BJ wrote: > > maybe you can add an event listener: > > this.wiki.addEventListener("change",function(changes) { > if($tw.utils.hop(changes,"updatebookmarks")) { > runmyupdatebookmarks() > } > }); > > > > On Wednesday, March 22, 2017 at 12:04:54 PM UTC+1, BJ wrote: >> >> ok, what I meant is, if you have a tiddler call "updatebookmarks", and >> when a button is clicked this tiddler is updated, this update is sync'd >> with the nodejs instance. In the nodejs instance there need to be a hook >> that listens for updates to the tiddler "updatebookmarks", and when updated >> runs a function. >> >> You cannot use chrome dev tools as the code should not run in the >> browser, only nodejs. >> >> You can see how to run code only in nodejs by looking at the command >> strartup - >> >> >> exports.platforms = ["node"]; >> >> HOWEVER, it seems the hooks are not called in the nodejs instance, so you >> cannot do it like this - ?? >> >> You could request a hook be added to the core that will run in the nodejs >> instance. >> >> >> Hi BJ, >>> >>> Thanks very much for the help. Can you possibly explain this in more >>> depth? I've tried to follow your instructions, and also read up on hooks >>> from twdocs and looked at the code in `boot.js`, but I still don't fully >>> understand how a hook function is called. >>> >>> The following is my progress so far. >>> >>> I wasn't sure where exactly the addHook function belonged or what the >>> name was supposed to be. My best guess was that they belonged in the plugin >>> startup module itself. So I took the main function in >>> `create-pinboard-tiddlers.js` and moved it to a new one. >>> I tested two different formats of `addhook()` based on what I read: >>> >>> exports.startup = function() { >>> >>> // $tw.hooks.addHook("reset-pinboard-tiddlers",function() { >>> // runPinboardPlugin(); >>> // return; >>> // }); >>> >>> $tw.hooks.addHook("th-saving-tiddler",function(tiddler) { >>> runPinboardPlugin(); >>> return tiddler; >>> }); >>> >>> runPinboardPlugin(); >>> } >>> >>> As you can see I commented out the first one, but I did try both. In >>> both cases, the plugin worked normally on startup. In neither case was I >>> able to successfully `invokeHook()`. I tried Chrome dev-tools snippets: >>> >>> `$tw.hooks.invokeHook("th-saving-tiddler");` >>> >>> & >>> >>> ``$tw.hooks.invokeHook("reset-pinboard-tiddlers");` >>> >>> depending on which one I was trying, but neither did anything. I also >>> tried saving tiddlers for the "th-saving-tiddler" test but this did >>> nothing either. >>> >>> What am I doing wrong? >>> >>> All the best, >>> Matt >>> >> -- 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+unsubscr...@googlegroups.com. To post to this group, send email to tiddlywiki@googlegroups.com. Visit this group at https://groups.google.com/group/tiddlywiki. To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/0340bafb-0178-4e6d-8dcd-7992dd3441d5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.