PDA

View Full Version : Handler Questions



Weltenbrand
December 11th, 2020, 09:08
Hello I have some questions on handlers (DB.addHandler).

Is onChildUpdate recursive ?
eg. does
DB.addHandler("rootnode", "onChildUpdate",doSomething) catch a change of rootnode.node.subnode ?

Is there a performance difference between (in the case of many nodes):


DB.addHandler("rootnode.*", "onUpdate",doSomething)
and

DB.addHandler("rootnode.node1", "onUpdate",doSomething)
DB.addHandler("rootnode.node2", "onUpdate",doSomething)
DB.addHandler("rootnode.node3", "onUpdate",doSomething)
....


Does the wildcard(*) spans multiple subnode?
e.g. does
DB.addHandler("rootnode.*.endnode", "onUpdate",doSomething) catch rootnode.node1.node2.node3.endnode ?

Best Regards

SilentRuin
December 11th, 2020, 15:09
Hello I have some questions on handlers (DB.addHandler).

Is onChildUpdate recursive ?
eg. does
DB.addHandler("rootnode", "onChildUpdate",doSomething) catch a change of rootnode.node.subnode ?

Is there a performance difference between (in the case of many nodes):


DB.addHandler("rootnode.*", "onUpdate",doSomething)
and

DB.addHandler("rootnode.node1", "onUpdate",doSomething)
DB.addHandler("rootnode.node2", "onUpdate",doSomething)
DB.addHandler("rootnode.node3", "onUpdate",doSomething)
....


Does the wildcard(*) spans multiple subnode?
e.g. does
DB.addHandler("rootnode.*.endnode", "onUpdate",doSomething) catch rootnode.node1.node2.node3.endnode ?

Best Regards

There is no recursive to my knowledge (if this can be done then its news to me - maybe some dev can comment). You are defining an exact match (this can include a child node in which case its any of them), when changed it will trigger the call back. (FYI I only deal with FGU code)

This is the doc (https://fantasygroundsunity.atlassian.net/wiki/spaces/FGU/pages/4096100/Developer+Guide) for things directly usable in FG - for the rest you you should be referencing the rulesets or extension code (.pak, .ext which are just zip files) for examples.

In the doc this is the description...

addHandler

function addHandler( nodepath, event, callback )
Add an event handler callback function to a specified database event on any node matching the specified database path.

The handler function should have the following signature: [function name]([parameters]). The parameters will vary depending on the database event the function is attached to, as follows.

* [onAdd] parameters = (nodeAdded)

* [onCategoryChange] parameters = (nodeChanged)

* [onChildAdded] parameters = (nodeParent, nodeChildAdded)

* [onChildCategoriesChange] parameters = (nodeParent)

* [onChildDeleted] parameters = (nodeParent)

* [onChildUpdate] parameters = (nodeParent, bListchanged)

* [onDelete] parameters = (nodeToBeDeleted)

* [onIntegrityChange] parameters = (nodeChanged)

* [onUpdate] parameters = (nodeUpdated)

Parameters

nodepath (string)
A data base path identifier. The '*' character can be used as a wildcard for a path segment.

event (string)
The event to be captured (onUpdate, onAdd, onDelete, onObserverUpdate, onChildAdded, onChildUpdate, onChildDeleted, onIntegrityChange)

callback (function)
The function to be called when the event triggers

Weltenbrand
December 15th, 2020, 08:58
Hi, thank you for your answer.
But it does not adress my question, I have read the docs and other ruleset are not really an answer to this question.

A "path segment" can contain multiple subpaths, depending on the implementation (which I dont know). I assume there are no recursive calls, but maybe the syntax is different (in some wildcard implementations some thing like /*/* would catch all subpaths).

SilentRuin
December 15th, 2020, 15:34
Hi, thank you for your answer.
But it does not adress my question, I have read the docs and other ruleset are not really an answer to this question.

A "path segment" can contain multiple subpaths, depending on the implementation (which I dont know). I assume there are no recursive calls, but maybe the syntax is different (in some wildcard implementations some thing like /*/* would catch all subpaths).

If you read it then you read what I quoted you here...

nodepath (string)
A data base path identifier. The '*' character can be used as a wildcard for a path segment.

If you looked through the 5E/CoreRPG rulesets as I described then a simple search for .*" would have shown you things like these...

DB.addHandler("charsheet.*", "onAdd", addIdentity);
DB.addHandler(DB.getPath(node, "effects.*"), "onChildUpdate", onEffectsUpdated);
DB.addHandler(DB.getPath(node, "targets.*"), "onChildUpdate", onTargetsChanged);

So if as you say you've already looked as I suggested - I'm not sure what questions you have left unless you need to try something nobody else has. Each trigger - as described in the document - will occur for a given node.

An example out of my own extensions shows even further refinement of this...

DB.addHandler("combattracker.list.*.inventorylist.*.carried", "onUpdate", onCarriedChanged);

Maybe its the word "recursive" that is confusing things to me in your question - either way - if you've looked at all these already - I'm not sure how to answer your question. Maybe someone else can give it a shot as I don't know what more I can tell you that I've not told you already.