Generate an Elm module for saving and loading data to an external key-value data source.
For guidance on how to wire the generated code to work with JavaScript through ports, take a look at the examples in the package Github repo.
Represents information about and configuration of the store you want to create. This type
does not have its constructor exposed and must be created using the init
function.
init : List String -> Store
Create a new store. You can pass this to the generate
function to generate
code with elm-codegen.
withDictSupport : Store -> Store
Adds support for generating encoding and decoding for Dict
values. Any key in the
Json.Decode.Value
passed to the generate
function ending in a _
character
will have its value recognize as a Dict
.
For example, when a Store
that has this option enabled is run on some JSON with the following shape:
{ "people_" :
{
name : "",
age : 0
}
}
The generated code will treat that as a Dict String { name : String, age: Int }
rather than
{ name : String, age: Int }
, which would be the default behavior.
generate : Json.Decode.Value -> Store -> Elm.File
Generates an Elm file from a passed Store
(which you can create with the init
function) and some JSON (as a Json.Decode.Value
).
If the passed Json cannot be decoded, the generated code will be for managing arbitrary key value pairs with the store. No decoding or encoding will be generated. While this may still be useful, it's less useful than getting all your serialization for free!
The generated code has its behavior documented. If you'd like to understand how your store is working internally, generate some code and read the comments!