Base class for components. It extends Vizabi.Events. You may think of Vizabi.Component similar to a Controller-View. Components can be rendered to a DOM element and have support for templating and model binding.
The following example shows a very simple component implementation:
Components may also be registered if reusable. Example:
Vizabi comes with many built-in reusable components. You can find them under src/components. All of them extend Vizabi.Component.
Sub-components
Components may also instantiate subcomponents. Assuming year-display from the previous example is registered, we can create a new component that uses it.
Model binding
The following code is an example of model binding at a component level:
resize(): called when the container detects a resize event
readyOnce(): called only once when both compoment’s DOM and model are ready
ready(): called when DOM and model are ready (multiple times)
Since we know that the DOM is ready in these methods, we can use this.element to access the root node of the component’s template and this.placeholder to access the placeholder node. Example:
And since we know that the model is ready in readyOnce and ready, we can use this.model to access its properties and data:
Checkout how Vizabi’s timeslider component uses such methods here.
Note that listening to the model’s ready event is different than using the component’s ready() method, because in the later, we ensure that the DOM is also ready, not only the model