DEV Community

Tom Larkworthy
Tom Larkworthy

Posted on • Originally published at observablehq.com on

2

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

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.

Image description

Sometimes we want control the dataflow 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.

Image description

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

Image description

You can create a lightweight view with Inputs.input

Image description

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

Image description

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!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay