plopp.core.Node#
- class plopp.core.Node(func, *parents, **kwparents)[source]#
A node that can have parent and children nodes, to create a graph. A node can be constructed from a callable
func
, or a raw object. In the case of a raw object, a node wrapping the object will be created.Nodes can have views attached to them, which are instances of
View
. Views can be notified when the node’s data changes. When this happens, the view typically requests data from its parent nodes, who in-turn request data from their parents, traversing the graph from bottom to top.Caching is used to avoid traversing the graph multiple times when data is requested multiple times without any changes to the graph.
Leaf nodes are nodes that have neither children nor views. When such nodes are notified of changes, they will call their
func
to ensure any side effects are executed.- Parameters:
func (
Any
) – The callable that is called when data is requested from the node. This can also be a raw object, in which case this becomes a callable that returns the object.*parents (
Any
) – Positional arguments that represent the positional arguments of the functionfunc
.*kwparents (
Any
) – Keyword arguments that represent the keyword arguments of the functionfunc
.
Methods
__init__
(func, *parents, **kwparents)add_kwparents
(**parents)Add one or more keyword parents to the node.
add_parents
(*parents)Add one or more parents to the node.
add_view
(view)Add a view to the node.
is_leaf
()Whether the node is a leaf node (i.e. has neither children nor views).
notify_children
(message)Notify all of the node's children with
message
.notify_views
(message)Notify the node's views with
message
.remove
()Remove the node from the graph.
request_data
()Request data from the node.
Attributes
id
The unique uuid of the node.
input_value
The input value of the node, if it is an input node.
is_input_node
Whether the node is an input node.