Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider allowing linking parameters by passing by reference #363

Closed
philippjfr opened this issue Nov 28, 2019 · 3 comments
Closed

Consider allowing linking parameters by passing by reference #363

philippjfr opened this issue Nov 28, 2019 · 3 comments
Labels
component: depends/watch status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. type-feature Feature request
Milestone

Comments

@philippjfr
Copy link
Member

Consider having two Parameterized classes:

class A(param.Parameterized):

    a_value = param.Number(default=0)

class B(param.Parameterized):

    b_value = param.Number(default=0)

I think it might be nice to be able to link parameters on these classes simple by passing the instance parameter, e.g.:

a = A()
b = B(b_value=a.param.a_value)

Parameter b_value on the B instance would now track the value of a_value on the A instance.

@poplarShift
Copy link

Because others might be interested, here is how I'm doing it currently:

def propagate_param(origin, origin_param, target, target_param):
    def callback(*events):
        for event in events:
            setattr(target, target_param, event.new)

    watcher = origin.param.watch(callback, [origin_param], onlychanged=False)
    origin.param.trigger(origin_param)
    return watcher

and then

a = A()
b = B()
propagate_param(a, 'a_value', b, 'b_value')

@Jhsmit
Copy link

Jhsmit commented Apr 9, 2020

Is there a way of doing this bidirectionally?

@ceball ceball added component: depends/watch status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. type-feature Feature request labels Apr 13, 2020
@tonyfast tonyfast added this to the 2.0 milestone Aug 31, 2020
@maximlt maximlt modified the milestones: 2.0, v2.x Apr 5, 2023
@philippjfr philippjfr modified the milestones: v2.x, 2.0 Sep 24, 2023
@philippjfr
Copy link
Member Author

Implemented in #843

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: depends/watch status: discussion Discussion. Not yet a specific feature/bug. Likely to result in multiple PRs/issues. type-feature Feature request
Projects
None yet
Development

No branches or pull requests

6 participants