[TW5] Creating a daemon

118 views
Skip to first unread message

Jed Carty

unread,
Jan 10, 2015, 2:27:50 PM1/10/15
to tiddly...@googlegroups.com
As Tobias and Jeremy pointed out to me in this thread https://groups.google.com/forum/#!topic/tiddlywiki/-TCkLodo_AU my link-fields widget (and almost everything in my MathyThing plugin http://inmysocks.tiddlyspot.com/#MathyThing%20Plugin) updates the tiddler store when rendered. I am going to make action-widget versions of each one, but I would like to be able to create something that has the same functionality as the widgets in the MathyThing plugin that doesn't require a user action to update.
Jeremy suggested I create a daemon that runs in the background and updates the outputs when appropriate. I was hoping that someone could point me in the direction of an example of a daemon used in tiddlywiki before I start poking the code trying to learn how without an example. I have found some examples of generic javascript daemons, but I am not familiar enough with javascript to implement them in tiddlywiki without a lot of trial and error, which is what I would like to avoid if possible.

Any suggestions would be greatly appreciated.

Tobias Beer

unread,
Jan 10, 2015, 4:10:36 PM1/10/15
to
I would like to be able to create something that has the same functionality as the widgets in the MathyThing plugin that doesn't require a user action to update.

However, you'd potentialy running into the same problems. Only just slightly less forcefully.
 
Jeremy suggested I create a daemon that runs in the background and updates the outputs when appropriate.

When appropriate is the key here. It shouldn't run on a timer but rather hook into certain events... hooks that may not exist yet.
 
I was hoping that someone could point me in the direction of an example of a daemon used in tiddlywiki before I start poking the code trying to learn how without an example.

You might want to come to terms with how you envision that process to (safely) work... and then ask that specific question with respect to what precisely your daemon is supposed to achieve (and above all WHY).

I have found some examples of generic javascript daemons, but I am not familiar enough with javascript to implement them in tiddlywiki without a lot of trial and error, which is what I would like to avoid if possible.

Understandably... but you might just be headed towards mostly unexplored waters. 

Best wishes, Tobias.

Jeremy Ruston

unread,
Jan 10, 2015, 4:29:40 PM1/10/15
to TiddlyWikiDev
The best example of a daemon in the core is the favicon handling in $:/core/modules/startup/favicon.js. It's a startup module that automatically updates the DOM's favicon link every time the tiddler $:/favicon.ico changes.

You could use it as a starting point for a daemon that takes actions in response to changes to tiddler values. In a tiddler change event you are free to modify other tiddlers.

Best wishes

Jeremy.


On Sat, Jan 10, 2015 at 9:10 PM, Tobias Beer <beert...@gmail.com> wrote:
I would like to be able to create something that has the same functionality as the widgets in the MathyThing plugin that doesn't require a user action to update.

However, you'd potentialy running into the same problems. Only just slightly less forcefully.
 
Jeremy suggested I create a daemon that runs in the background and updates the outputs when appropriate.

When appropriate is the key here. It shouldn't run on a timer but rather hook into certain events... hooks that may not exist yet.
 
I was hoping that someone could point me in the direction of an example of a daemon used in tiddlywiki before I start poking the code trying to learn how without an example.

You might want to come to terms with how you envision that process to (safely) work... and then as that specific question with respect to what precisely your daemon is supposed to achieve (and above all WHY).

I have found some examples of generic javascript daemons, but I am not familiar enough with javascript to implement them in tiddlywiki without a lot of trial and error, which is what I would like to avoid if possible.

Understandably... but you might just be headed towards mostly unexplored waters. 

Best wishes, Tobias.

--
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.



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

Tobias Beer

unread,
Jan 10, 2015, 7:58:08 PM1/10/15
to tiddly...@googlegroups.com, jeremy...@gmail.com
Hi Jeremy,
 
The best example of a daemon in the core is the favicon handling in $:/core/modules/startup/favicon.js. It's a startup module that automatically updates the DOM's favicon link every time the tiddler $:/favicon.ico changes.

