param icon indicating copy to clipboard operation
param copied to clipboard

Reactive: root executed while updating a branch

Open maximlt opened this issue 2 years ago • 1 comments

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'

maximlt avatar Oct 05 '23 09:10 maximlt

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

philippjfr avatar Mar 06 '24 18:03 philippjfr