Skip to content

Instantly share code, notes, and snippets.

@anvaka
Last active January 1, 2016 19:59
Show Gist options
  • Select an option

  • Save anvaka/8193474 to your computer and use it in GitHub Desktop.

Select an option

Save anvaka/8193474 to your computer and use it in GitHub Desktop.
Imagine you have graph layout algorithm, which uses a physical engine. The engine has dozens of configuration options. What do you think is the best way to expose these options?
// engine is injected into layout:
var layout = forceBasedLayout(engine);
// Modify global gravity force:
engine.gravity(9.8);
// Modify drag coefficient:
engine.drag(0.1);
// ... you can also chain code above
// engine.gravity(9.8).drag(0.1);
// engine is injected into layout:
var layout = forceBasedLayout(engine);
// Modify global gravity force and drag coefficient:
engine.options({
gravity: 9.8,
drag: 0.1
});
// engine is injected into layout:
var layout = forceBasedLayout(engine);
// Modify global gravity force and drag coefficient:
engine.option('gravity', 9.8);
engine.option('drag', 0.1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment