annotation Motion::PeriodicTimer

Overview

Set this annotation on any methods that require invocation every x interval. This annotation accepts 1 argument which is named interval and expects the type to be Time::Span

Here is a small example setting MyComponent#tick as a periodic timer:

class TickerComponent < Motion::Base
  props ticker : Int32 = 0
  props motion_component : Bool = true

  @[Motion::PeriodicTimer(interval: 1.second)]
  def tick
    @ticker += 1
  end

  def render
    div do
      span @ticker.to_s
    end
  end
end

When the user hits the page containing this component, Motion will invoke the method assigned to @[Motion::PeriodicTimer] based on the Time::Span provided.

Defined in:

motion/annotations.cr