--- url: /reference/items/Indexable/examples.md --- # Examples ## Counter :::code-group ```js import { Base, registerComponent } 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() { for (const instance of this.$query('Counter')) instance.goPrev(); } onNextBtnClick() { for (const instance of this.$query('Counter')) instance.goNext(); } } registerComponent(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()` dispatches a native `CustomEvent` whose `detail` is the payload object, `data-on:index` catches the `index` event and forwards `event.detail.index` to every [`DataBind`](../DataBind/index.md) and [`DataComputed`](../DataComputed/index.md), which move the track, highlight the dots and update the counter. No carousel 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 carousel component is registered. registerComponent(Indexable); registerComponent(Action); registerComponent(DataBind); registerComponent(DataComputed); ``` :::