Very useful to know, starting to collect dev tips here...


Best wishes, Tobias.

Jed Carty

unread,
Jan 11, 2015, 1:39:57 AM1/11/15
to tiddly...@googlegroups.com
It was surprisingly easy to convert the widget into a daemon.
Because the widget input syntax isn't available I need to find some better way to give inputs than I have now. I think that is just going to be a lot of regular expressions and text parsing and, while that may not be trivial, I at least have a pretty good idea how to make it work.

Jeremy Ruston

unread,
Jan 11, 2015, 3:59:50 AM1/11/15
to TiddlyWikiDev
Hi Jed

On Sun, Jan 11, 2015 at 6:39 AM, Jed Carty <inmy...@gmail.com> wrote:
It was surprisingly easy to convert the widget into a daemon.

Great.
 
Because the widget input syntax isn't available I need to find some better way to give inputs than I have now. I think that is just going to be a lot of regular expressions and text parsing and, while that may not be trivial, I at least have a pretty good idea how to make it work.

A good strategy is to read your configuration from the tiddler store. Perhaps every dynamic calculation that one sets up would be represented by a single tiddler tagged with "$:/tags/MathyThing".

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.
For more options, visit https://groups.google.com/d/optout.

Astrid Elocson

unread,
Jan 11, 2015, 4:32:08 AM1/11/15
to tiddly...@googlegroups.com
Hi Jed,


> I think that is just going to be a lot of regular expressions and text parsing and, while that may not be trivial, I at least have a pretty good idea how to make it work.

The trick to text parsing is to tokenise the text first, i.e. perform a preliminary step that converts a flat string of characters like `xyz = i * 99` into a list of tokens like ["xyz", "=", "i", "*", "99"]. You can then process the tokens without having to worry about having to ignore things like whitespace and comments.

You can either do the tokenisation in one fell swoop up front, or get the parser to call a tokenise function whenever it needs the next token.

I recently wrote a parser for the new railroad diagram plugin, which you may find helpful:

https://github.com/Jermolene/TiddlyWiki5/tree/master/plugins/tiddlywiki/railroad

– æ

Tobias Beer

unread,
Jan 11, 2015, 7:05:58 AM1/11/15
to tiddly...@googlegroups.com
Hi Astrid,

That's a great example! Glad to find this in the repo.
Always wanted to better understand tokenizing.
So, this simple yet practical example helps a lot.


Best wishes, Tobias.

Tobias Beer

unread,
Jan 11, 2015, 7:08:23 AM1/11/15
to tiddly...@googlegroups.com
Hi Astrid,
 

[[x|"tiddler"]] link
{{"tiddler"}} transclusion

May I ask why it calls for those quotes?

Best wishes, Tobias.

Astrid Elocson

unread,
Jan 11, 2015, 7:37:41 AM1/11/15
to tiddly...@googlegroups.com
Hi Tobias,


> May I ask why it calls for those quotes?

It's because the tokeniser doesn't know about the parser's context.

For example, when tokenising `{{some tiddler or other}}`, it doesn't know that the parser will be in parseTransclusion() and potentially able to treat everything up to `}}` as a string. It would instead tokenise this as ["{{", "some", "tiddler", "or", "other", "}}"].

This could of course be solved, but it would make the tokeniser messier.

The [[…]] and {{…}} syntaxes inside railroad diagrams were afterthoughts, and like all the best afterthoughts, they didn't quite fit in with the design I'd already built :)

– æ

Tobias Beer

unread,
Jan 11, 2015, 7:47:38 AM1/11/15
to tiddly...@googlegroups.com
Hi Astrid,
 
This could of course be solved, but it would make the tokeniser messier.

At second thought, It's not something that needs solving, I think.
Chaining things in a railroad diagram is the main task of it,
so that takes precedence over declaring string literals.

Best wishes, Tobias.

Reply all
Reply to author
Forward
0 new messages