You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+25-6Lines changed: 25 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -130,7 +130,7 @@ It is possible to embed a graph into another thanks to a graph node. Any visitat
130
130
131
131
### Fork
132
132
133
-
FreExGraph provide a fork mechanism. It provides an easy way to duplicate a graph from a given node until the end of the graph (or to a specific node that would be used as a join: useful to implement).
133
+
FreExGraph provide a fork mechanism. It provides an easy way to duplicate a graph from a given node until the end of the graph (or to a specific node that would be used as a join).
134
134
135
135
Here is an example:
136
136
_Given the following graph in `execution_graph`:_
@@ -179,11 +179,11 @@ Join is do-able by adding the
179
179
### Abstract Visitor hooks
180
180
181
181
Abstract visitor provide some default hooks that can be overridden from custom visitors in order to implement more complex logic depending on the graph visit.
182
-
*`hook_start()` : This hook is called when the visitation of the graph start
183
-
*`hook_end()` : This hook is called when the visitation of the graph end
184
-
*`hook_fork_started(n: FreExNode, fork_id: str)` : This hook is called when a fork has been entered (when visiting the first node of a fork)
185
-
*`hook_start_graph_node(gn: GraphNode)` : This hook is called when a graphnode recursion start (graph node given as parameter of the hook)
186
-
*`hook_end_graph_node(gn: GraphNode)` : This hook is called when a graphnode visitation end (graph node given as parameter of the hook)
182
+
*`hook_start()` : This hook is called when the visitation of the graph start (an interesting way to use this hook could be to reinitialize your visitor in case of re-use).
183
+
*`hook_end()` : This hook is called when the visitation of the graph end.
184
+
*`hook_fork_started(n: FreExNode, fork_id: str)` : This hook is called when a fork has been entered (when visiting the first node of a fork).
185
+
*`hook_start_graph_node(gn: GraphNode)` : This hook is called when a graphnode recursion start (graph node given as parameter of the hook).
186
+
*`hook_end_graph_node(gn: GraphNode)` : This hook is called when a graphnode visitation end (graph node given as parameter of the hook).
187
187
188
188
Custom hooks can be implemented if you must trigger a specific action that depend on the business data stored in your node.
189
189
To do so, in the `__init__` of your custom visitor, use the method `register_custom_hook(predicate: Callable, hook: Callable)` : This method will trigger the provided hook if the given predicate return true for a node.
@@ -243,6 +243,25 @@ v = ValidateGraphIntegrity()
243
243
# visitation does assertion to verify if the graph is correct
244
244
v.visit(graph_above.root())
245
245
```
246
+
Those visitor implement the start hook that reinitialize their state as if they were new freshly created visitor. Which is why an instance of a standard visitor can be re-used. To implement this kind of behaviour in your own visitors, check out [visitor hooks](#abstract-visitor-hooks).
247
+
248
+
### Reverse visit
249
+
It is possible to revert the order of visitation of your visitor by setting its attribute `is_reversed` of your visitor (works with any kind of visitor), example :
250
+
```python
251
+
# we assume a graph called `execution_graph` that represent the following graph:
0 commit comments