observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

No way to depend on a cell without introducing a dataflow link. #470

Open tomlarkworthy opened 2 years ago

tomlarkworthy commented 2 years ago

Is your feature request related to a problem? Please describe. Some tasks have a async background aspect, for example, maintaining a login session require periodic refresh of a short lived access_token. The 'frontend' to components might have a dataflow with completely different dataflow schedule, for example, a login button might emit events only when the logged in user changes.

Now, I can hide a background processes dataflow updates using a bunch of viewofs or mutables that backwrite into the root component. With that approach I can control the events fully. The problem appears when I try to create a single importable cell of the login component. Background process side chains have to be additionally imported in addition to the button in order for them to manipulate the root component.

I cannot figure out a configuration that allows importing and creating an observed background process in a single cell.

I think the root cause is you can't put a dependency between cells without making the descendant reevaluate on the ascendant. There is a missing semantic.

Describe the solution you'd like Some extra macro like

ignore <identifier>

which should make the name cell observed (i.e. run in runtime) but otherwise doesn't link the two cells with dataflow.

Describe alternatives you've considered Currently I make the importer just import the background worker too, but they have to instantiate it to e.g.

import {viewof login, background} from '<notebook>'
login. // paint frontend
background // start token refresher background process
mootari commented 2 years ago

https://github.com/observablehq/runtime/issues/286 might be related, specifically the promiseof operator suggested there.

tomlarkworthy commented 2 years ago

Oh yeah, if you use promiseof can we consume the events without retriggering, something like

frontend = {
    while (true) {
        await promiseof backend
    }
}

If I did want to emit events while I am awaiting the promise I guess I can use .then in a more complex arrangement leaving space to get some yields in too (?).