chiasm-project / chiasm

A browser based environment for interactive data visualizations.
MIT License
184 stars 27 forks source link

Allow components to register themselves #58

Open curran opened 8 years ago

curran commented 8 years ago

In the case that the browser global Chiasm is defined at the time a given module is loaded (included as a script tag), that module should be able to register itself as a plugin in the Chiasm runtime. For this, the plugins object for Chiasm could use prototypal inheritence, and inherit from a global set of plugins.

Examples would be much simpler (no Chiasm boilerplate with plugin assignment necessary). Only a single <script> tag would be necessary to include a Chiasm component on a page. It must be placed after the Chiasm runtime script, chiasm.js.

The following modules should have UMD builds that automatically register themselves:

curran commented 8 years ago

The API could look something like this:

Chiasm.registerPlugin(pluginName, constructor);
Chiasm.registerPlugins(plugins);

var chiasm1 = Chiasm();
chiasm1.registerPlugin(pluginName, constructor);
chiasm1.registerPlugins(plugins);

var chiasm2 = Chiasm(chiasm1);
chiasm2.registerPlugin(pluginName, constructor);
chiasm2.registerPlugins(plugins);

This should use prototypal inheritence. This would enable nested Chiasm instances, as is required for small multiples https://github.com/chiasm-project/chiasm/issues/60