# Elm AMR
Automatic message-replay for Elm!

This module records `messages` that are passed to the `update`-function during development, and automatically replays them when the `program` is reloaded:
- All `messages` up until the first unrecognized will be replayed - This mitigates `jarring app-states` that could otherwise cause confusion during development.
- There is currently no built-in way to reinitialize this kind of `program`, which means changes to `commands` sent from `init` won't be picked up. One way around this is to open the developer-console in the browser, and type `localStorage.clear()`, assuming you're using `localStorage` for persistance.

The API requires a few functions:
1. Encode messages to JSON
2. Decode messages from JSON
3. Read JSON-encoded messages from `flags`
4. Write JSON-encoded messages to an outgoing `port`
5. A tiny script in your HTML to pick up `port`-output, persisting it somehow

A tiny example can be found [here](https://github.com/opvasger/elm-amr/blob/master/example).

## Design
On top the stuff described above, this module addresses some of the performance-issues related to recording every single interaction with your application:
- Messages are encoded exactly **once** each, mapped to an integer, and then added to an array of integers that represent the sequence of messages update received. Integer-arrays with a mapping from integer to message should be more space-efficient than storing encoded messages directly (and redundantly).
- Every new message is pre-encoded, when update is called, to speed up cache-writes.

## Future Plans
I plan to have message-encoding/decoding be code-generated using static-analysis, distributed as a small CLI/API on NPM.