datavis-tech / topologica

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

Accept Array as Reactive Function #37

Closed curran closed 5 years ago

curran commented 5 years ago

Sometimes, for simple reactive functions, it's desirable to specify the function and its dependencies more concisely. Proposal: use an array with two elements, the function and the dependencies.

For example: Unpacking objects.

Before:

const DOMScaffold = ({svg}) => ({
  axisG: one(svg, 'g.axes'),
  backgroundMarksG: one(svg, 'g.background-marks'),
  foregroundMarksG: one(svg, 'g.foreground-marks')
});
DOMScaffold.dependencies = 'svg';

const axisG = ({DOMScaffold}) => DOMScaffold.axisG;
axisG.dependencies = 'DOMScaffold';

const backgroundMarksG = ({DOMScaffold}) => DOMScaffold.backgroundMarksG;
backgroundMarksG.dependencies = 'DOMScaffold';

const foregroundMarksG = ({DOMScaffold}) => DOMScaffold.foregroundMarksG;
foregroundMarksG.dependencies = 'DOMScaffold';

const dataFlow = Topologica({
  DOMScaffold,
  axisG,
  backgroundMarksG,
  foregroundMarksG
});
const DOMScaffold = ({svg}) => ({
  axisG: one(svg, 'g.axes'),
  backgroundMarksG: one(svg, 'g.background-marks'),
  foregroundMarksG: one(svg, 'g.foreground-marks')
});
DOMScaffold.dependencies = 'svg';

const dataFlow = Topologica({
  DOMScaffold,
  axisG: [({DOMScaffold}) => DOMScaffold.axisG, 'DOMScaffold'],
  backgroundMarksG: [({DOMScaffold}) => DOMScaffold.backgroundMarksG, 'DOMScaffold'],
  foregroundMarksG: [({DOMScaffold}) => DOMScaffold.foregroundMarksG, 'DOMScaffold']
});
curran commented 5 years ago

This would simplify the examples in the README as well.