ioxu / boxer

workflow tool
MIT License
1 stars 0 forks source link

add `Container.replace()` #2

Closed ioxu closed 11 months ago

ioxu commented 11 months ago

Presently there is parent_container.replace_child().

Should add Contaner.replace() to hide parent logic inside Container.

usage here, but should work regardless if a Container has a parent (is a root) or not: https://github.com/ioxu/boxer/blob/9d16528a92268d7a1a3d71ae1c3dd886549bbb14/boxer/containers.py#L710

.replace_child() implemented here: https://github.com/ioxu/boxer/blob/9d16528a92268d7a1a3d71ae1c3dd886549bbb14/boxer/containers.py#L184

ioxu commented 11 months ago

change_container() is messy. This should help generalise.

ioxu commented 11 months ago

.. cannot replace the root Container of course.

ioxu commented 11 months ago

added .replace_by()

It's mostly to make utilising code shorter.

use

if container.parent is None:
    container.set_child( new_container, 0 )
else:
    container = container.replace_by( new_container )

which is all very smelly.