WardrikEvents.View behaviour (wardrik_events v0.1.0-rc.1)

Copy Markdown

The behaviour for views. A view folds an agent's events, oldest first, into what a screen shows.

{timeline, cursor} = WardrikEvents.view(MyApp.Events, "acme/triage", WardrikEvents.Timeline)

To keep a view current, stream the log after cursor and fold each event into the same state:

{:ok, stream} = WardrikEvents.stream(MyApp.Events, ["acme/triage"], after: WardrikEvents.Cursor.encode(cursor))

Enum.reduce(stream, timeline, fn {event, _cursor}, timeline ->
  WardrikEvents.Timeline.handle_event(event, timeline)
end)

See WardrikEvents.Timeline, WardrikEvents.Runs and WardrikEvents.Activity.

Summary

Callbacks

Folds one event into the state.

Returns the state before any event.

Functions

Folds events, oldest first, into a new state of view. opts are passed to init/1.

Callbacks

handle_event(t, state)

@callback handle_event(WardrikEvents.CloudEvent.t(), state :: term()) :: term()

Folds one event into the state.

init(opts)

@callback init(opts :: keyword()) :: term()

Returns the state before any event.

Functions

fold(events, view, opts \\ [])

Folds events, oldest first, into a new state of view. opts are passed to init/1.