threefoldtecharchive / jumpscaleX_archived

Apache License 2.0
1 stars 6 forks source link

How to subscribe to a config updates in classes that implement JSConfig/JSConfigs base class? #753

Closed GlenDC closed 5 years ago

GlenDC commented 5 years ago

It is not clear for me as a JSX power-user, how to ensure that a class I develop myself can be made aware for any config update. What I mean is that the (public, config-based) properties for such a class would be managed by the JSConfig/JSConfigs base class.

Now on init time this is not an issue I guess, as I can create some specific state object based on the initial data as configured at that time. But if on runtime such a property (managed/stored in that class' config) is modified, that internal state object would need to be modified too.

Is there a way to subscribe to when such a config (property) change happens, and so the class knows at the very least:

Extra information is welcome too, but that would be the most important information required, to what value it has been updated can be easily checked by checking the property myself I suppose. What the old value was before the update could be checking my state object if required I suppose.

The goal of such a state object (call it a config object if you want), would be that you can have some small object configured by a client's config, so that you can pass it to certain internal clients, without requiring to pass the entire client itself.

Is this possible in JumpscaleX? Does it fit within how it is to be used and designed? Am I doing this wrong?

zaibon commented 5 years ago

I think this exists and is called _update_trigger I used it in the zero-os client: https://github.com/threefoldtech/jumpscaleX/blob/5fb073a82aeb0e66fc7d9660c45a1e31bc094bfa/Jumpscale/clients/zero_os/ZeroOSClient.py#L33-L43

As far as I understood it's a function you can create on an object that inherits j.application.JSBaseConfigClass

GlenDC commented 5 years ago

I see. That seems simple enough. Does it only react for updates to properties defined in the class config?

zaibon commented 5 years ago

Does it only react for updates to properties defined in the class config?

I don't really know, sorry :-/

GlenDC commented 5 years ago

No worries. Not important. I think my question got answered. Thank you. Going to close this for now.

@rkhamis if this isn't part of the documentation yet, it might be useful to somehow add this in the right location. What this issue is concerned however, I considered it resolved.

Thank you @zaibon!