Skip to content

ElmFragment and ElmActivity

diklimchuk edited this page Jan 26, 2021 · 1 revision

To simplify writing Elm screens and reducing the amount of errors elmslie-android provides ElmFragment and ElmActivity classes. They handle implementing Elm architecure on android. After extending them there's only a minimal set of methods to implement:

Methods

  • val initEvent: Event

Should be set to some specific Event which will be sent the first to initialize the Store

  • fun createStore(): Store

It should create and ElmStore instance passing to it the necessary initial State, Actor and Reducer

  • fun render(State)

Draw the State on the screen. For example set views visibility, text or recycler view items.

  • fun handleEffects(Effect) - optional

Handles screen effect. It's guaranteed to be called insode onResume/onPause state both for Fragment and Activity.

  • fun mapList(State): List - optional

This is used to asynchronously map list items for recycler view. The returned set of items will be passed to the next method, renderList

  • fun renderList(List) - optional

Called with the items you will return inside mapList, but on the main thread.