holoviz / param

Param: Make your Python code clearer and more reliable by declaring Parameters
https://param.holoviz.org
BSD 3-Clause "New" or "Revised" License
427 stars 73 forks source link

Reactive: root executed while updating a branch #867

Closed maximlt closed 2 months ago

maximlt commented 12 months ago

I was trying to understand what happens when a reactive expressions has multiple "reactive inputs".

graph TD;
    firstnamex-->append_lastname;
    lastnamex-->append_lastname;

Looking at the last cell of the image below, I'm surprised to see 'transforming first name johnny' being printed while updating lastnamex, is that expected?

image

from param import rx

firstnamex = rx('john')
lastnamex = rx('lenon')

def debug(value, info=''):
    print(info, value)
    return value

def append_lastname(fn, ln):
    return fn + ' ' + ln

pfnx = firstnamex.rx.pipe(debug, info='transforming first name').title()
plnx = lastnamex.rx.pipe(debug, info='transforming last name').title()
together = pfnx.rx.pipe(append_lastname, ln=plnx).rx.pipe(debug, info='merged')

together

firstnamex.rx.value = 'johnny'
lastnamex.rx.value = 'hallyday'
philippjfr commented 7 months ago

Seems to be to do with over-eagerly invalidating the root.