Skip to content

Add only_on_change flag to add_on_update_callback #306

@shihab-dls

Description

@shihab-dls

Allowing add_on_update_callback to take an only_on_change=True flag would allow us to fan out values to attributes bidirectionally. For example:

attr1 = AttrRW(Bool)
attr2 = AttrRW(Bool)

@dataclass
class AttrGroup:
    fan_out_attr: AttrRW
    
    async def __call__(self, value: Any):
        await fan_out_attr.update(value)
 
attr1.add_on_update_callaback(AttrGroup(attr2))
attr2.add_on_update_callaback(AttrGroup(attr1))

would re-trigger the callback recursively; but this:

attr1.add_on_update_callaback(AttrGroup(attr2), only_on_change=True)
attr2.add_on_update_callaback(AttrGroup(attr1), only_on_change=True)

would not. A use case for this can be found on #133.

Acceptance Criteria

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions