Sitemap

How to 1-of-n switch Dataflow streams on Observable

Nov 24, 2021

In this series, I will explore programming techniques for the notebook platform Observable. Today I am looking at how to direct a reactive Dataflow stream to one-of-n downstream cells. This article assumes you are familiar with Observable’s non-linear reactive program flow already.

Press enter or click to view image in full size

Sometimes we want to control the data flow with logic. If we have a cell called data streaming values, we might like to direct those updates to either cell_1 or cell_2.

Press enter or click to view image in full size

You can programmatically trigger dataflow by calling dispatchEvent on its enclosing view.

Press enter or click to view image in full size

You can create a lightweight view with Inputs.input

Now dataflow is guided by the value of the choice variable.

Press enter or click to view image in full size

Give it a try on the live notebook at @tomlarkworthy/switch-dataflow

I hope you find that useful and that you find other useful ways to manipulate dataflow!

--

--

Tom Larkworthy
Tom Larkworthy

Written by Tom Larkworthy

Observablehq/Cloud consultant. Developing webcode.run to serverless to Observablehq. Ex-Firebase, Ex-Google Cloud.

No responses yet