UNPKG

apisearch-events-ui

Version:

Javascript User Interface to visualize all events data.

62 lines (56 loc) 1.18 kB
/** * ApisearchEventsUI class */ class ApisearchEventsUI { /** * Constructor. */ constructor(client) { this.client = client; this.widgets = {}; this.activeWidgets = []; } /** * Initialize components */ init() { /** * Trigger the widget initialization method * to let itself setup properly */ this.activeWidgets.map( widget => widget.initialize(this.client) ); /** * Render the widgets for the first time */ this.render(); } /** * Add new widget */ addWidget(widget) { this.activeWidgets = [...this.activeWidgets, widget]; return this; } /** * Add components in bulk mode */ addWidgets(...widgets) { widgets.map(widget => this.addWidget(widget)); return this; } /** * Render. * * Loop all active components * Hydrate them with new props * And render them. */ render() { this.activeWidgets.map(widget => { widget.render(); }); } } export default ApisearchEventsUI;