--- url: /reference/items/Indexable/examples.md --- # Examples ## Counter :::code-group ```js import { Base, createApp } from '@studiometa/js-toolkit'; import { Indexable } from '@studiometa/ui'; class Counter extends Indexable { static config = { name: 'Counter', }; get length() { return 10; } onIndex() { this.$el.textContent = this.currentIndex; } } class App extends Base { static config = { name: 'App', refs: ['prevBtn', 'nextBtn'], components: { Counter, }, }; onPrevBtnClick() { this.$children.Counter.forEach((instance) => instance.goPrev()); } onNextBtnClick() { this.$children.Counter.forEach((instance) => instance.goNext()); } } export default createApp(App); ``` ::: ## Slider This example builds a slider without a dedicated component. `Indexable` owns the index — `total` sets the number of slides and `boundary="loop"` wraps around — while [`Action`](../Action/index.md) triggers `goPrev()`, `goNext()` and `goTo()`. A co-located `Action` bridges the reactive rendering: because [`$emit`](https://js-toolkit.studiometa.dev/api/instance-methods/#emit) dispatches a native event, `data-on:index` catches the `index` event and forwards `event.detail[0]` to every [`DataBind`](../DataBind/index.md) and [`DataComputed`](../DataComputed/index.md), which move the track, highlight the dots and update the counter. No `Slider` component is registered. :::code-group ```js import { registerComponent } from '@studiometa/js-toolkit'; import { Indexable, Action, DataBind, DataComputed } from '@studiometa/ui'; // No App and no subclass: Indexable owns the index (with `total` and // `boundary`), a co-located Action bridges its `index` event to the // DataBind/DataComputed renderers. No Slider component is registered. registerComponent(Indexable); registerComponent(Action); registerComponent(DataBind); registerComponent(DataComputed); ``` :::