Using Providers

Last updated 5 months ago

A Provider represents a source of asynchronous events. To subscribe to a Provider, you use it and pass it a block that will be called whenever there is an event to process.

component Main {
state counter : Number = 0
use Provider.Tick {
ticks = () : Promise(Never, Void) => {
next { counter = counter + 1 }
}
}
fun render : Html {
<div>
<{ Number.toString(counter) }>
</div>
}
}

In the above example we will update counter every second using the Tick Provider.

Other available Providers: AnimationFrame, Mouse and Scroll