I have a scenario where multiple nodes are connected to each other in a certain hierarchy. Each node has a property "isNodeActive", and the value of this property depends on the parent node's "isNodeActive" property. I need to update a node's "isNodeActive" property to either "true" or "false". When this happens, the child nodes' "isNodeActive" properties should also be updated, continuing down the hierarchy.
If a child node has multiple parents and all its parent nodes' "isNodeActive" values are "false", the child's "isNodeActive" should be updated to "false". However, if any of the parent nodes' "isNodeActive" values is "true", the child node should remain active, and the propagation should continue accordingly.
For example, in this diagram:
-
lets say all nodes are initialized with "isNodeActive" as true.
-
If I set Node3's "isNodeActive" to "false", then Node4 and Node8 should also have their "isNodeActive" set to "false", as none of their parent nodes have "isNodeActive" set to "true". Node5 should remain unaffected, and its "isNodeActive" should remain "true" because it has another parent "Node2" whose "isNodeActive" is "true". This also means that Node6 and Node7 should retain "isNodeActive = true".
-
If I later set Node5's "isNodeActive" to "false", then Node7's "isNodeActive" should turn "false" as it only has Node5 as a parent, and both of its parents' "isNodeActive" values are now "false". However, Node6 should remain "true", as it has another parent Node1 whose "isNodeActive" is still "true".
can this be achieved ?