TW5 subscribe to save tiddler event on root widget

157 views
Skip to first unread message

Danielo Rodríguez

unread,
Sep 4, 2015, 11:42:27 AM9/4/15
to TiddlyWikiDev
Hello.

I want to know if it is possible to subscribe to tiddler saves. I don't care about all kind of changes, just saves. I tried adding an event listener on the root widget to the message tm-save-tiddler, but it does not work, the handler is never called. Does the events pops up or do they stop at the first subscriber?

Many thanks

Danielo Rodríguez

unread,
Sep 5, 2015, 11:09:11 AM9/5/15
to TiddlyWikiDev
Is this even possible?
Should I try a different approach? I am now using a subscription to change event, but it si way more complicated than just using the tm-tiddler-save.

Regards

BJ

unread,
Sep 5, 2015, 3:16:24 PM9/5/15
to TiddlyWikiDev

tm-save-tiddler is consumed by the navigator widget so never reaches the root widget. You will have to add a listener for change events, then check the change list to remove ones that have 'deleted'  values.

cheers

BJ

Danielo Rodríguez

unread,
Sep 7, 2015, 8:55:26 AM9/7/15
to TiddlyWikiDev
Hello BJ,


El sábado, 5 de septiembre de 2015, 21:16:24 (UTC+2), BJ escribió:

tm-save-tiddler is consumed by the navigator widget so never reaches the root widget. You will have to add a listener for change events, then check the change list to remove ones that have 'deleted'  values.

That is more or less what I did:


Thank you for confirming that there is not possible to allow tm-save-tiddler to pop up. 

Jeremy Ruston

unread,
Sep 7, 2015, 10:19:38 AM9/7/15
to TiddlyWikiDev
This looks like a situation where it would be useful to use the hook mechanism:


The idea would be for the navigator widget to invoke a new hook "th-saving-tiddler" that gave plugins a chance to operate on a tiddler before it is saved. I'll add it to my list, but please put your hand up if anyone is willing to make a pull request.

Best wishes

Jeremy.

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywikidev/8b9bcb26-57dd-40d8-80e0-a48e5d6065d1%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Jeremy Ruston
mailto:jeremy...@gmail.com

PMario

unread,
Sep 8, 2015, 8:54:49 AM9/8/15
to tiddly...@googlegroups.com, jeremy...@gmail.com
On Monday, September 7, 2015 at 4:19:38 PM UTC+2, Jeremy Ruston wrote:
This looks like a situation where it would be useful to use the hook mechanism:


The idea would be for the navigator widget to invoke a new hook "th-saving-tiddler" that gave plugins a chance to operate on a tiddler before it is saved. I'll add it to my list, but please put your hand up if anyone is willing to make a pull request.

imo plugins can't change the tiddler variable since its components are immutable. So I think there is no need for hooks. The tiddler has to be written to the store and it needs to be overwritten anyway. eg: Which hook will win, if 2 plugins need to work with the same hook? Also: What if the navigator widget is not involved?

IMO we should make the "tm-" and action widget mechanism more generic and usable for plugin authors. IMO the "messaging" API is not very consistent atm.

-mario

Jeremy Ruston

unread,
Sep 8, 2015, 11:21:25 AM9/8/15
to PMario, TiddlyWikiDev
Hi Mario

I've gone ahead with an implementation of the th-saving-tiddler hook:


imo plugins can't change the tiddler variable since its components are immutable.

Tiddler objects are immutable, meaning that they can't be modified once created. But the hook can just return a new tiddler; see the docs in the commit.
 
So I think there is no need for hooks. The tiddler has to be written to the store and it needs to be overwritten anyway. eg: Which hook will win, if 2 plugins need to work with the same hook?

Hooks with the same name are invoked in the order that they were registered.

 
Also: What if the navigator widget is not involved?

The navigator widget is always involved in saving tiddlers via the "confirm" toolbar button. This hook isn't invoked for tiddlers saved through other means (eg state tiddlers).

IMO we should make the "tm-" and action widget mechanism more generic and usable for plugin authors. IMO the API is not very consistent atm.

Do you have any specific thoughts or ideas? The message and widget mechanisms are entirely generic, and I don't think there are any obstacles to their use by plugin authors.

Best wishes

Jeremy
 

-mario

Danielo Rodríguez

unread,
Sep 9, 2015, 5:44:34 AM9/9/15
to TiddlyWikiDev
Hello Jeremy,

That was exactly what I was looking for.
Currently I'm using a startup module to subscribe to changes and operator over the changed tiddlers. Since the event listener listen for changes and change the tiddlers itself it's easy to fall to an infinite loop. I fixed it with a small cache tho control the latest modified tiddlers.
I was worried about performance, because ANY change in ANY way to ANY tiddler would trigger my listener, which means 99% of unnecessary function executions. Do you think this hook would improve performance.


Mario, I do not see the problem in this particular hook. The problem I has is exactly what you are complaining about: I only want to subscribe to manual changes done by the user, and not other changes made by any action widgets or state tiddlers.
If you want to listen to any change, then you can listen for "change" on the root widget. Why does that do not meet your needs?

Regards.

Jeremy Ruston

unread,
Sep 9, 2015, 12:20:51 PM9/9/15
to TiddlyWikiDev
Hi Danielo

That was exactly what I was looking for.
Currently I'm using a startup module to subscribe to changes and operator over the changed tiddlers. Since the event listener listen for changes and change the tiddlers itself it's easy to fall to an infinite loop. I fixed it with a small cache tho control the latest modified tiddlers.
I was worried about performance, because ANY change in ANY way to ANY tiddler would trigger my listener, which means 99% of unnecessary function executions. Do you think this hook would improve performance.

Yes, it should. The hook is only invoked for tiddlers that are saved with the "confirm" toolbar button.

Best wishes

Jeremy.

 

Regards.

--
You received this message because you are subscribed to the Google Groups "TiddlyWikiDev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywikide...@googlegroups.com.
To post to this group, send email to tiddly...@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywikidev.

For more options, visit https://groups.google.com/d/optout.

Eric Drechsel

unread,
Jan 14, 2016, 12:52:15 PM1/14/16
to TiddlyWikiDev, jeremy...@gmail.com
I'm trying to do something on save as well, but the hook doesn't provide enough context

https://github.com/Jermolene/TiddlyWiki5/issues/196#issuecomment-171691438

IMO there should be a hook in the store for this. It seems like kind of a glaring omission.
Reply all
Reply to author
Forward
0 new messages