kudzu-forest / elm-recent-event-counter / RecentEventCounter

This module provides functionality of counting some events which happened in user-determined certain time range. You can stop and restart the time-induced change as you like. Useful for scorering typing-practice game etc.

Types


type RecentEventCounter

An opaque type representating a counter for events having recently happend.

Creation

create : { durationInMillis : Basics.Float, moving : Basics.Bool } -> RecentEventCounter

create a RecentEventCounter from some configuration. Recode is used in order to prevent user from misunderstanding the time unit.

Modification

Incrementing event count

increment : RecentEventCounter -> RecentEventCounter

Call this when the observed event happend.

rec : RecentEventCounter
rec = create { durationInMillis = 30000, isMoving = False}

rec
    |> increment
    |> count
    --> 1

Change over time

subscribe : (RecentEventCounter -> msg) -> RecentEventCounter -> Platform.Sub.Sub msg

Make subscription for the time-induced change of RecentEventCounter. If the timer is moving, the passed milliseconds is enlarged each frame. Otherwise nothing changes. If the oldest event memorized expires its lifetime then the event is forgotton and the event count decreases by one.

    subscribe toMsg rec

Stop & Restart

stop : RecentEventCounter -> RecentEventCounter

Make the timer stops whichever it has been originally moving or not.

start : RecentEventCounter -> RecentEventCounter

Make the timer moves whichever it has been originally moving or not.

toggle : RecentEventCounter -> RecentEventCounter

If the timer is moving, then stops it. Else, restart the timer.

Discarding the content

resetCounter : RecentEventCounter -> RecentEventCounter

Return RecentEventCounter with the event count forgotten, while the passed time from initialization of the application is remained.

resetWhole : RecentEventCounter -> RecentEventCounter

Return RecentEventCounter in completely seme state as it was created.

Query

count : RecentEventCounter -> Basics.Int

Return how many times increment is called during the user-defined length of time by now.

isMoving : RecentEventCounter -> Basics.Bool

Returns if the timer is currently moving.

passedMillis : RecentEventCounter -> Basics.Float

Returns time in milliseconds passed with the timer moving.