datavis-tech / topologica

Minimal library for reactive dataflow programming. Based on topological sort.
MIT License
50 stars 1 forks source link

Explicit API #2

Closed curran closed 6 years ago

curran commented 6 years ago

When defining functions separately from the call to topologica (which will be most of the time), it would be nice to specify the inputs at the same location in the code as the function is defined.

Example code from Color Picker Example.

Before:

// Generates a color string from red, green, and blue values.
const color = ({r, g, b}) => `rgb(${r},${g},${b})`;

// Sets the background color.
const background = ({color}) => {
  d3.select('body').style('background-color', color);
}

// Set up the data flow graph.
const dataflow = topologica({
  color: [color, 'r, g, b'],
  background: [background, 'color']
});

After:

// Generates a color string from red, green, and blue values.
const color = ({r, g, b}) => `rgb(${r},${g},${b})`;
color.inputs = 'r, g, b';

// Sets the background color.
const background = ({color}) => {
  d3.select('body').style('background-color', color);
}
background.inputs = 'color'

// Set up the data flow graph.
const dataflow = topologica({ color, background });
curran commented 6 years ago

Better yet topologica.reactiveFunction(fn, inputs)

curran commented 6 years ago

Idea for developer ergonomics: